 # Sample currently set RenderTarget2D

-w = (0, 0, Lpos.z) so the last expression doesn’t make sense because only z-component will be non-zero.

So I had to guess your intentions as this where 15 is plane distance.

``````float2 lightDirection = lightPosition.xy - pixelPosition;
float2 offset = lightDirection * (15 / lightPosition.z) * screenMultiplier;
``````

Is that correct?

My intentions are correct, that’s why w.z is used, which is z component of w

Ah, I see. I thought the “.” was something else.

``````Here is Pixel shader
float4 OmniLightPS(VertexToPixel PSIn) : COLOR0
{
//We calculate in world space
//simple transform into world space (where one pixel is one world unit), this is our current point on background plane
float3 pointWS;
pointWS.xy = (PSIn.TexCoord.xy) * viewport;
pointWS.z = -planeDistance;

//Vector between light and point
float3 lightVec =  lightPos - pointWS;

//vector from plane we are projecting to, I leave this as whole float3 so its obvious what that was in equation, reduce this to float
float3 w = float3(0,0, -lightPos.z);

//light vec is from point to light so whole thing is *-1 which remove negative signs
float s = w.z / lightVec.z;

float3 samplePoint = lightPos + s * lightVec;

//sample texture, don't forget to get sample point coordinates back to screen space
float shadowTerm=  tex2D(Sampler,  samplePoint,xy/ viewport).a; //as Sample point Z is 0 as that was plane were targeting

//calculate attenuation
float intensity =  saturate(1.0f - length(lightVec) / (attuneation)) ; //sorry about type in attenuation

return float4(PSIn.Color.rgb * intensity * (1 - shadowTerm) ,1);
}``````

Okay, thanks. So the expression I wrote before is correct, right?

no, offset itself is (-light.z / lightVector.z) * lightVector
lightVector is whole vector, not just direction (that implies normalized vector)

I’m calculating the offset from the destination pixel not the light position, sorry forgot to mention that.