Sign in to follow this  

Tangent Lighting Bad(Picture)

This topic is 4357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();
   }

}




Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this