Tangent Lighting Bad(Picture)

Started by
2 comments, last by helix 18 years, 3 months ago
It seems my tangent lighting shader is not working right. It's giving me a funky tangent Light vector. Should be like this: Image hosted by Photobucket.com But ends up like this: Image hosted by Photobucket.com


float4x4 matWorld ;	          
float4x4 matViewProjection ;	
float4x4 matWorldView ;
float4x4 matView ;
float4x4 worldInv;



struct vertexInput {
    float3 position				: POSITION;
     float2 texCoordDiffuse		: TEXCOORD0;
     float3 normal		        : NORMAL;
     float3 tangent		        : TANGENT;
     float4 col  : COLOR0;
};

struct vertexOutput {
    float4 hPosition		    : POSITION;
    float2 texCoordDiffuse      : TEXCOORD0;
    float3 normal			    : TEXCOORD1;
    float3 tlight			    : TEXCOORD2;
  

};
 

vertexOutput VSIT(vertexInput IN) 
{
    vertexOutput OUT;
    
 
	
 
	float3x3 worldToTangentSpace;
	  worldToTangentSpace[0] = mul(IN.tangent, matWorld);
	  worldToTangentSpace[1] = mul(cross(IN.tangent, IN.normal), matWorld);
	  worldToTangentSpace[2] = mul(IN.normal, matWorld);
	OUT.normal = worldToTangentSpace[2];
	
 
    OUT.tlight = mul(worldToTangentSpace,float3(1,0,0) );
    OUT.hPosition =  mul( float4(  IN.position.xyz  , 1.0) , matViewProjection);
   
	
    OUT.texCoordDiffuse = IN.texCoordDiffuse;
  
 
 	return OUT;
}

float4 PSIT(vertexOutput OUT) : COLOR
{
	float light = dot(normalize(OUT.normal),normalize(OUT.tlight) );
	
 	return float4(light*float3(1,1,1),1);
}



technique Test
{
   pass Pass_0
   {
    
     VertexShader = compile vs_3_0 VSIT();
    PixelShader = compile ps_3_0 PSIT();
   }

}




Advertisement
Hmm... last post vanished....
here it is again:
Quote:
I have a question:
How do you get that low color depth look? Is it just the screenshot? I would really like to know if someone knows how to get that look in a high color depth application.

To your problem:
Your normal is in world space and your tLight vector in tangent space, maybe that´s the cause of the problem?
Quote:Original post by matches81
Hmm... last post vanished....
here it is again:
Quote:
I have a question:
How do you get that low color depth look? Is it just the screenshot? I would really like to know if someone knows how to get that look in a high color depth application.

To your problem:
Your normal is in world space and your tLight vector in tangent space, maybe that´s the cause of the problem?



Yes! That did it, thank you! I was soo blind

The low color depth look was just from me saving it as a GIF. I am unsure on how to get that look with shaders.

That picture is bad ass! It looks like the ying yang symbol. :)

This topic is closed to new replies.

Advertisement