Sign in to follow this  
crozzbreed23

Per-Pixel lighting wierd rotation.

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

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