getClipAndStyleCode.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import Check from "../Core/Check.js";
  2. /**
  3. * Gets a GLSL snippet that clips a fragment using the `clip` function from {@link getClippingFunction} and styles it.
  4. *
  5. * @param {String} samplerUniformName Name of the uniform for the clipping planes texture sampler.
  6. * @param {String} matrixUniformName Name of the uniform for the clipping planes matrix.
  7. * @param {String} styleUniformName Name of the uniform for the clipping planes style, a vec4.
  8. * @returns {String} A string containing GLSL that clips and styles the current fragment.
  9. * @private
  10. */
  11. function getClipAndStyleCode(
  12. samplerUniformName,
  13. matrixUniformName,
  14. styleUniformName
  15. ) {
  16. //>>includeStart('debug', pragmas.debug);
  17. Check.typeOf.string("samplerUniformName", samplerUniformName);
  18. Check.typeOf.string("matrixUniformName", matrixUniformName);
  19. Check.typeOf.string("styleUniformName", styleUniformName);
  20. //>>includeEnd('debug');
  21. var shaderCode =
  22. " float clipDistance = clip(gl_FragCoord, " +
  23. samplerUniformName +
  24. ", " +
  25. matrixUniformName +
  26. "); \n" +
  27. " vec4 clippingPlanesEdgeColor = vec4(1.0); \n" +
  28. " clippingPlanesEdgeColor.rgb = " +
  29. styleUniformName +
  30. ".rgb; \n" +
  31. " float clippingPlanesEdgeWidth = " +
  32. styleUniformName +
  33. ".a; \n" +
  34. " if (clipDistance > 0.0 && clipDistance < clippingPlanesEdgeWidth) \n" +
  35. " { \n" +
  36. " gl_FragColor = clippingPlanesEdgeColor;\n" +
  37. " } \n";
  38. return shaderCode;
  39. }
  40. export default getClipAndStyleCode;