PointCloudEyeDomeLighting.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#extension GL_EXT_frag_depth : enable\n\
  3. uniform sampler2D u_pointCloud_colorGBuffer;\n\
  4. uniform sampler2D u_pointCloud_depthGBuffer;\n\
  5. uniform vec2 u_distanceAndEdlStrength;\n\
  6. varying vec2 v_textureCoordinates;\n\
  7. vec2 neighborContribution(float log2Depth, vec2 offset)\n\
  8. {\n\
  9. float dist = u_distanceAndEdlStrength.x;\n\
  10. vec2 texCoordOrig = v_textureCoordinates + offset * dist;\n\
  11. vec2 texCoord0 = v_textureCoordinates + offset * floor(dist);\n\
  12. vec2 texCoord1 = v_textureCoordinates + offset * ceil(dist);\n\
  13. float depthOrLogDepth0 = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord0));\n\
  14. float depthOrLogDepth1 = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord1));\n\
  15. if (depthOrLogDepth0 == 0.0 || depthOrLogDepth1 == 0.0) {\n\
  16. return vec2(0.0);\n\
  17. }\n\
  18. float depthMix = mix(depthOrLogDepth0, depthOrLogDepth1, fract(dist));\n\
  19. vec4 eyeCoordinate = czm_windowToEyeCoordinates(texCoordOrig, depthMix);\n\
  20. return vec2(max(0.0, log2Depth - log2(-eyeCoordinate.z / eyeCoordinate.w)), 1.0);\n\
  21. }\n\
  22. void main()\n\
  23. {\n\
  24. float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates));\n\
  25. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depthOrLogDepth);\n\
  26. eyeCoordinate /= eyeCoordinate.w;\n\
  27. float log2Depth = log2(-eyeCoordinate.z);\n\
  28. if (depthOrLogDepth == 0.0)\n\
  29. {\n\
  30. discard;\n\
  31. }\n\
  32. vec4 color = texture2D(u_pointCloud_colorGBuffer, v_textureCoordinates);\n\
  33. vec2 texelSize = 1.0 / czm_viewport.zw;\n\
  34. vec2 responseAndCount = vec2(0.0);\n\
  35. responseAndCount += neighborContribution(log2Depth, vec2(-texelSize.x, 0.0));\n\
  36. responseAndCount += neighborContribution(log2Depth, vec2(+texelSize.x, 0.0));\n\
  37. responseAndCount += neighborContribution(log2Depth, vec2(0.0, -texelSize.y));\n\
  38. responseAndCount += neighborContribution(log2Depth, vec2(0.0, +texelSize.y));\n\
  39. float response = responseAndCount.x / responseAndCount.y;\n\
  40. float strength = u_distanceAndEdlStrength.y;\n\
  41. float shade = exp(-response * 300.0 * strength);\n\
  42. color.rgb *= shade;\n\
  43. gl_FragColor = vec4(color);\n\
  44. #ifdef LOG_DEPTH\n\
  45. czm_writeLogDepth(1.0 + (czm_projection * vec4(eyeCoordinate.xyz, 1.0)).w);\n\
  46. #else\n\
  47. gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(eyeCoordinate.xyz, 1.0)).z;\n\
  48. #endif\n\
  49. }\n\
  50. ";