@Alkher wrote:
Hi !
I'm certainly doing something wrong. I'm drawings quads for particles and I also read from a depth texture (to not render them if needed to, and soft particles later)
It used to work in XNA, but not with MonoGame
Problem is: the UV coordinates in the input of the pixelshader correspond to the quad rendered. So the depth is applyed to each quad, one quad = one depth texture, not onto the whole screen.
So I wanted to get the normalized position of a pixel: in clipspace, x is [-1, 1], z [0, 1] (for opengl it is [-1, 1] right ?) , and y is in [0,1] with 0 bottom right.
Then I did this:float GetScreenDepth(float4 projectedpos){ //Scale-bias the clipping space pos from [-1,1] to [0,1] float2 NormalizedScreenPos = 0.5 * projectedpos.xy / projectedpos.w + 0.5; //Flip the y-coordinate as the origin of the window and the texture are different NormalizedScreenPos.y = 1 - NormalizedScreenPos.y; float dpth = depthModelsTexture.SampleLevel(DepthModelsSampler, NormalizedScreenPos, 0).r; return dpth; }
Where projectedpos is computed in the vertex like this:
Output.Position = mul(float4(Output.Position.xyz, 1), mul(View, Projection));then passed to GetScreenDepth() as
GetScreenDepth(input.ProjectedPos);
Where did I fail ?
As you can, the silhouette of the character is repeated for each quad and clip occurs on each of them too:
Posts: 3
Participants: 1