PolylineShadowVolumeMorphFS.glsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. varying vec3 v_forwardDirectionEC;
  2. varying vec3 v_texcoordNormalizationAndHalfWidth;
  3. varying float v_batchId;
  4. #ifdef PER_INSTANCE_COLOR
  5. varying vec4 v_color;
  6. #else
  7. varying vec2 v_alignedPlaneDistances;
  8. varying float v_texcoordT;
  9. #endif
  10. float rayPlaneDistanceUnsafe(vec3 origin, vec3 direction, vec3 planeNormal, float planeDistance) {
  11. // We don't expect the ray to ever be parallel to the plane
  12. return (-planeDistance - dot(planeNormal, origin)) / dot(planeNormal, direction);
  13. }
  14. void main(void)
  15. {
  16. vec4 eyeCoordinate = gl_FragCoord;
  17. eyeCoordinate /= eyeCoordinate.w;
  18. #ifdef PER_INSTANCE_COLOR
  19. gl_FragColor = czm_gammaCorrect(v_color);
  20. #else // PER_INSTANCE_COLOR
  21. // Use distances for planes aligned with segment to prevent skew in dashing
  22. float distanceFromStart = rayPlaneDistanceUnsafe(eyeCoordinate.xyz, -v_forwardDirectionEC, v_forwardDirectionEC.xyz, v_alignedPlaneDistances.x);
  23. float distanceFromEnd = rayPlaneDistanceUnsafe(eyeCoordinate.xyz, v_forwardDirectionEC, -v_forwardDirectionEC.xyz, v_alignedPlaneDistances.y);
  24. // Clamp - distance to aligned planes may be negative due to mitering
  25. distanceFromStart = max(0.0, distanceFromStart);
  26. distanceFromEnd = max(0.0, distanceFromEnd);
  27. float s = distanceFromStart / (distanceFromStart + distanceFromEnd);
  28. s = (s * v_texcoordNormalizationAndHalfWidth.x) + v_texcoordNormalizationAndHalfWidth.y;
  29. czm_materialInput materialInput;
  30. materialInput.s = s;
  31. materialInput.st = vec2(s, v_texcoordT);
  32. materialInput.str = vec3(s, v_texcoordT, 0.0);
  33. czm_material material = czm_getMaterial(materialInput);
  34. gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);
  35. #endif // PER_INSTANCE_COLOR
  36. }