David Catuhe 9 anni fa
parent
commit
c073b3763e

File diff suppressed because it is too large
+ 12 - 12
dist/preview release/babylon.core.js


File diff suppressed because it is too large
+ 848 - 847
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 12 - 12
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 11 - 2
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 12 - 12
dist/preview release/babylon.noworker.js


+ 9 - 0
src/Lights/Shadows/babylon.shadowGenerator.js

@@ -9,6 +9,7 @@ var BABYLON;
             this._blurBoxOffset = 0;
             this._bias = 0.00005;
             this._lightDirection = BABYLON.Vector3.Zero();
+            this.forceBackFacesOnly = false;
             this._darkness = 0;
             this._transparencyShadow = false;
             this._viewMatrix = BABYLON.Matrix.Zero();
@@ -80,8 +81,14 @@ var BABYLON;
                     if (mesh.useBones && mesh.computeBonesUsingShaders) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
+                    if (_this.forceBackFacesOnly) {
+                        engine.setState(true, 0, false, true);
+                    }
                     // Draw
                     mesh._processRendering(subMesh, _this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { return _this._effect.setMatrix("world", world); });
+                    if (_this.forceBackFacesOnly) {
+                        engine.setState(true, 0, false, false);
+                    }
                 }
                 else {
                     // Need to reset refresh rate of the shadowMap
@@ -351,6 +358,7 @@ var BABYLON;
             serializationObject.mapSize = this.getShadowMap().getRenderSize();
             serializationObject.useVarianceShadowMap = this.useVarianceShadowMap;
             serializationObject.usePoissonSampling = this.usePoissonSampling;
+            serializationObject.forceBackFacesOnly = this.forceBackFacesOnly;
             serializationObject.renderList = [];
             for (var meshIndex = 0; meshIndex < this.getShadowMap().renderList.length; meshIndex++) {
                 var mesh = this.getShadowMap().renderList[meshIndex];
@@ -384,6 +392,7 @@ var BABYLON;
             if (parsedShadowGenerator.bias !== undefined) {
                 shadowGenerator.bias = parsedShadowGenerator.bias;
             }
+            shadowGenerator.forceBackFacesOnly = parsedShadowGenerator.forceBackFacesOnly;
             return shadowGenerator;
         };
         ShadowGenerator._FILTER_NONE = 0;

+ 13 - 0
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -29,6 +29,8 @@
         private _bias = 0.00005;
         private _lightDirection = Vector3.Zero();
 
+        public forceBackFacesOnly = false;
+
         public get bias(): number {
             return this._bias;
         }
@@ -208,9 +210,17 @@
                         this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
 
+                    if (this.forceBackFacesOnly) {
+                        engine.setState(true, 0, false, true);
+                    }
+
                     // Draw
                     mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
                         (isInstance, world) => this._effect.setMatrix("world", world));
+
+                    if (this.forceBackFacesOnly) {
+                        engine.setState(true, 0, false, false);
+                    }
                 } else {
                     // Need to reset refresh rate of the shadowMap
                     this._shadowMap.resetRefreshCounter();
@@ -408,6 +418,7 @@
             serializationObject.mapSize = this.getShadowMap().getRenderSize();
             serializationObject.useVarianceShadowMap = this.useVarianceShadowMap;
             serializationObject.usePoissonSampling = this.usePoissonSampling;
+            serializationObject.forceBackFacesOnly = this.forceBackFacesOnly;
 
             serializationObject.renderList = [];
             for (var meshIndex = 0; meshIndex < this.getShadowMap().renderList.length; meshIndex++) {
@@ -450,6 +461,8 @@
                 shadowGenerator.bias = parsedShadowGenerator.bias;
             }
 
+            shadowGenerator.forceBackFacesOnly = parsedShadowGenerator.forceBackFacesOnly;
+
             return shadowGenerator;
         }
     }

+ 1 - 1
src/Materials/babylon.standardMaterial.js

@@ -313,7 +313,7 @@ var BABYLON;
                             }
                         }
                         effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
+                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
                     }
                 }
                 lightIndex++;

+ 1 - 1
src/Materials/babylon.standardMaterial.ts

@@ -364,7 +364,7 @@
                             }
                         }
                         effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
+                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
                     }
                 }
 

+ 12 - 11
src/Shaders/default.fragment.fx

@@ -312,11 +312,12 @@ float computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, fl
 {
 	vec3 directionToLight = vPositionW - lightPosition;
 	float depth = length(directionToLight);
-	float diskScale = (1.0 - (1.0 + depth * 3.0)) / mapSize;
 
-	depth = clamp(depth, 0., 1.);
+	depth = (depth - depthValues.x) / (depthValues.y - depthValues.x);
+	depth = clamp(depth, 0., 1.0);
 
-	directionToLight.y = 1.0 - directionToLight.y;
+	directionToLight = normalize(directionToLight);
+	directionToLight.y = -directionToLight.y;
 
 	float visibility = 1.;
 
@@ -329,10 +330,10 @@ float computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, fl
 	// Poisson Sampling
 	float biasedDepth = depth - bias;
 
-	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0] * diskScale)) < biasedDepth) visibility -= 0.25;
-	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1] * diskScale)) < biasedDepth) visibility -= 0.25;
-	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2] * diskScale)) < biasedDepth) visibility -= 0.25;
-	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[3] * diskScale)) < biasedDepth) visibility -= 0.25;
+	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[3] * mapSize)) < biasedDepth) visibility -= 0.25;
 
 	return  min(1.0, visibility + darkness);
 }
@@ -381,10 +382,10 @@ float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, flo
 	// Poisson Sampling
 	float biasedDepth = depth.z - bias;
 
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;
-	if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] * mapSize)) < biasedDepth) visibility -= 0.25;
+	if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] * mapSize)) < biasedDepth) visibility -= 0.25;
 
 	return  min(1.0, visibility + darkness);
 }

+ 1 - 1
src/Shaders/shadowMap.vertex.fx

@@ -82,7 +82,7 @@ void main(void)
 	vPosition = finalWorld * vec4(position, 1.0);
 	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
 #else
-	vPosition = viewProjection * finalWorld * vec4(position, 1.0)
+	vPosition = viewProjection * finalWorld * vec4(position, 1.0);
 	gl_Position = vPosition;
 #endif