Text with new lighting shader

Jun 2, 2010 at 4:33 PM

Hi

I've gone over to using another shader to render specular lighting for my 3D text, but I'm getting the following defects appear on the text:

http://screencast.com/t/ODRkYzNhMmQt

Is this something you recognise? and would you be able to suggest a fix? Here is my Vertex shader:

VertexShaderOutput DiffuseLighting(
     float3 position : POSITION,
     float3 normal : NORMAL )
{

     VertexShaderOutput output;

     //generate the world-view-proj matrix
     float4x4 wvp = mul(mul(world, view), projection);
     
     //transform the input position to the output
     output.Position = mul(float4(position, 1.0), wvp);
     
     
     //////////////////////////////////////////////////////////////
     // Example 3.6                                              //
     //                                                          //
     // In this shader, we expect the light to be defined in     //
     // terms of World Space.  We need to transform the model    //
     // normals to World Space as well to make them useful in    //
     // the lighting caculation.                                 //
     //////////////////////////////////////////////////////////////
     float3 worldNormal =  mul(normal, world);
     
     //////////////////////////////////////////////////////////////
     // Example 3.7                                              //
     //                                                          //
     // The actual lighting calculation for diffuse light is     //
     // normal-dot-lightDirection.  The intrinsic function       //
     // used is called "dot" and takes two vectors as parameters //
     // and returns a scalar value.                              //
     //                                                          //
     // The lambertian lighting calculation uses the direction   //
     // from the vertex to the light.  Therefore the light       //
     // direction vector is reversed (negated) as lightDirection //
     // indicates the direction of the light is pointing.        //
     //////////////////////////////////////////////////////////////
     float diffuseIntensity = saturate( dot(-lightDirection, worldNormal));
     
     //////////////////////////////////////////////////////////////
     // Example 3.8                                              //
     //                                                          //
     // The diffuse intensity is then mutiplied by the light     //
     // color to get the diffuse color at the vertex.            //
     //////////////////////////////////////////////////////////////
     float4 diffuseColor = lightColor * diffuseIntensity;
     
     
     
     //////////////////////////////////////////////////////////////
     // Example 3.9                                              //
     //                                                          //
     // The final vertex color is the sum of the diffuse         //
     // lighting at the vertex and the global ambient light.     //
     //                                                          //
     // This simplistic shader will unintentionally modify the   //
     // alpha (opacity) of the vertex color, so the alpha        //
     // component of the color is set fixed at 1.0 (totally      //
     // opaque) for the purposes of this sample.                 //
     //////////////////////////////////////////////////////////////
     output.Color = diffuseColor + ambientColor;
     diffuseColor.a = 1.0;


     //return the output structure
     return output;
}

Its taken from one of the samples on creators club. I would dig deeper myself, but I only have time for temporary fix right now. Will be getting a good book on the subject soon :)

Thanks

 

Coordinator
Jul 2, 2010 at 8:05 AM
Never seen such a thing happen. It does look as if the text doesn't retain the winding order of polygons on the front face and CullMode being set to either ignore back faces or front faces (but not both). The text mesh should have a uniform winding order, though, unless the OpenGL tessellator (that's the the content pipeline DLL uses to convert to build the face caps from the text outline) behaves differently in your case.
Aug 29, 2010 at 8:28 PM

Hi Cygon

Got my answer on the xna creators forum a while back (http://forums.xna.com/forums/t/54819.aspx). But I can also post the solution here so others may benefit. Was just a simple case of setting up the CullMode correctly like you said:

BaseGame.Device.RenderState.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;

Aicos