Jump to content
  • Advertisement
Sign in to follow this  
crozzbreed23

Per-Pixel lighting wierd rotation.

This topic is 4186 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

I'm having trouble adding per-lighting to my engine. The light on the wall seems to be rotated which is why I think the circle looks incomplete. Could it have something to do with the way I'm doing my cameras? http://img413.imageshack.us/my.php?image=lightlu8.jpg Fragment shader
//
// cgVertData
// Data that gets passed from the vertex shader
//
struct cgVertData
{
	float2 st0	: TEXCOORD0;
	float3 lightvec : TEXCOORD1;
};

struct cgFragOut {
	float4 rgba  : COLOR;
};

cgFragOut main( cgVertData IN,
				uniform sampler2D diffuseTex,
				uniform sampler2D normalTex ) {
	cgFragOut OUT;
	
	half3 color   = tex2D(diffuseTex, IN.st0).xyz;
	half3 normal  = 2.0 * (tex2D(normalTex, IN.st0).xyz - 0.5);

	normal = normalize( normal );
	
	float diffuse = max(dot(normal, normalize(IN.lightvec)), 0.0);
	
	float attenuation = clamp(1 - dot(IN.lightvec/(100 * 1.4),IN.lightvec/(100 * 1.4)), 0.0, 1.0);

	OUT.rgba = float4(color * float3(diffuse) * attenuation, 1);
	return OUT;
}
[/SOURCE]
[/source] Vertex shader
// interaction.cgvp
// (c) 2007 Truepaint.Net
//

//
// cgInterData
// Data that gets passed into the shader.
//
struct cgInterData
{
	float4 xyz	: POSITION;
	float2 st0	: TEXCOORD0;
	float3 tangent  : TEXCOORD1;
	float3 binormal : TEXCOORD2;
	float3 normal : TEXCOORD3;
	float4 lightorigin : TEXCOORD4;
	float3 cameraPos : TEXCOORD5;
};

//
// cgVertData
// Data that gets passed to the fragment shader.
//
struct cgVertData
{
    float4 xyz  : POSITION;
	float2 st0	: TEXCOORD0;
	float3 lightvec : TEXCOORD1;
};

//
// main
//
cgVertData main( cgInterData IN, uniform float4x4 modelViewMatrix : state.matrix.modelview,
				 uniform float4x4 projectionMatrix : state.matrix.projection ) 
{
	cgVertData OUT;
	float4 viewxyz;
	
	// Light vector.
	float3 light = IN.lightorigin.xyz - IN.xyz.xyz;
	
	// Transform the view to view space.
	viewxyz = mul(modelViewMatrix, IN.xyz);

	// Finally transform it to clip space.
    OUT.xyz = mul(projectionMatrix, viewxyz);
	OUT.st0 = IN.st0;	// Texture 0 - diffuse texture
	
	// Calculate the light vector based on the tbn matrix.
	float3x3 TBNMatrix = float3x3(IN.tangent, IN.binormal, IN.normal);
	OUT.lightvec = mul(TBNMatrix, light);

	return OUT;
}
[/SOURCE]
[/source] Does anyone know what could cause that?

Share this post


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