Преглед на файлове

Merge pull request #2308 from sebavan/Development

Development
David Catuhe преди 8 години
родител
ревизия
e19a02e3dd

+ 1 - 1
materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts

@@ -69,7 +69,7 @@ module BABYLON {
         public INVERTNORMALMAPX = false;
         public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
-        public SHADOWFULLFLOAT = false;
+        public SHADOWFLOAT = false;
 
         public METALLICWORKFLOW = false;
         public METALLICMAP = false;

+ 7 - 16
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -69,16 +69,7 @@
                 this._boxBlurPostprocess.dispose();
             }
 
-            var textureType: number;
-            var caps = this._scene.getEngine().getCaps();
-            if (this._useFullFloat) {
-                textureType = Engine.TEXTURETYPE_FLOAT;
-            }
-            else {
-                textureType = Engine.TEXTURETYPE_UNSIGNED_INT;
-            }
-
-            this._boxBlurPostprocess = new PostProcess("DepthBoxBlur", "depthBoxBlur", ["screenSize", "boxOffset"], [], 1.0 / this.blurScale, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define OFFSET " + value, textureType);
+            this._boxBlurPostprocess = new PostProcess("DepthBoxBlur", "depthBoxBlur", ["screenSize", "boxOffset"], [], 1.0 / this.blurScale, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, "#define OFFSET " + value, this._textureType);
             this._boxBlurPostprocess.onApplyObservable.add(effect => {
                 effect.setFloat2("screenSize", this._mapSize / this.blurScale, this._mapSize / this.blurScale);
             });
@@ -172,7 +163,6 @@
         private _currentFaceIndex = 0;
         private _currentFaceIndexCache = 0;
 
-        private _useFullFloat = true;
         private _textureType: number;
         private _isCube = false;
 
@@ -193,12 +183,13 @@
 
             // Texture type fallback from float to int if not supported.
             var caps = this._scene.getEngine().getCaps();
-            if (caps.textureFloat && caps.textureFloatLinearFiltering && caps.textureFloatRender) {
-                this._useFullFloat = true;
+            if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {
                 this._textureType = Engine.TEXTURETYPE_FLOAT;
             }
+            else if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {
+                this._textureType = Engine.TEXTURETYPE_HALF_FLOAT;
+            }
             else {
-                this._useFullFloat = false;
                 this._textureType = Engine.TEXTURETYPE_UNSIGNED_INT;
             }
 
@@ -367,8 +358,8 @@
         public isReady(subMesh: SubMesh, useInstances: boolean): boolean {
             var defines = [];
 
-            if (this._useFullFloat) {
-                defines.push("#define FULLFLOAT");
+            if (this._textureType !== Engine.TEXTURETYPE_UNSIGNED_INT) {
+                defines.push("#define FLOAT");
             }
 
             if (this.useExponentialShadowMap || this.useBlurExponentialShadowMap) {

+ 1 - 1
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -65,7 +65,7 @@
         public INVERTNORMALMAPX = false;
         public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
-        public SHADOWFULLFLOAT = false;
+        public SHADOWFLOAT = false;
         public NORMALXYSCALE = true;
         public USERIGHTHANDEDSYSTEM = false;
 

+ 4 - 2
src/Materials/babylon.materialHelper.ts

@@ -172,11 +172,13 @@
 
             let caps = scene.getEngine().getCaps();
 
-            if (defines["SHADOWFULLFLOAT"] === undefined) {
+            if (defines["SHADOWFLOAT"] === undefined) {
                 needRebuild = true;
             }
 
-            defines["SHADOWFULLFLOAT"] = (shadowEnabled && caps.textureFloat && caps.textureFloatLinearFiltering && caps.textureFloatRender);
+            defines["SHADOWFLOAT"] = shadowEnabled && 
+                                    ((caps.textureFloatRender && caps.textureFloatLinearFiltering) ||
+                                         (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering));
             defines["LIGHTMAPEXCLUDED"] = lightmapMode;
 
             if (needRebuild) {

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

@@ -56,7 +56,7 @@ module BABYLON {
         public INVERTNORMALMAPX = false;
         public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
-        public SHADOWFULLFLOAT = false;
+        public SHADOWFLOAT = false;
         public CAMERACOLORGRADING = false;
         public CAMERACOLORCURVES = false;
         public MORPHTARGETS = false;

+ 7 - 7
src/Shaders/ShadersInclude/shadowsFragmentFunctions.fx

@@ -1,5 +1,5 @@
 #ifdef SHADOWS
-	#ifndef SHADOWFULLFLOAT
+	#ifndef SHADOWFLOAT
 		float unpack(vec4 color)
 		{
 			const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);
@@ -19,7 +19,7 @@
 		directionToLight = normalize(directionToLight);
 		directionToLight.y = -directionToLight.y;
 		
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			float shadow = unpack(textureCube(shadowSampler, directionToLight));
 		#else
 			float shadow = textureCube(shadowSampler, directionToLight).x;
@@ -53,7 +53,7 @@
 
 		// Poisson Sampling
 
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0] * mapSize)) < depth) visibility -= 0.25;
 			if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1] * mapSize)) < depth) visibility -= 0.25;
 			if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2] * mapSize)) < depth) visibility -= 0.25;
@@ -78,7 +78,7 @@
 		directionToLight = normalize(directionToLight);
 		directionToLight.y = -directionToLight.y;
 		
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			float shadowMapSample = unpack(textureCube(shadowSampler, directionToLight));
 		#else
 			float shadowMapSample = textureCube(shadowSampler, directionToLight).x;
@@ -99,7 +99,7 @@
 			return 1.0;
 		}
 
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			float shadow = unpack(texture2D(shadowSampler, uv));
 		#else
 			float shadow = texture2D(shadowSampler, uv).x;
@@ -133,7 +133,7 @@
 
 		// Poisson Sampling
 
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] * mapSize)) < depth.z) visibility -= 0.25;
 			if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] * mapSize)) < depth.z) visibility -= 0.25;
 			if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] * mapSize)) < depth.z) visibility -= 0.25;
@@ -160,7 +160,7 @@
 			return 1.0;
 		}
 	
-		#ifndef SHADOWFULLFLOAT
+		#ifndef SHADOWFLOAT
 			float shadowMapSample = unpack(texture2D(shadowSampler, uv));
 		#else
 			float shadowMapSample = texture2D(shadowSampler, uv).x;

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

@@ -1,4 +1,4 @@
-#ifndef FULLFLOAT
+#ifndef FLOAT
 vec4 pack(float depth)
 {
 	const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
@@ -49,9 +49,9 @@ void main(void)
 	depth = exp(-min(87., biasAndScale.y * depth));
 #endif
 
-#ifndef FULLFLOAT
-	gl_FragColor = pack(depth);
-#else
+#ifdef FLOAT
 	gl_FragColor = vec4(depth, 1.0, 1.0, 1.0);
+#else
+	gl_FragColor = pack(depth);
 #endif
 }

+ 3 - 0
src/babylon.engine.ts

@@ -746,6 +746,9 @@
 
             this._caps.textureHalfFloat = this._webGLVersion > 1 || this._gl.getExtension('OES_texture_half_float');
             this._caps.textureHalfFloatLinearFiltering = this._webGLVersion > 1 || (this._caps.textureHalfFloat && this._gl.getExtension('OES_texture_half_float_linear'));
+            if (this._webGLVersion > 1) {
+                Engine.HALF_FLOAT_OES = 0x140B;
+            }
             this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer();
 
             this._caps.textureLOD = this._webGLVersion > 1 || this._gl.getExtension('EXT_shader_texture_lod');