# Lotes

Member

8

131 Neutral

• Rank
Newbie

2. ## Problems with Alchemy SSAO implementation

I now think the problem is, that on the even surfaces the dot product of v and the normal (for one sample) is not zero. The "getViewPosition" function must be wrong... This function should reconstruct the world space coordinate from texture coordinate (uv) and the depth buffer. My current version of "getWorldPosition" is something like that (it is not correct so far):   float3 getWorldPosition(float2 uv) {     float depth = readDepth(uv);     float4 projectionPosition = float4(uv, depth, 1);     float4 worldPosition = mul(inverseProjection, projectionPosition);         worldPosition /= worldPosition.w;         worldPosition = mul(inverseView, worldPosition);             return worldPosition.xyz; } What is the right way of reconstructing the world space coordinate?

4. ## Render depth to texture

It works with this code. But I find it very ugly to use a magic number like 25 as a factor in this case. How can I calculate this factor from my matrices? :-/ [CODE] VertexToPixel PositionsVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float4 inColor: COLOR) { VertexToPixel Output = (VertexToPixel)0; float4x4 preViewProjection = mul (xView, xProjection); float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); Output.Position = mul(inPos, preWorldViewProjection); Output.Color = 1; Output.Color.rgb = Output.Position.z; return Output; } PixelToFrame PositionsPS(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; Output.Color = PSIn.Color/25; return Output; } [/CODE] My cubes have a dimension of 0.9x0.9x0.9 at positions (0,0,-10), (0,0,-9) ... (0,0,10). My camera is at (0,10,-20) looking at (0,0,0).
5. ## Render depth to texture

they are drawn (black cubes on blue background). changing 200 to 200.0 did not help. i think in hlsl it does not matter.
6. ## Render depth to texture

Here is it... [CODE] VertexToPixel PositionsVS( float4 inPos : POSITION) { VertexToPixel Output = (VertexToPixel)0; float4x4 preWorldView= mul (xWorld, xView); Output.Position = mul(inPos, preWorldView); Output.Color = 1; Output.Color.rgb = Output.Position.z/200; Output.Position = mul(Output.Position,xProjection); return Output; } PixelToFrame PositionsPS(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; Output.Color = PSIn.Color; return Output; } [/CODE]
7. ## Render depth to texture

Thanks. My far clip plane has a distance of 200.0f. Is that the value for zFar? When I tried out your code my cubes became entirely black :-/.
8. ## Render depth to texture

Hi, I work with XNA and I want to render the depth information of my scene into a texture. But all I get is my scene (some cubes) completly colored in white. So the depth information I determined is greater or equal 1.0 I guess. How is it done right? I googled a lot, but I can't find my mistake :'-(... Do I have to make any settings in XNA before rendering? Here are the HLSL shaders I use: [CODE] float4x4 xView; float4x4 xProjection; float4x4 xWorld; struct VertexToPixel { float4 Position : POSITION; float4 Color : COLOR0; }; struct PixelToFrame { float4 Color : COLOR0; }; VertexToPixel PositionsVS( float4 inPos : POSITION) { float4x4 preViewProjection = mul (xView, xProjection); float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); VertexToPixel Output = (VertexToPixel)0; Output.Position = mul(inPos, preWorldViewProjection); Output.Color.a = 1; Output.Color.rgb = Output.Position.z/Output.Position.w; return Output; } PixelToFrame PositionsPS(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; Output.Color = PSIn.Color; return Output; } technique Positions { pass Pass0 { VertexShader = compile vs_3_0 PositionsVS(); PixelShader = compile ps_3_0 PositionsPS(); } } [/CODE]