#include "stdafx.h" CKERROR CreateApplyShaderProto(CKBehaviorPrototype **pproto); int ApplyShader( const CKBehaviorContext& behcontext ); /***********************************************/ // DECLARATION /***********************************************/ CKObjectDeclaration *FillBehaviorApplyShader() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Set Shader"); od->SetDescription("Apply a shader to a material."); od->SetCategory("Shaders/General"); od->SetType(CKDLL_BEHAVIORPROTOTYPE); od->SetGuid( CKGUID(0x7e747e40,0x58a17d30) ); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetVersion(0x00010000); od->SetCreationFunction(CreateApplyShaderProto); od->SetCompatibleClassId(CKCID_MATERIAL); return od; } /***********************************************/ // PROTO /***********************************************/ CKERROR CreateApplyShaderProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Set Shader"); if(!proto) return CKERR_OUTOFMEMORY; proto->DeclareInput("In"); proto->DeclareOutput("Out"); proto->DeclareInParameter( "Shader", CKPGUID_SHADER ); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction( ApplyShader ); proto->SetBehaviorFlags( (CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_TARGETABLE) ); *pproto = proto; return CK_OK; } /***********************************************/ // MAIN /***********************************************/ int ApplyShader( const CKBehaviorContext& behcontext ) { CKBehavior* beh = behcontext.Behavior; beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); CKMaterial* mat = (CKMaterial*)beh->GetTarget(); if( !mat ) return CKBR_PARAMETERERROR; CKContext* ctx = behcontext.Context; CKShaderManager* shaderMan = (CKShaderManager*)ctx->GetManagerByGuid( ShaderManagerGUID ); if( !shaderMan ) return CKBR_GENERICERROR; char* shaderName = (char*)beh->GetInputParameterReadDataPtr(0); CKShader* shader = shaderMan->GetShaderByName( shaderName ); mat->SetShader( shader ); return CKBR_OK; }