Jelajahi Sumber

when using uniform near/far use float2 for the params

Trevor Baron 7 tahun lalu
induk
melakukan
d75da978de

+ 1 - 1
src/PostProcess/babylon.blurPostProcess.ts

@@ -44,7 +44,7 @@
 		}
 
         constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
-            super(name, "kernelBlur", ["delta", "direction", "near", "far"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
+            super(name, "kernelBlur", ["delta", "direction", "cameraMinMaxZ"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType, "kernelBlur", {varyingCount: 0, depCount: 0}, true);
 			
 			this.onApplyObservable.add((effect: Effect) => {
 				effect.setFloat2('delta', (1 / this.width) * this.direction.x, (1 / this.height) * this.direction.y);

+ 2 - 3
src/PostProcess/babylon.circleOfConfusionPostProcess.ts

@@ -7,7 +7,7 @@ module BABYLON {
 
         
         constructor(name: string, depthTexture: RenderTargetTexture, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
-            super(name, "circleOfConfusion", ["near", "far", "focusDistance", "cocPrecalculation"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType);
+            super(name, "circleOfConfusion", ["cameraMinMaxZ", "focusDistance", "cocPrecalculation"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType);
             this.onApplyObservable.add((effect: Effect) => {
                 effect.setTexture("depthSampler", depthTexture);
                 
@@ -18,8 +18,7 @@ module BABYLON {
                 effect.setFloat('focusDistance', this.focusDistance);
                 effect.setFloat('cocPrecalculation', cocPrecalculation);
                 
-                effect.setFloat('near', camera.minZ);
-                effect.setFloat('far', camera.maxZ);
+                effect.setFloat2("cameraMinMaxZ", camera.minZ, camera.maxZ);
             })
         }
     }

+ 1 - 2
src/PostProcess/babylon.depthOfFieldBlurPostProcess.ts

@@ -12,8 +12,7 @@ module BABYLON {
                 }
                 effect.setTexture("depthSampler", depthMap)
                 
-                effect.setFloat('near', camera.minZ);
-                effect.setFloat('far', camera.maxZ);
+                effect.setFloat2('cameraMinMaxZ', camera.minZ, camera.maxZ);
 			});
         }
     }

+ 2 - 3
src/Shaders/circleOfConfusion.fragment.fx

@@ -5,8 +5,7 @@ uniform sampler2D depthSampler;
 varying vec2 vUV;
 
 // preconputed uniforms (not effect parameters)
-uniform float near;
-uniform float far;
+uniform vec2 cameraMinMaxZ;
 
 // uniforms
 uniform float focusDistance;
@@ -14,7 +13,7 @@ uniform float cocPrecalculation;
 
 float sampleDistance(const in vec2 offset) {
     float depth = texture2D(depthSampler, offset).r;	// depth value from DepthRenderer: 0 to 1
-	return (near + (far - near)*depth)*1000.0;		            // actual distance from the lens in scene units/1000 (eg. millimeter)
+	return (cameraMinMaxZ.x + (cameraMinMaxZ.y - cameraMinMaxZ.x)*depth)*1000.0;		            // actual distance from the lens in scene units/1000 (eg. millimeter)
 }
 
 void main(void)

+ 2 - 3
src/Shaders/kernelBlur.fragment.fx

@@ -8,12 +8,11 @@ varying vec2 sampleCenter;
 #ifdef DOF
 	uniform sampler2D depthSampler;
 
-	uniform float near;
-	uniform float far;
+	uniform vec2 cameraMinMaxZ;
 
 	float sampleDistance(const in vec2 offset) {
 		float depth = texture2D(depthSampler, offset).r; // depth value from DepthRenderer: 0 to 1 
-		return near + (far - near)*depth; // actual distance from the lens 
+		return cameraMinMaxZ.x + (cameraMinMaxZ.y - cameraMinMaxZ.x)*depth; // actual distance from the lens 
 	}
 #endif