cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

giorgius
Journeyman III

how to render point sprites as correct spheres

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

97222_1401451495_depth.png

but I want to get this result


97223_1401451545_depth.jpg


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, View); 
  29.     output.PosW    = (output.Pos.xyz); 
  30.  
  31.     output.Pos    = mul(output.Pos, Projection); 
  32.     output.Tex    = gQuadTexC
  33.     TriStream.Append(output); 
  34.   } 
  35.   TriStream.RestartStrip(); 
  36.  
  37. //pixel shader 
  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.   { 
  45.     discard; 
  46.   } 
  47.  
  48.   N.z = sqrt(1.0f-mag); 
  49.   N = N * 0.5 + 0.5
  50.  
  51.  
  52.   float4 pixelPos = float4(input.PosW + N*(1/32), 1.0); 
  53.   float4 clipSpacePos = mul(pixelPos, Projection); 
  54.   float depthval = (clipSpacePos.z / clipSpacePos.w); 


0 Likes
0 Replies