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