• Create Account

### #Actualbelfegor

Posted 18 November 2012 - 07:41 AM

Let me explain my problem:

I have a sun, and let say it is at position 100, 50, 20

And then i use this code to obtain sun position in "texcoord space"
viewProj = cam.view * cam.proj;
...
D3DXVECTOR2 sunPosCS;
D3DXVECTOR4 clipSpaceLightPos;
D3DXVec4Transform(&clipSpaceLightPos, &D3DXVECTOR4(sunPos.x, sunPos.y, sunPos.z, 1.f), &viewProj);
D3DXVECTOR4 screenSpaceLightPos = clipSpaceLightPos / clipSpaceLightPos.w;
sunPosCS = D3DXVECTOR2(screenSpaceLightPos.x, screenSpaceLightPos.y);
sunPosCS.x = ((sunPosCS.x  + 1.0f) / 2.0f);
sunPosCS.y = ((-sunPosCS.y + 1.0f) / 2.0f);
...
effect->SetValue(hSunPosCS, sunPosCS, sizeof(D3DXVECTOR2));
...


Then i render fullscreen quad and use this pixel shader to be able to see where the sun is:
OUT.Color = distance(IN.TexCoord0, LightPosCS) < 0.05f ? float4(1.0f, 0.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 0.0f, 1.0f);


When i face my camera to look at the sun, and then just move left or right, the red circle (representing the sun) is also moving but it should not, because sun in real life is quite far away from the viewer and its movement on the screen should not be noticeable. If you understand what i mean? Any suggestions?

### #1belfegor

Posted 18 November 2012 - 07:41 AM

Let me explain my problem:

I have a sun, and let say it is at position 100, 50, 20

And then i use this code to obtain sun position in "texcoord space"
viewProj = cam.view * cam.proj;
...
D3DXVECTOR2 sunPosCS;
D3DXVECTOR4 clipSpaceLightPos;
D3DXVec4Transform(&clipSpaceLightPos, &D3DXVECTOR4(sunPos.x, sunPos.y, sunPos.z, 1.f), &viewProj);
D3DXVECTOR4 screenSpaceLightPos = clipSpaceLightPos / clipSpaceLightPos.w;
sunPosCS = D3DXVECTOR2(screenSpaceLightPos.x, screenSpaceLightPos.y);
sunPosCS.x = ((sunPosCS.x  + 1.0f) / 2.0f);
sunPosCS.y = ((-sunPosCS.y + 1.0f) / 2.0f);
...
effect->SetValue(hSunPosCS, sunPosCS, sizeof(D3DXVECTOR2));
...


Then i render fullscreen quad and use this pixel shader to be able to see where the sun is:
OUT.Color = distance(IN.TexCoord0, LightPosCS) < 0.05f ? float4(1.0f, 0.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 0.0f, 1.0f);


When i face my camera to look at the sun, and then just move left or right the, red circle (representing the sun) is also moving but it should not, because sun in real life is quite far away from the viewer and its movement on the screen should not be noticeable. If you understand what i mean? Any suggestions?