#include "stdafx.h" #define SETMATERIALSHADERTECHNIQUE_GUID CKGUID(0x3b8e0a69,0x7c380101) //----------------------------------------------------------------------------- int SetMaterialShaderTechnique(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKMaterial* mat = (CKMaterial*)beh->GetTarget(); if( !mat ) return CKBR_PARAMETERERROR; //--- Gets the MaterialShader CKMaterialShader* mfx = mat->GetMaterialShader(); if( !mfx ){ behcontext.Context->OutputToConsole("Material doesn't use a shader."); return CKBR_PARAMETERERROR; } //--- Technique string char* technique = (char*)beh->GetInputParameterReadDataPtr(0); mfx->m_TechniqueName = technique; //--- Finds the next technique ? mfx->m_FindNextValidTechnique = FALSE; beh->GetInputParameter(1)->GetValue( &mfx->m_FindNextValidTechnique ); int forceID = 0; CKShader* fx = (CKShader*)mfx->m_Shader; int techIndex = -1; if( !fx->GetTechIndexByName( mfx->m_TechniqueName, techIndex ) ){ beh->GetCKContext()->OutputToConsoleEx( "Technique '%s' is not valid on Shader Fx '%s'", technique, fx->GetName().CStr()); return CKBR_PARAMETERERROR; } fx->LinkTechnique( forceID, mfx->m_TechniqueName, mfx->m_FindNextValidTechnique, mfx->m_TechIndex ); beh->ActivateOutput(0); return CKBR_OK; } //----------------------------------------------------------------------------- CKERROR CreateSetMaterialShaderTechniqueProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Set Shader Technique"); if(!proto) return CKERR_OUTOFMEMORY; proto->DeclareInput("In"); proto->DeclareOutput("Out"); proto->DeclareInParameter("Technique", CKPGUID_TECHNIQUE); proto->DeclareInParameter("Find Next Valid Technique", CKPGUID_BOOL, "FALSE"); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction(SetMaterialShaderTechnique); proto->SetBehaviorFlags( (CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_TARGETABLE) ); *pproto = proto; return CK_OK; } //----------------------------------------------------------------------------- CKObjectDeclaration *FillBehaviorSetMaterialShaderTechnique() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Set Shader Technique"); od->SetDescription("Sets shader material's technique."); od->SetCategory("Shaders/General"); od->SetType(CKDLL_BEHAVIORPROTOTYPE); od->SetGuid(SETMATERIALSHADERTECHNIQUE_GUID); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetVersion(0x00010000); od->SetCreationFunction(CreateSetMaterialShaderTechniqueProto); od->SetCompatibleClassId(CKCID_MATERIAL); return od; }