# What are those lights doing ?

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

## Recommended Posts

Hi all,

What are those lights doing ? Why they follow the camera ?

see video: http://img706.imageshack.us/img706/4306/lightingissue.mp4

I can't understand why. I perform lighting in view space, the light position is

multiplied by the view matrix ( lightPos = (x,y,z,1) ).

The video show clearly the problem.

Thanks in advance for any help

##### Share on other sites
If you're sure you're using a view-space light position in your lighting shader, are you sure your geometry is really in view space? And you calculating the attenuation of the point light based on the difference of these two view space positions? Can you post some of the code?

##### Share on other sites
Quote:
 Original post by My_Mind_Is_GoingIf you're sure you're using a view-space light position in your lighting shader, are you sure your geometry is really in view space? And you calculating the attenuation of the point light based on the difference of these two view space positions? Can you post some of the code?

Here is my vertex shader for the gbuffer filling:

VS_OUTPUT vs_gbuffer_main(VS_INPUT Input) {	VS_OUTPUT vs_out = (VS_OUTPUT)0; 		vs_out.oTc = Input.iTc;		//let's extract tangent space	vs_out.oNormalDepth.xyz = normalize( mul(Input.iNormal,(float3x3)invTransWorldViewMatrix) );//output normals in view space						//tangent and binormal need to be in view space 	float3 binormal = cross(Input.iTangent,Input.iNormal);	vs_out.oTangent = normalize( mul(Input.iTangent,(float3x3)invTransWorldViewMatrix) );	vs_out.oBinormal = normalize( mul(binormal,(float3x3)invTransWorldViewMatrix) );	//		//world space view dir	float3 WSViewDir = normalize( WSViewPos-Input.pos ); 		//tangent space view dir	float3x3 rotation = float3x3(Input.iTangent,binormal,Input.iNormal);		vs_out.oTSViewDir = mul(rotation,WSViewDir);		float4 p = float4(Input.pos,1.f);	float3 eyeLinear = mul(p,worldViewMatrix).xyz;	//trasform into eye linear space (camera space)		//write out eye linear depth	#ifdef OGL	vs_out.oNormalDepth.w = -eyeLinear.z;			//negate depth if we use ogl as the we use a right handed frame of reference	#else	vs_out.oNormalDepth.w =  eyeLinear.z;			//d3d is left handed#endif		vs_out.oPos = mul(p,mul(worldViewMatrix,prjMatrix));			return vs_out;}

the output pos vs_out.oPos I guess should be correct ... and since I'm sure that the position is in view space because the view space reconstruction is done in the pixel shader using the 4 far plane corne of the view frustum in view space I guess everything should be fine !

I pass the light position from the application after the viewMatrix is been multiplied, so the light position is in view space too !

D3DXVec4Transform(&VSLightPos,&D3DXVECTOR4((*itr)->getLightPos().x(*itr)->getLightPos().y,(*itr)->getLightPos().z,1.f),&pRenderer->getViewMatrix());...//pass the view space point light position to the shader as uniformm_pipelineEffect->setVector4("light.lightPos",VSLightPos);

it seems everything is in view space to me ;) but maybe I could have been missing something ... ;)

Thanks

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 34
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015643
×