You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CircleScanShader.glsl 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. in vec2 v_textureCoordinates;
  2. uniform sampler2D colorTexture;
  3. uniform sampler2D depthTexture;
  4. uniform vec3 centerWC;
  5. uniform vec3 normalWC;
  6. uniform float radius;
  7. uniform vec4 color;
  8. uniform float speed;
  9. float getDepth(){
  10. float z_window = czm_unpackDepth(texture(depthTexture, v_textureCoordinates));
  11. z_window = czm_reverseLogDepth(z_window);
  12. float n_range = czm_depthRange.near;
  13. float f_range = czm_depthRange.far;
  14. return (2.0 * z_window - n_range - f_range) / (f_range - n_range);
  15. }
  16. vec4 toEye(in vec2 uv, in float depth){
  17. vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));
  18. vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);
  19. posInCamera = posInCamera / posInCamera.w;
  20. return posInCamera;
  21. }
  22. vec3 pointProjectOnPlane(in vec3 planeNormal, in vec3 planeOrigin, in vec3 point){
  23. vec3 v01 = point - planeOrigin;
  24. float d = dot(planeNormal, v01) ;
  25. return (point - planeNormal * d);
  26. }
  27. void main() {
  28. out_FragColor = texture(colorTexture, v_textureCoordinates);
  29. float depth = getDepth();
  30. vec4 viewPos = toEye(v_textureCoordinates, depth);
  31. vec4 center = czm_view * vec4(centerWC,1);
  32. vec4 planeNormal = czm_view * vec4(normalWC,0);
  33. vec3 prjOnPlane = pointProjectOnPlane(planeNormal.xyz, center.xyz, viewPos.xyz);
  34. float dis = length(prjOnPlane.xyz - center.xyz);
  35. float time = fract(czm_frameNumber * speed / 1000.0);
  36. float temp = radius * time;
  37. if(dis < temp) {
  38. float f = 1.0 - abs(temp - dis) / temp;
  39. f = pow(f, 4.0);
  40. out_FragColor = mix(out_FragColor, color, f);
  41. }
  42. }