// Render Scene with Pass (0x3c853df1,0x6ba35e3e) // - Rendertarget View. // - Render Options. // - Name of the pass. (string) // - Material as fallback (souvent un black). // - ... Parameters (applyed to all effects). #include "CKAll.h" #include "RTView.h" #define RENDERSCENEWITHPASS_GUID CKGUID(0x3c853df1,0x6ba35e3e) //----------------------------------------------------------------------------- enum { PARAM_VIEW = 0, PARAM_RENDEROPTIONS, PARAM_BGCOLOR, PARAM_PASS, PARAM_MATERIAL }; //----------------------------------------------------------------------------- int RenderSceneWithPass(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKParameterIn* pin = beh->GetInputParameter(PARAM_VIEW); if (!pin->GetRealSource()) return CKBR_PARAMETERERROR; // Read the View RTView rtview(pin->GetRealSource()); // Reads background color VxColor bgcolor(0, 0, 0, 0); beh->GetInputParameterValue(PARAM_BGCOLOR, &bgcolor); // The pass const char* pass = (const char*)beh->GetInputParameterReadDataPtr(PARAM_PASS); if (!pass) return CKBR_PARAMETERERROR; // The material CKMaterial* mat = (CKMaterial*)beh->GetInputParameterObject(PARAM_MATERIAL); if (!mat) return CKBR_PARAMETERERROR; // On if (beh->IsInputActive(0)) { CKRenderContext* rc = behcontext.CurrentRenderContext; if (rtview.tex) rtview.tex->EnsureVideoMemory(rc); //--- Check Rect size if(rtview.rect.right <=0 && rtview.rect.bottom <=0 ){ if(rtview.tex){ rtview.rect.right = (float)rtview.tex->GetWidth(); rtview.rect.bottom = (float)rtview.tex->GetHeight(); }else{ rtview.rect.right = (float)rc->GetWidth(); rtview.rect.bottom = (float)rc->GetHeight(); } } CKDWORD ropt = rc->GetCurrentRenderOptions(); beh->GetInputParameterValue(PARAM_RENDEROPTIONS, &ropt); // Remove present command ropt &= ~CK_RENDER_DOBACKTOFRONT; VxRect oldrect; rc->GetViewRect(oldrect); //--- Set Render Target rc->SetRenderTarget(rtview.tex); //--- Set Render View rc->SetViewRect(rtview.rect); VxColor oldbg = rc->GetBackgroundMaterial()->GetDiffuse(); rc->GetBackgroundMaterial()->SetDiffuse(bgcolor); rc->SetOverriddenRendering(CK_OVERRIDE_PASS, mat, pass); rc->Render((CK_RENDER_FLAGS)ropt); rc->SetOverriddenRendering(CK_OVERRIDE_NONE); rc->GetBackgroundMaterial()->SetDiffuse(oldbg); if (!rtview.tex) rc->ChangeCurrentRenderOptions(CK_RENDER_RESTORENEXTFRAME | CK_RENDER_SKIPDRAWSCENE | CK_RENDER_DOBACKTOFRONT, CK_RENDER_CLEARBACK); // Restore old rendertarget rc->SetRenderTarget(NULL); rc->SetViewRect(oldrect); } beh->ActivateOutput(0); return CKBR_OK; } //----------------------------------------------------------------------------- CKERROR CreateRenderSceneWithPassProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Render Scene With Pass"); if(!proto) return CKERR_OUTOFMEMORY; proto->DeclareInput("In"); proto->DeclareOutput("Out"); proto->DeclareInParameter("Target View", CKPGUID_RTVIEW); proto->DeclareInParameter("Render Options", CKPGUID_RENDEROPTIONS); proto->DeclareInParameter("Background Color", CKPGUID_COLOR); proto->DeclareInParameter("Material", CKPGUID_MATERIAL); proto->DeclareInParameter("Pass", CKPGUID_PASS); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction(RenderSceneWithPass); *pproto = proto; return CK_OK; } //----------------------------------------------------------------------------- CKObjectDeclaration *FillBehaviorRenderSceneWithPass() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Render Scene With Pass"); od->SetDescription("Renders the scene into a RenderTarget View; does processing on materials."); /* rem: In: triggers the process
Out: is activated when the process is completed.

View: The rendertarget view.
Render Options: Render flags.
Background Color: The background color used for clear.
Pass Name: The name of the pass to run.
Material: The material to use to render.
*/ od->SetCategory("Shaders/Rendering"); od->SetType(CKDLL_BEHAVIORPROTOTYPE); od->SetGuid(RENDERSCENEWITHPASS_GUID); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetVersion(0x00010000); od->SetCreationFunction(CreateRenderSceneWithPassProto); od->SetCompatibleClassId(CKCID_BEOBJECT); return od; }