Hello,
I try to make a shader to do celshading “toon effect” it works fine on my openGL test project, but when I try to implement it on my windows project a got this error :
{“An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, NORMAL0.”}
Here my .fx file :
#if OPENGL #define SV_POSITION POSITION #define VS_SHADERMODEL vs_3_0 #define PS_SHADERMODEL ps_3_0 #else #define VS_SHADERMODEL vs_4_0_level_9_1 #define PS_SHADERMODEL ps_4_0_level_9_1 #endif float4x4 World; float4x4 View; float4x4 Projection; float4x4 WorldInverseTranspose; float4 MeshColor; float3 DiffuseLightDirection = float3(0, 0, 0); float4 DiffuseColor = float4(1, 1, 1, 1); struct VertexShaderInput { float4 Position : SV_Position0; // The position of the vertex float3 Normal : NORMAL0; // The vertex's normal float4 Color : COLOR0; // The vertex's color }; struct VertexShaderOutput { float4 Position : SV_Position0; float4 Color : COLOR0; float3 Normal : NORMAL0; }; VertexShaderOutput MainVS(in VertexShaderInput input) { VertexShaderOutput output = (VertexShaderOutput)0; // Transform the position float4 worldPosition = mul(input.Position, World); float4 viewPosition = mul(worldPosition, View); output.Position = mul(viewPosition, Projection); // Transform the normal output.Normal = normalize(mul(input.Normal, WorldInverseTranspose)); output.Color = input.Color; return output; } float4 MainPS(VertexShaderOutput input) : COLOR0 { // Calculate diffuse light amount float intensity = dot(normalize(DiffuseLightDirection), input.Normal); if (intensity < 0) intensity = 0; // Calculate what would normally be the final color, including texturing and diffuse lighting float4 color = MeshColor * DiffuseColor * DiffuseColor.a; float light; if (intensity > 0.01) light = 1.1; else if (intensity > 0.0002) light = 1; else light = .4; color.rgb *= light; return color; } technique Toon { pass P0 { VertexShader = compile VS_SHADERMODEL MainVS(); PixelShader = compile PS_SHADERMODEL MainPS(); } };
And the C# code :
foreach (ModelMesh mesh in GameData.Bank.getModel(this.Model).Meshes) { Matrix nworld = mesh.ParentBone.Transform *this.world * Matrix.CreateScale(ModelScale); foreach (Effect effect in mesh.Effects) { effect.Parameters["View"].SetValue(this.view); effect.Parameters["Projection"].SetValue(this.projection); effect.Parameters["World"].SetValue(nworld); effect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(nworld))); effect.Parameters["DiffuseLightDirection"].SetValue(lightDirection); effect.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, lightIntensity)); } mesh.Draw(); }
the exception occurs when mesh.Draw(); is called
I’m new with HLSL and 3D programing and don’t understand what is wrong with my code