ソースを参照

Fix Bones Fallback shadow and glow

Sebastien Vandenberghe 6 年 前
コミット
b64a287120

+ 6 - 2
src/Layers/effectLayer.ts

@@ -18,7 +18,7 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "../States/index"
 import { BaseTexture } from "../Materials/Textures/baseTexture";
 import { Texture } from "../Materials/Textures/texture";
 import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
-import { Effect } from "../Materials/effect";
+import { Effect, EffectFallbacks } from "../Materials/effect";
 import { Material } from "../Materials/material";
 import { MaterialHelper } from "../Materials/materialHelper";
 import { Constants } from "../Engines/constants";
@@ -468,6 +468,7 @@ export abstract class EffectLayer {
         }
 
         // Bones
+        const fallbacks = new EffectFallbacks();
         if (mesh.useBones && mesh.computeBonesUsingShaders) {
             attribs.push(VertexBuffer.MatricesIndicesKind);
             attribs.push(VertexBuffer.MatricesWeightsKind);
@@ -477,6 +478,9 @@ export abstract class EffectLayer {
             }
             defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
             defines.push("#define BonesPerMesh " + (mesh.skeleton ? (mesh.skeleton.bones.length + 1) : 0));
+            if (mesh.numBoneInfluencers > 0) {
+                fallbacks.addCPUSkinningFallback(0, mesh);
+            }
         } else {
             defines.push("#define NUM_BONE_INFLUENCERS 0");
         }
@@ -511,7 +515,7 @@ export abstract class EffectLayer {
                     "glowColor", "morphTargetInfluences",
                     "diffuseMatrix", "emissiveMatrix", "opacityMatrix", "opacityIntensity"],
                 ["diffuseSampler", "emissiveSampler", "opacitySampler"], join,
-                undefined, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers });
+                fallbacks, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers });
         }
 
         return this._effectLayerMapGenerationEffect.isReady();

+ 6 - 2
src/Lights/Shadows/shadowGenerator.ts

@@ -13,7 +13,7 @@ import { Light } from "../../Lights/light";
 import { Material } from "../../Materials/material";
 import { MaterialDefines } from "../../Materials/materialDefines";
 import { MaterialHelper } from "../../Materials/materialHelper";
-import { Effect } from "../../Materials/effect";
+import { Effect, EffectFallbacks } from "../../Materials/effect";
 import { Texture } from "../../Materials/Textures/texture";
 import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture";
 
@@ -1186,6 +1186,7 @@ export class ShadowGenerator implements IShadowGenerator {
         }
 
         // Bones
+        const fallbacks = new EffectFallbacks();
         if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
             attribs.push(VertexBuffer.MatricesIndicesKind);
             attribs.push(VertexBuffer.MatricesWeightsKind);
@@ -1195,6 +1196,9 @@ export class ShadowGenerator implements IShadowGenerator {
             }
             const skeleton = mesh.skeleton;
             defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
+            if (mesh.numBoneInfluencers > 0) {
+                fallbacks.addCPUSkinningFallback(0, mesh);
+            }
 
             if (skeleton.isUsingTextureForMatrices) {
                 defines.push("#define BONETEXTURE");
@@ -1275,7 +1279,7 @@ export class ShadowGenerator implements IShadowGenerator {
             this._effect = this._scene.getEngine().createEffect(shaderName,
                 attribs, uniforms,
                 samplers, join,
-                undefined, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers });
+                fallbacks, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers });
         }
 
         if (!this._effect.isReady()) {

+ 0 - 4
src/Materials/Background/backgroundMaterial.ts

@@ -848,10 +848,6 @@ export class BackgroundMaterial extends PushMaterial {
 
             MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
 
-            if (defines.NUM_BONE_INFLUENCERS > 0) {
-                fallbacks.addCPUSkinningFallback(0, mesh);
-            }
-
             //Attributes
             var attribs = [VertexBuffer.PositionKind];
 

+ 0 - 4
src/Materials/PBR/pbrBaseMaterial.ts

@@ -1130,10 +1130,6 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             fallbacks.addFallback(fallbackRank++, "VERTEXCOLOR");
         }
 
-        if (defines.NUM_BONE_INFLUENCERS > 0) {
-            fallbacks.addCPUSkinningFallback(fallbackRank++, mesh);
-        }
-
         if (defines.MORPHTARGETS) {
             fallbacks.addFallback(fallbackRank++, "MORPHTARGETS");
         }

+ 4 - 1
src/Materials/effect.ts

@@ -86,7 +86,7 @@ export class EffectFallbacks {
      */
     public reduce(currentDefines: string, effect: Effect): string {
         // First we try to switch to CPU skinning
-        if (this._mesh && this._mesh.computeBonesUsingShaders && this._mesh.numBoneInfluencers > 0 && this._mesh.material) {
+        if (this._mesh && this._mesh.computeBonesUsingShaders && this._mesh.numBoneInfluencers > 0) {
             this._mesh.computeBonesUsingShaders = false;
             currentDefines = currentDefines.replace("#define NUM_BONE_INFLUENCERS " + this._mesh.numBoneInfluencers, "#define NUM_BONE_INFLUENCERS 0");
             effect._bonesComputationForcedToCPU = true;
@@ -96,6 +96,9 @@ export class EffectFallbacks {
                 var otherMesh = scene.meshes[index];
 
                 if (!otherMesh.material) {
+                    if (!this._mesh.material && otherMesh.computeBonesUsingShaders && otherMesh.numBoneInfluencers > 0) {
+                        otherMesh.computeBonesUsingShaders = false;
+                    }
                     continue;
                 }
 

+ 0 - 30
src/Shaders/ShadersInclude/bones300Declaration.fx

@@ -1,30 +0,0 @@
-#if NUM_BONE_INFLUENCERS > 0
-	#ifdef BONETEXTURE
-		uniform sampler2D boneSampler;
-	#else
-		uniform mat4 mBones[BonesPerMesh];
-	#endif	
-
-		in vec4 matricesIndices;
-		in vec4 matricesWeights;
-		#if NUM_BONE_INFLUENCERS > 4
-			in vec4 matricesIndicesExtra;
-			in vec4 matricesWeightsExtra;
-		#endif
-
-	#ifdef BONETEXTURE
-		mat4 readMatrixFromRawSampler(sampler2D smp, float index)
-		{
-			mat4 result;
-			float offset = index  * 4.0;	
-			float dx = 1.0 / boneTextureWidth;
-
-			result[0] = texture(smp, vec2(dx * (offset + 0.5), 0.));
-			result[1] = texture(smp, vec2(dx * (offset + 1.5), 0.));
-			result[2] = texture(smp, vec2(dx * (offset + 2.5), 0.));
-			result[3] = texture(smp, vec2(dx * (offset + 3.5), 0.));
-
-			return result;
-		}
-	#endif
-#endif

+ 0 - 15
src/Shaders/ShadersInclude/clipPlaneFragmentDeclaration2.fx

@@ -1,15 +0,0 @@
-#ifdef CLIPPLANE
-	in float fClipDistance;
-#endif
-
-#ifdef CLIPPLANE2
-	in float fClipDistance2;
-#endif
-
-#ifdef CLIPPLANE3
-	in float fClipDistance3;
-#endif
-
-#ifdef CLIPPLANE4
-	in float fClipDistance4;
-#endif

+ 0 - 19
src/Shaders/ShadersInclude/clipPlaneVertexDeclaration2.fx

@@ -1,19 +0,0 @@
-#ifdef CLIPPLANE
-	uniform vec4 vClipPlane;
-	out float fClipDistance;
-#endif
-
-#ifdef CLIPPLANE2
-	uniform vec4 vClipPlane2;
-	out float fClipDistance2;
-#endif
-
-#ifdef CLIPPLANE3
-	uniform vec4 vClipPlane3;
-	out float fClipDistance3;
-#endif
-
-#ifdef CLIPPLANE4
-	uniform vec4 vClipPlane4;
-	out float fClipDistance4;
-#endif

+ 0 - 8
src/Shaders/ShadersInclude/instances300Declaration.fx

@@ -1,8 +0,0 @@
-#ifdef INSTANCES
-	in vec4 world0;
-	in vec4 world1;
-	in vec4 world2;
-	in vec4 world3;
-#else
-	uniform mat4 world;
-#endif