Jump to content
  • Advertisement
Sign in to follow this  
MetaKnight

Tangent Lighting Bad(Picture)

This topic is 4569 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
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?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!