• Advertisement
Sign in to follow this  

What are those lights doing ?

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

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 this post


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


Link to post
Share on other sites
Quote:
Original post by My_Mind_Is_Going
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?


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 uniform
m_pipelineEffect->setVector4("light.lightPos",VSLightPos);




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

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement