fluidRenderingParticleDepth.fragment.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // Do not edit.
  2. import { ShaderStore } from "../Engines/shaderStore.js";
  3. const name = "fluidRenderingParticleDepthPixelShader";
  4. const shader = `uniform mat4 projection;varying vec2 uv;varying vec3 viewPos;varying float sphereRadius;
  5. #ifdef FLUIDRENDERING_VELOCITY
  6. varying float velocityNorm;
  7. #endif
  8. void main(void) {vec3 normal;normal.xy=uv*2.0-1.0;float r2=dot(normal.xy,normal.xy);if (r2>1.0) discard;normal.z=sqrt(1.0-r2);
  9. #ifndef FLUIDRENDERING_RHS
  10. normal.z=-normal.z;
  11. #endif
  12. vec4 realViewPos=vec4(viewPos+normal*sphereRadius,1.0);vec4 clipSpacePos=projection*realViewPos;
  13. #ifdef WEBGPU
  14. gl_FragDepth=clipSpacePos.z/clipSpacePos.w;
  15. #else
  16. gl_FragDepth=(clipSpacePos.z/clipSpacePos.w)*0.5+0.5;
  17. #endif
  18. #ifdef FLUIDRENDERING_RHS
  19. realViewPos.z=-realViewPos.z;
  20. #endif
  21. #ifdef FLUIDRENDERING_VELOCITY
  22. glFragColor=vec4(realViewPos.z,velocityNorm,0.,1.);
  23. #else
  24. glFragColor=vec4(realViewPos.z,0.,0.,1.);
  25. #endif
  26. }
  27. `;
  28. // Sideeffect
  29. ShaderStore.ShadersStore[name] = shader;
  30. /** @internal */
  31. export const fluidRenderingParticleDepthPixelShader = { name, shader };
  32. //# sourceMappingURL=fluidRenderingParticleDepth.fragment.js.map