Переглянути джерело

Add clip planes support in shadow generation.

sebavan 5 роки тому
батько
коміт
a29913f555

+ 1 - 0
dist/preview release/what's new.md

@@ -61,6 +61,7 @@
 - Added `textures/opacity.png` file to the Playground ([Popov72](https://github.com/Popov72))
 - Refactored the shadow generators code ([Popov72](https://github.com/Popov72))
 - Added preview area pop up for NME ([Kyle Belfort](https://github.com/belfortk))
+- Supports clip planes with shadows ([sebavan](http://www.github.com/sebavan))
 
 ### Engine
 

+ 26 - 1
src/Lights/Shadows/shadowGenerator.ts

@@ -1064,6 +1064,9 @@ export class ShadowGenerator implements IShadowGenerator {
             // Morph targets
             MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
 
+            // Clip planes
+            MaterialHelper.BindClipPlane(this._effect, scene);
+
             this._bindCustomEffectForRenderSubMeshForShadowMap(subMesh, this._effect);
 
             if (this.forceBackFacesOnly) {
@@ -1274,6 +1277,27 @@ export class ShadowGenerator implements IShadowGenerator {
             }
         }
 
+        // ClipPlanes
+        const scene = this._scene;
+        if (scene.clipPlane) {
+            defines.push("#define CLIPPLANE");
+        }
+        if (scene.clipPlane2) {
+            defines.push("#define CLIPPLANE2");
+        }
+        if (scene.clipPlane3) {
+            defines.push("#define CLIPPLANE3");
+        }
+        if (scene.clipPlane4) {
+            defines.push("#define CLIPPLANE4");
+        }
+        if (scene.clipPlane5) {
+            defines.push("#define CLIPPLANE5");
+        }
+        if (scene.clipPlane6) {
+            defines.push("#define CLIPPLANE6");
+        }
+
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
@@ -1298,7 +1322,8 @@ export class ShadowGenerator implements IShadowGenerator {
             this._cachedDefines = join;
 
             let shaderName = "shadowMap";
-            let uniforms = ["world", "mBones", "viewProjection", "diffuseMatrix", "lightData", "depthValues", "biasAndScale", "morphTargetInfluences", "boneTextureWidth"];
+            let uniforms = ["world", "mBones", "viewProjection", "diffuseMatrix", "lightData", "depthValues", "biasAndScale", "morphTargetInfluences", "boneTextureWidth",
+                            "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "vClipPlane5", "vClipPlane6"];
             let samplers = ["diffuseSampler", "boneSampler"];
 
             // Custom shader?

+ 4 - 0
src/Shaders/shadowMap.fragment.fx

@@ -16,8 +16,12 @@ uniform vec2 depthValues;
 varying float z;
 #endif
 
+#include<clipPlaneFragmentDeclaration>
+
 void main(void)
 {
+#include<clipPlaneFragment>
+
 #ifdef ALPHATEST
     if (texture2D(diffuseSampler, vUV).a < 0.4)
         discard;

+ 5 - 0
src/Shaders/shadowMap.vertex.fx

@@ -36,6 +36,8 @@ attribute vec2 uv2;
 varying float z;
 #endif
 
+#include<clipPlaneVertexDeclaration>
+
 void main(void)
 {
 vec3 positionUpdated = position;
@@ -98,4 +100,7 @@ gl_Position = viewProjection * worldPos;
         vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
     #endif
 #endif
+
+#include<clipPlaneVertex>
+
 }