It’s always those little things

So today I have spent several hours chasing a bug about Culling, so when I set it to back culling, somehow front culling was enabled, and visa versa.

Then suddenly I tried to reverse the normals, which fixed it, so in fact there was nothing wrong with the program itself, just the mesh.

It’s always those little things that bugs us, which we never think off.

BTW. I developed a new parser for materials, so developing a new shader looks like the following:

</pre>
Any description or text can go here. The parser ignores it.

shader "Gem_Shader"
{
 // Properties go here
 info = "Gem shader showing the passes feature";

 :input
 :{
     // Define our two texture maps
     Texture2D noise;
     Texture2D reflection;
     TextureCube environment;

     // To simplify
     #define OUT output

     #define lighting_intensity 0.7f
     #define NOSHADOWS
 :}

 :pass
 {
    :properties {
       Cull [Front];
    }

    :linkage
    :{
       float3 Reflect : REF;
    :}

   :vertex
   :{
      float3 ViewDir = normalize(mul(position, worldMatrix) - eyepos);
      output.Reflect = reflect(viewvec, mul(normal, worldMatrix));
      output.Reflect.y = -output.Reflect.y;
   :}

   :pixel
   :{
      float4 colors = reflection.Sample(ss, input.texcoord)/4.0f;
      float4 cubeMap = environment.Sample(ss, input.Reflect);

      output.Diffuse = float4( colors.rgb + (cubeMap.rgb / 2.0f) , 1.0f);
   :}
 }

 :pass
 {
   :properties {
      Cull [Back];
   }

   :linkage
   :{
      float3 Reflect : REF;
   :}

   :vertex
   :{
      float3 ViewDir = normalize(mul(position, worldMatrix) - eyepos);
      output.Reflect = reflect(viewvec, mul(normalize(float4(normal.xyz, 0)), worldMatrix));
      output.Reflect.y = -output.Reflect.y;
   :}

   :pixel
   :{
      float4 colors = reflection.Sample(ss, input.texcoord)/2.0f;
      float4 cubeMap = environment.Sample(ss, input.Reflect);

      output.Diffuse = float4( colors.rgb + (cubeMap.rgb) , 0.6f);
   :}
 }
}
<pre>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s