# Get normals from depth buffer

Hi, I’m working on my Fluid simulation using CUDA 4.2 and DirectX 11 and I want to get normals from depth buffer to shade fluid surface…

Here Is my depth buffer http://s24.postimg.org/drx0ldd90/Untitled1.jpg

I’m Using geometry shader to convert point to quad sprite, http://developer.download.nvidia.com/presentations/2010/gdc/Direct3D_Effects.pdf

But when I’m trying to get normals I get this - http://s29.postimg.org/x4s68mopz/Untitled2.jpg
but I must get this - http://s28.postimg.org/pwqnd5w7h/Untitled3.jpg

Here is my code:

GSPS_INPUT VS(VS_INPUT inp)
{

GSPS_INPUT vop;
vop.Pos = inp.pos;

//
return vop;

}

//================================================================
[maxvertexcount(4)]
void mainGS(point GSPS_INPUT gInput[1],inout TriangleStream<GSPS_OUTPUT> TriStream)
{

float3 up = float3(0.0f, 1.0f, 0.0f);
float3 look = gEyePos.xyz - gInput[0].Pos;
look.y = 0.0f;
look = normalize(look);
float3 right = cross(up, look);

//
float halfWidth  = 0.038f;
float halfHeight = 0.038f;
//
float4 v[4];
v[0] = float4(gInput[0].Pos + halfWidth*right - halfHeight*up, 1.0f);
v[1] = float4(gInput[0].Pos + halfWidth*right + halfHeight*up, 1.0f);
v[2] = float4(gInput[0].Pos - halfWidth*right - halfHeight*up, 1.0f);
v[3] = float4(gInput[0].Pos - halfWidth*right + halfHeight*up, 1.0f);

//
GSPS_OUTPUT output;
[unroll]
for(int i=0; i<4; ++i)
{
//
output.Pos		= mul(v[i], View);
output.PosW		= mul(output.Pos.xyz,world);
output.Pos		= mul(output.Pos, Projection);
output.Tex		= gQuadTexC[i];
TriStream.Append(output);
}
TriStream.RestartStrip();

}

//================================================================
float4 PS(GSPS_OUTPUT input) : SV_TARGET
{
float3 N;
N.xy = input.Tex*2.0f-1.0f;
float r2 = dot(N.xy, N.xy);
if (r2 > 1.0)
{
discard;
}

N.z = sqrt(1.0f-r2);
N = N * 0.5 + 0.5;

float4 pixelPos = float4(input.PosW + N*(particleRadius), 1.0);
float4 clipSpacePos = mul(pixelPos, Projection);
float depthval = (clipSpacePos.z / clipSpacePos.w);