• Create Account

### #Actualjeremie009

Posted 27 September 2012 - 08:35 AM

I've been trying to get my world space position of my pixel but I'm missing something.
I'm using a orthographic view for a 2.5d game. My depth is linear and this is my code.

float3 lightPos  = lightPosition;// light World position use to draw the sphere volume
float2 texCoord = PostProjToScreen(PSIn.lightPosition)+halfPixel;// use to project the normal and depth texture.

float depth = tex2D(depthMap, texCoord);

float4 position;

position.x = texCoord.x *2-1;
position.y = (1-texCoord.y)*2-1;
position.z = depth.r;
position.w = 1;
position = mul(position, inViewProjection);
//position.xyz/=position.w; // I comment it but even without it it doesn't work

float4 normal = (tex2D(normalMap, texCoord)-.5f) * 2;
normal = normalize(normal);

float3 lightDirection = normalize(lightPos-position);
float att = saturate(1.0f - length(lightDirection) /attenuation);
float lightning = saturate (dot(normal, lightDirection));

return float4(lightColor* lightning*att, 1);


I'm using a sphere but it's not working the way I want. I reproject the textures properly onto the sphere but the light coordinates in the pixel shader seems to be stuck at zero even if when I move the camera light volume update accordingly. I'm using an orthographic view ( non off centered) and xna.

### #2jeremie009

Posted 27 September 2012 - 12:32 AM

I've been trying to get my world space position of my pixel but I'm missing something.
I'm using a orthographic view for a 2.5d game. My depth is linear and this is my code.

float3 lightPos  = lightPosition;// light World position use to draw the sphere volume
float2 texCoord = PostProjToScreen(PSIn.lightPosition)+halfPixel;// use to project the normal and depth texture.

float depth = tex2D(depthMap, texCoord);

float4 position;

position.x = texCoord.x *2-1;
position.y = (1-texCoord.y)*2-1;
position.z = depth.r;
position.w = 1;
position = mul(position, inViewProjection);
//position.xyz/=position.w; // I comment it but even without it it doesn't work

float4 normal = (tex2D(normalMap, texCoord)-.5f) * 2;
normal = normalize(normal);

float3 lightDirection = normalize(lightPos-position);
float att = saturate(1.0f - length(lightDirection) /attenuation);
float lightning = saturate (dot(normal, lightDirection));

return float4(lightColor* lightning*att, 1);


I'm using a sphere but it's not working the way I want. I reproject the textures properly onto the sphere but the light coordinates in the pixel shader seems to be stuck at zero even if when I move the camera light volume update accordingly. I'm using an orthographic view ( non off centered) and xna.

### #1jeremie009

Posted 27 September 2012 - 12:30 AM

I've been trying to get my world space position of my pixel but I'm missing something.
I'm using a orthographic view for a 2.5d game. My depth is linear and this is my code.

float3 lightPos  = lightPosition;// light World position use to draw the sphere volume
float2 texCoord = PostProjToScreen(PSIn.lightPosition)+halfPixel;// use to project the normal and depth texture.

float depth = tex2D(depthMap, texCoord);

float4 position;

position.x = texCoord.x *2-1;
position.y = (1-texCoord.y)*2-1;
position.z = depth.r;
position.w = 1;
position = mul(position, inViewProjection);
//position.xyz/=position.w; // I comment it but even without it it doesn't work

float4 normal = (tex2D(normalMap, texCoord)-.5f) * 2;
normal = normalize(normal);

float3 lightDirection = normalize(lightPos-position);
float att = saturate(1.0f - length(lightDirection) /attenuation);
float lightning = saturate (dot(normal, lightDirection));

return float4(lightColor* lightning*att, 1);


I'm using a sphere but it's not working the way I want. I reproject the textures properly onto the sphere but the light coordinates in the pixel shader seems to be stuck at zero even if when I move the camera light volume update accordingly.

PARTNERS