how to render point sprites as correct spheres

Question asked by giorgius on Jun 7, 2014

I'm trying to render my fluid simulation(CUDA & DirectX 11) with liquid effect, I render particles as sprites

but I want to get this result

here is my geometry an pixel shader

1. [maxvertexcount(4)]
2. void mainGS(point GSPS_INPUT gInput[1],inout TriangleStream<GSPS_OUTPUT> TriStream)
3.
4.
5.   float size = 0.065
6.   matrix mv = View;
7.   float3 right  = normalize(float3(mv._11,mv._21,mv._31));
8.   float3 up    = normalize(float3(mv._12,mv._22,mv._32));
9.   //
10.   float3 posEye = mul( float4(gInput[0].Pos.xyz, 1.0),world).xyz;
11.   //
12.   float halfWidth  = size/length(posEye);
13.   float halfHeight = size/length(posEye);
14.   //
15.   float4 v[4];
16.   v[0] = float4(gInput[0].Pos + halfWidth*right - halfHeight*up, 1.0f);
17.   v[1] = float4(gInput[0].Pos + halfWidth*right + halfHeight*up, 1.0f);
18.   v[2] = float4(gInput[0].Pos - halfWidth*right - halfHeight*up, 1.0f);
19.   v[3] = float4(gInput[0].Pos - halfWidth*right + halfHeight*up, 1.0f);
20.   //
21.   //
22.   GSPS_OUTPUT output;
23.   [unroll]
24.   for(int i=0; i<4; ++i)
25.   {
26.
27.     //
28.     output.Pos    = mul(v[i], View);
29.     output.PosW    = (output.Pos.xyz);
30.
31.     output.Pos    = mul(output.Pos, Projection);
32.     output.Tex    = gQuadTexC[i];
33.     TriStream.Append(output);
34.   }
35.   TriStream.RestartStrip();
36.
38.
39. float4 PS(GSPS_OUTPUT input) : SV_TARGET
40.   float3 N;
41.   N.xy = input.Tex*float2(2.0f,-2.0f) + float2(-1.0f,1.0f);
42.   float mag = dot(N.xy, N.xy);
43.   if (mag > 1.0)
44.   {