//---------------------------------------------------------------------------- JunglerMaterial::JunglerMaterial () { VertexShader* vshader = new0 VertexShader("PX2.JunglerMaterial", 3, 3, 8, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelNormal", Shader::VT_FLOAT3, Shader::VS_NORMAL); vshader->SetInput(2, "modelTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(2, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); vshader->SetConstant(0, "gPVWMatrix", 4); vshader->SetConstant(1, "gShineEmissive", 1); vshader->SetConstant(2, "gShineAmbient", 1); vshader->SetConstant(3, "gShineDiffuse", 1); vshader->SetConstant(4, "gLightColour", 1); vshader->SetConstant(5, "gLightAttenuation", 1); vshader->SetConstant(6, "gLightModelDirection", 1); vshader->SetConstant(7, "gUser", 1); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("PX2.JunglerMaterial", 2, 1, 0, 1, false); pshader->SetInput(0, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetInput(1, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D); pshader->SetFilter(0, Shader::SF_LINEAR); pshader->SetCoordinate(0, 0, Shader::SC_REPEAT); pshader->SetCoordinate(0, 1, Shader::SC_REPEAT); pshader->SetTextureUnits(msPTextureUnits); pshader->SetPrograms(msPPrograms); MaterialPass* pass = new0 MaterialPass(); pass->SetVertexShader(vshader); pass->SetPixelShader(pshader); pass->SetAlphaProperty(new0 AlphaProperty()); pass->SetCullProperty(new0 CullProperty()); pass->SetDepthProperty(new0 DepthProperty()); pass->SetOffsetProperty(new0 OffsetProperty()); pass->SetStencilProperty(new0 StencilProperty()); pass->SetWireProperty(new0 WireProperty()); MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); InsertTechnique(technique); }
//---------------------------------------------------------------------------- UIMaterial::UIMaterial () { VertexShader* vshader = new0 VertexShader("PX2.UI", 3, 3, 1, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelColor0", Shader::VT_FLOAT4, Shader::VS_COLOR0); vshader->SetInput(2, "modelTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexColor0", Shader::VT_FLOAT4, Shader::VS_COLOR0); vshader->SetOutput(2, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetConstant(0, "gPVWMatrix", 4); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("PX2.UI", 2, 1, 0, 1, false); pshader->SetInput(0, "vertexColor0", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetInput(1, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D); pshader->SetFilter(0, Shader::SF_NEAREST); pshader->SetCoordinate(0, 0, Shader::SC_CLAMP_EDGE); pshader->SetCoordinate(0, 1, Shader::SC_CLAMP_EDGE); pshader->SetTextureUnits(msPTextureUnits); pshader->SetPrograms(msPPrograms); MaterialPass* pass = new0 MaterialPass(); pass->SetVertexShader(vshader); pass->SetPixelShader(pshader); pass->SetAlphaProperty(new0 AlphaProperty()); pass->SetCullProperty(new0 CullProperty()); pass->SetDepthProperty(new0 DepthProperty()); pass->SetOffsetProperty(new0 OffsetProperty()); pass->SetStencilProperty(new0 StencilProperty()); pass->SetWireProperty(new0 WireProperty()); pass->GetAlphaProperty()->BlendEnabled = true; MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); InsertTechnique(technique); }
//---------------------------------------------------------------------------- Texture2DMaterial::Texture2DMaterial (Shader::SamplerFilter filter, Shader::SamplerCoordinate coordinate0, Shader::SamplerCoordinate coordinate1) { VertexShader* vshader = new0 VertexShader("PX2.Texture2D", 2, 2, 1, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetConstant(0, "gPVWMatrix", 4); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("PX2.Texture2D", 1, 1, 0, 1, false); pshader->SetInput(0, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D); pshader->SetFilter(0, filter); pshader->SetCoordinate(0, 0, coordinate0); pshader->SetCoordinate(0, 1, coordinate1); pshader->SetTextureUnits(msPTextureUnits); pshader->SetPrograms(msPPrograms); MaterialPass* pass = new0 MaterialPass(); pass->SetVertexShader(vshader); pass->SetPixelShader(pshader); pass->SetAlphaProperty(new0 AlphaProperty()); pass->SetCullProperty(new0 CullProperty()); pass->SetDepthProperty(new0 DepthProperty()); pass->SetOffsetProperty(new0 OffsetProperty()); pass->SetStencilProperty(new0 StencilProperty()); pass->SetWireProperty(new0 WireProperty()); MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); InsertTechnique(technique); }
//---------------------------------------------------------------------------- void ImageProcessing::CreateMaterial (PixelShader* pshader, Material*& material, MaterialInstance*& instance) { // 创建pass MaterialPass* pass = new0 MaterialPass(); pass->SetPixelShader(pshader); // 所有材质都共享相同的顶点着色器 pass->SetVertexShader(mVertexShader); // 创建渲染状态 pass->SetAlphaProperty(new0 AlphaProperty()); pass->SetOffsetProperty(new0 OffsetProperty()); pass->SetStencilProperty(new0 StencilProperty()); pass->SetWireProperty(new0 WireProperty()); // 不裁剪三角形 CullProperty* cproperty = new0 CullProperty(); cproperty->Enabled = false; pass->SetCullProperty(cproperty); // 不需要深度缓冲区 DepthProperty* dproperty = new0 DepthProperty(); dproperty->Enabled = false; dproperty->Writable = false; pass->SetDepthProperty(dproperty); // 创建Technique MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); material = new0 Material(); material->InsertTechnique(technique); // Create the material instance and set the vertex shader constants. // 创建材质实例 instance = new0 MaterialInstance(material, 0); // 顶点着色器变换 instance->SetVertexConstant(0, "PVWMatrix", mPVWMatrixConstant); }
//---------------------------------------------------------------------------- StandardESMaterial_AlphaTest::StandardESMaterial_AlphaTest () { VertexShader* vshader = new0 VertexShader("PX2.StandardESMaterial_AlphaTest", 3, 3, 7, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelNormal", Shader::VT_FLOAT3, Shader::VS_NORMAL); vshader->SetInput(2, "modelTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(2, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); vshader->SetConstant(0, "gPVWMatrix", 4); vshader->SetConstant(1, "gShineEmissive", 1); vshader->SetConstant(2, "gShineAmbient", 1); vshader->SetConstant(3, "gShineDiffuse", 1); vshader->SetConstant(4, "gLightAmbient", 1); vshader->SetConstant(5, "gLightDiffuse", 1); vshader->SetConstant(6, "gLightModelDirection", 1); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("PX2.StandardESMaterial_AlphaTest", 2, 1, 0, 1, false); pshader->SetInput(0, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetInput(1, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D); pshader->SetFilter(0, Shader::SF_LINEAR); pshader->SetCoordinate(0, 0, Shader::SC_CLAMP); pshader->SetCoordinate(0, 1, Shader::SC_CLAMP); pshader->SetTextureUnits(msPTextureUnits); pshader->SetPrograms(msPPrograms); vshader->SetShaderKey(SKT_STANNDES_ALPHATEST); pshader->SetShaderKey(SKT_STANNDES_ALPHATEST); MaterialPass* pass = new0 MaterialPass(); pass->SetVertexShader(vshader); pass->SetPixelShader(pshader); pass->SetAlphaProperty(new0 AlphaProperty()); pass->SetCullProperty(new0 CullProperty()); pass->SetDepthProperty(new0 DepthProperty()); pass->SetOffsetProperty(new0 OffsetProperty()); pass->SetStencilProperty(new0 StencilProperty()); pass->SetWireProperty(new0 WireProperty()); pass->GetAlphaProperty()->CompareEnabled = true; pass->GetAlphaProperty()->Compare = PX2::AlphaProperty::CM_GREATER; pass->GetAlphaProperty()->Reference = 0.25f; MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); InsertTechnique(technique); }