I’m trying to make a vertex shader with some of the basic functionality that a basiceffect has and that I can extend upon, but I’m having some trouble. I tried to look at the source for basicEffect but I can’t get it to work in my own shader;
#include "Macros.fxh"
DECLARE_TEXTURE(Texture, 0);
BEGIN_CONSTANTS
float4 DiffuseColor _vs(c0) _ps(c1) _cb(c0);
float3 EmissiveColor _vs(c1) _ps(c2) _cb(c1);
float3 SpecularColor _vs(c2) _ps(c3) _cb(c2);
float SpecularPower _vs(c3) _ps(c4) _cb(c2.w);
float3 DirLight0Direction _vs(c4) _ps(c5) _cb(c3);
float3 DirLight0DiffuseColor _vs(c5) _ps(c6) _cb(c4);
float3 DirLight0SpecularColor _vs(c6) _ps(c7) _cb(c5);
float3 DirLight1Direction _vs(c7) _ps(c8) _cb(c6);
float3 DirLight1DiffuseColor _vs(c8) _ps(c9) _cb(c7);
float3 DirLight1SpecularColor _vs(c9) _ps(c10) _cb(c8);
float3 DirLight2Direction _vs(c10) _ps(c11) _cb(c9);
float3 DirLight2DiffuseColor _vs(c11) _ps(c12) _cb(c10);
float3 DirLight2SpecularColor _vs(c12) _ps(c13) _cb(c11);
float3 EyePosition _vs(c13) _ps(c14) _cb(c12);
float3 FogColor _ps(c0) _cb(c13);
float4 FogVector _vs(c14) _cb(c14);
float4x4 World _vs(c19) _cb(c15);
float3x3 WorldInverseTranspose _vs(c23) _cb(c19);
MATRIX_CONSTANTS
float4x4 WorldViewProj _vs(c15) _cb(c0);
END_CONSTANTS
#include "Structures.fxh"
#include "Common.fxh"
#include "Lighting.fxh"
// Vertex shader: vertex color.
VSOutput VSBasicVc(VSInputVc vin)
{
VSOutput vout;
CommonVSOutput cout = ComputeCommonVSOutput(vin.Position);
SetCommonVSOutputParams;
vout.Diffuse *= vin.Color;
return vout;
}
// Pixel shader: basic.
float4 PSBasic(VSOutput pin) : SV_Target0
{
float4 color = pin.Diffuse;
ApplyFog(color, pin.Specular.w);
return color;
}
technique CommonTech
{
pass CommonPass
{
PixelShader = compile ps_3_0 PSBasic();
VertexShader = compile vs_3_0 VSBasicVc();
}
};
//TECHNIQUE( BasicEffect_OneLight_Texture_VertexColor, VSBasicOneLightTxVc, PSBasicVertexLightingTx );
I made a setup where I can switch between my own effect and the basic effect to see if they behave the same way.
Effect effect = material == null ? _basicEffect : material.effect;
Matrix worldMatrix = this.worldMatrix;
Matrix viewMatrix = camera.viewMatrix3D;
Matrix projectionMatrix = camera.projectionMatrix3D;
Matrix.Multiply( ref worldMatrix, ref viewMatrix, out Matrix worldView );
Matrix.Multiply( ref worldView, ref projectionMatrix, out Matrix worldViewProj );
// Set BasicEffect parameters.
if (effect.Parameters["World"] != null) effect.Parameters["World"].SetValue( worldMatrix ); //World not used anywhere so optimized out
if (effect.Parameters["WorldViewProj"] != null) effect.Parameters["WorldViewProj"].SetValue( worldViewProj );
if (effect.Parameters["DiffuseColor"] != null) effect.Parameters["DiffuseColor"].SetValue( color.ToVector3() );
// Set our vertex declaration, vertex buffer, and index buffer.
Core.graphicsDevice.SetVertexBuffer( _vertexBuffer );
Core.graphicsDevice.Indices = _indexBuffer;
effect.CurrentTechnique.Passes[0].Apply();
But whenever I use my own effect the screen comes up blank (with the basic effect I can see my mesh fine). I noticed that the “World” is missing when I use my own shader, which makes sense since it’s not used anywhere.
Here’s the source for basic effect and the macros for convenience;
Any pointers?