瀏覽代碼

Shadow INT

Sebastien Vandenberghe 8 年之前
父節點
當前提交
98e1700ebd

文件差異過大導致無法顯示
+ 1045 - 1037
dist/preview release/customConfigurations/minimalViewer/babylon.d.ts


文件差異過大導致無法顯示
+ 28 - 27
dist/preview release/customConfigurations/minimalViewer/babylon.js


文件差異過大導致無法顯示
+ 42 - 14
dist/preview release/customConfigurations/minimalViewer/babylon.max.js


文件差異過大導致無法顯示
+ 1045 - 1037
dist/preview release/customConfigurations/minimalViewer/babylon.module.d.ts


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

@@ -398,6 +398,11 @@
                 this._kernelBlurXPostprocess.autoClear = false;
                 this._kernelBlurYPostprocess.autoClear = false;
 
+                if (this._textureType === Engine.TEXTURETYPE_UNSIGNED_INT) {
+                    (<BlurPostProcess>this._kernelBlurXPostprocess).packedFloat = true;
+                    (<BlurPostProcess>this._kernelBlurYPostprocess).packedFloat = true;
+                }
+
                 this._blurPostProcesses = [this._kernelBlurXPostprocess, this._kernelBlurYPostprocess];
             }
             else {
@@ -490,10 +495,8 @@
 
         private _applyFilterValues(): void {
             if (this.filter === ShadowGenerator.FILTER_NONE) {
-                this._shadowMap.anisotropicFilteringLevel = 1;
                 this._shadowMap.updateSamplingMode(Texture.NEAREST_SAMPLINGMODE);
             } else {
-                this._shadowMap.anisotropicFilteringLevel = 16;
                 this._shadowMap.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);
             }
         }
@@ -519,17 +522,18 @@
 
             // Alpha test
             if (material && material.needAlphaTesting()) {
-                defines.push("#define ALPHATEST");
-                if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
-                    attribs.push(VertexBuffer.UVKind);
-                    defines.push("#define UV1");
-                }
-                if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
-                    var alphaTexture = material.getAlphaTestTexture();
-
-                    if (alphaTexture.coordinatesIndex === 1) {
-                        attribs.push(VertexBuffer.UV2Kind);
-                        defines.push("#define UV2");
+                var alphaTexture = material.getAlphaTestTexture();
+                if (alphaTexture) {
+                    defines.push("#define ALPHATEST");
+                    if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+                        attribs.push(VertexBuffer.UVKind);
+                        defines.push("#define UV1");
+                    }
+                    if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+                        if (alphaTexture.coordinatesIndex === 1) {
+                            attribs.push(VertexBuffer.UV2Kind);
+                            defines.push("#define UV2");
+                        }
                     }
                 }
             }

+ 24 - 0
src/PostProcess/babylon.blurPostProcess.ts

@@ -2,6 +2,7 @@
     export class BlurPostProcess extends PostProcess {
 		protected _kernel: number;
 		protected _idealKernel: number;
+		protected _packedFloat: boolean	= false;
 
 		/**
 		 * Sets the length in pixels of the blur sample region
@@ -24,6 +25,24 @@
 			return this._idealKernel;
 		}
 
+		/**
+		 * Sets wether or not the blur needs to unpack/repack floats
+		 */
+		public set packedFloat(v: boolean) {
+			if (this._packedFloat === v) {
+				return;
+			}
+			this._packedFloat = v;
+            this._updateParameters();
+		}
+
+		/**
+		 * Gets wether or not the blur is unpacking/repacking floats
+		 */
+		public get packedFloat(): boolean {
+			return this._packedFloat;
+		}
+
         constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "kernelBlur", ["delta", "direction"], null, options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
             this.onApplyObservable.add((effect: Effect) => {
@@ -113,6 +132,11 @@
                 defines += `#define KERNEL_DEP_WEIGHT${depCount} ${this._glslFloat(weights[i])}\r\n`;
                 depCount++;
 			}
+
+			if (this.packedFloat) {
+				defines += `#define PACKEDFLOAT 1`;
+			}
+
             this.updateEffect(defines, null, null, {
 				varyingCount: varyingCount,
 				depCount: depCount

+ 5 - 1
src/Shaders/ShadersInclude/kernelBlurFragment.fx

@@ -1 +1,5 @@
-blend += texture2D(textureSampler, sampleCoord{X}) * KERNEL_WEIGHT{X};
+#ifdef PACKEDFLOAT
+    blend += unpack(texture2D(textureSampler, sampleCoord{X})) * KERNEL_WEIGHT{X};
+#else
+    blend += texture2D(textureSampler, sampleCoord{X}) * KERNEL_WEIGHT{X};
+#endif

+ 5 - 1
src/Shaders/ShadersInclude/kernelBlurFragment2.fx

@@ -1 +1,5 @@
-blend += texture2D(textureSampler, sampleCenter + delta * KERNEL_DEP_OFFSET{X}) * KERNEL_DEP_WEIGHT{X};
+#ifdef PACKEDFLOAT
+    blend += unpack(texture2D(textureSampler, sampleCenter + delta * KERNEL_DEP_OFFSET{X})) * KERNEL_DEP_WEIGHT{X};
+#else
+    blend += texture2D(textureSampler, sampleCenter + delta * KERNEL_DEP_OFFSET{X}) * KERNEL_DEP_WEIGHT{X};
+#endif

+ 30 - 1
src/Shaders/kernelBlur.fragment.fx

@@ -6,10 +6,39 @@ uniform vec2 delta;
 varying vec2 sampleCenter;
 #include<kernelBlurVaryingDeclaration>[0..varyingCount]
 
+#ifdef PACKEDFLOAT
+	vec4 pack(float depth)
+	{
+		const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
+		const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
+
+		vec4 res = fract(depth * bit_shift);
+		res -= res.xxyz * bit_mask;
+
+		return res;
+	}
+
+	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);
+		return dot(color, bit_shift);
+	}
+#endif
+
 void main(void)
 {
+#ifdef PACKEDFLOAT	
+	float blend = 0.;
+#else
 	vec4 blend = vec4(0.);
+#endif
+
 	#include<kernelBlurFragment>[0..varyingCount]
 	#include<kernelBlurFragment2>[0..depCount]
-	gl_FragColor = blend;
+
+	#ifdef PACKEDFLOAT
+		gl_FragColor = pack(blend);
+	#else
+		gl_FragColor = blend;
+	#endif
 }