David Catuhe %!s(int64=8) %!d(string=hai) anos
pai
achega
293b79bc44

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1189 - 1189
dist/preview release/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1189 - 1189
dist/preview release/babylon.module.d.ts


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

@@ -305,6 +305,8 @@
 
             if (this.useVarianceShadowMap || this.useBlurVarianceShadowMap) {
                 defines.push("#define VSM");
+            } else if (this.useExponentialShadowMap) {
+                defines.push("#define ESM");
             }
 
             if (this.getLight().needCube()) {

+ 28 - 1
src/Shaders/ShadersInclude/shadowsFragmentFunctions.fx

@@ -176,6 +176,33 @@
 
 	float computeShadowWithESM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)
 	{
-		return 1.0;
+		vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
+		vec3 depth = 0.5 * clipSpace + vec3(0.5);
+		vec2 uv = depth.xy;
+		float shadowPixelDepth = depth.z;
+
+		if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
+		{
+			return 1.0;
+		}
+	
+		#ifndef SHADOWFULLFLOAT
+			float shadowMapSample = unpack(texture2D(shadowSampler, uv));
+		#else
+			float shadowMapSample = texture2D(shadowSampler, uv).x;
+		#endif
+
+		const float shadowStrength = 250.0;
+	//	const float exponentLimit = 87.0; //this prevents float overflow in the exp, should be ~< ln(MAX_FLOAT)
+	//	float delta = shadowStrength * (shadowMapSample - shadowPixelDepth); // note: farclip - nearclip?
+	//	float esm = exp(clamp(delta, -exponentLimit, 0.0));
+		float esm = clamp(exp(shadowStrength * shadowPixelDepth) * shadowMapSample, 0., 1.);
+
+		// Apply fade out at frustum edge
+		const float fadeDistance = 0.07;
+		vec2 cs2 = clipSpace.xy * clipSpace.xy; //squarish falloff
+		float mask = smoothstep(1.0, 1.0 - fadeDistance, dot(cs2, cs2));
+
+		return mix(1.0, esm, mask) + darkness;
 	}
 #endif

+ 6 - 1
src/Shaders/shadowMap.fragment.fx

@@ -47,7 +47,12 @@ void main(void)
 	depth = clamp(depth, 0., 1.0);
 #else
 	float depth = vPosition.z / vPosition.w;
-	depth = depth * 0.5 + 0.5;
+	depth = depth * 0.5 + 0.5;	
+#endif
+
+#ifdef ESM
+	const float shadowStrength = 250.0;
+	depth = exp(-shadowStrength * depth);
 #endif
 
 #ifdef VSM