STUDIO TAMA


clippingVertex.glsl

1varying vec3 vPosition;
2
3void main() {
4  vPosition = (modelMatrix * vec4(position, 1.0)).xyz;
5}

clippingFragment.glsl

1uniform float cutX;
2uniform float cutY;
3uniform float cutZ;
4uniform vec4 uDiffuse;
5uniform vec3 uSphereCenter;
6uniform float uSphereRadius;
7uniform vec3 uBoxCenter;
8uniform float uBoxSize;
9
10varying vec3 vPosition;
11
12void main() {
13  float epsilon = 0.02;
14  
15  //case plane
16  if (vPosition.x > cutX) {
17    discard;
18  }
19  if (vPosition.y > cutY) {
20    discard;
21  }
22  if (vPosition.z < cutZ) {
23    discard;
24  }
25
26  //case sphere
27  if (length(vPosition - uSphereCenter) < uSphereRadius) {
28    discard;
29  }
30
31  //case box
32  if (vPosition.x < uBoxCenter.x + uBoxSize / 2.0 && vPosition.x > uBoxCenter.x - uBoxSize / 2.0 &&
33      vPosition.y < uBoxCenter.y + uBoxSize / 2.0 && vPosition.y > uBoxCenter.y - uBoxSize / 2.0 &&
34      vPosition.z < uBoxCenter.z + uBoxSize / 2.0 && vPosition.z > uBoxCenter.z - uBoxSize / 2.0) {
35    discard;
36  }
37
38
39  if(vPosition.x <= cutX && vPosition.x >= cutX - epsilon){
40    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
41    return;
42  }
43  if(vPosition.y <= cutY && vPosition.y >= cutY - epsilon){
44    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
45    return;
46  }
47  if(vPosition.z >= cutZ && vPosition.z <= cutZ + epsilon){
48    gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
49    return;
50  }
51
52
53  gl_FragColor = vec4(uDiffuse);
54}
55