getClipAndStyleCode.js 1.6 KB

123456789101112131415161718192021222324252627282930
  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(samplerUniformName, matrixUniformName, styleUniformName) {
  12. //>>includeStart('debug', pragmas.debug);
  13. Check.typeOf.string('samplerUniformName', samplerUniformName);
  14. Check.typeOf.string('matrixUniformName', matrixUniformName);
  15. Check.typeOf.string('styleUniformName', styleUniformName);
  16. //>>includeEnd('debug');
  17. var shaderCode =
  18. ' float clipDistance = clip(gl_FragCoord, ' + samplerUniformName + ', ' + matrixUniformName + '); \n' +
  19. ' vec4 clippingPlanesEdgeColor = vec4(1.0); \n' +
  20. ' clippingPlanesEdgeColor.rgb = ' + styleUniformName + '.rgb; \n' +
  21. ' float clippingPlanesEdgeWidth = ' + styleUniformName + '.a; \n' +
  22. ' if (clipDistance > 0.0 && clipDistance < clippingPlanesEdgeWidth) \n' +
  23. ' { \n' +
  24. ' gl_FragColor = clippingPlanesEdgeColor;\n' +
  25. ' } \n';
  26. return shaderCode;
  27. }
  28. export default getClipAndStyleCode;