Sfoglia il codice sorgente

Motion blur post-process adding motionStrength property
Fixed iPhone issue with floating point textures

Julien Moreau-Mathis 8 anni fa
parent
commit
349749f72c

+ 14 - 7
src/PostProcess/babylon.standardRenderingPipeline.ts

@@ -76,6 +76,9 @@ module BABYLON {
         @serialize()
         public depthOfFieldBlurWidth: number = 2.0;
 
+        @serialize()
+        public motionStrength: number = 1.0;
+
         // IAnimatable
         public animations: Animation[] = [];
 
@@ -216,9 +219,12 @@ module BABYLON {
             // Initialize
             this._scene = scene;
 
-            // Create pass post-processe
+            // Misc
+            var floatTextureType = scene.getEngine()["_badOS"] ? Engine.TEXTURETYPE_HALF_FLOAT : Engine.TEXTURETYPE_FLOAT;
+
+            // Create pass post-process
             if (!originalPostProcess) {
-                this.originalPostProcess = new PostProcess("HDRPass", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define PASS_POST_PROCESS", Engine.TEXTURETYPE_FLOAT);
+                this.originalPostProcess = new PostProcess("HDRPass", "standard", [], [], ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define PASS_POST_PROCESS", floatTextureType);
             }
             else {
                 this.originalPostProcess = originalPostProcess;
@@ -253,7 +259,7 @@ module BABYLON {
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), "HDRPostLensFlareDepthOfFieldSource", () => { return this.lensFlareFinalPostProcess; }, true));
 
             // Create luminance
-            this._createLuminancePostProcesses(scene);
+            this._createLuminancePostProcesses(scene, floatTextureType);
 
             // Create HDR
             this._createHdrPostProcess(scene, ratio);
@@ -409,10 +415,10 @@ module BABYLON {
         }
 
         // Create luminance
-        private _createLuminancePostProcesses(scene: Scene): void {
+        private _createLuminancePostProcesses(scene: Scene, textureType: number): void {
             // Create luminance
             var size = Math.pow(3, StandardRenderingPipeline.LuminanceSteps);
-            this.luminancePostProcess = new PostProcess("HDRLuminance", "standard", ["lumOffsets"], [], { width: size, height: size }, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LUMINANCE", Engine.TEXTURETYPE_FLOAT);
+            this.luminancePostProcess = new PostProcess("HDRLuminance", "standard", ["lumOffsets"], [], { width: size, height: size }, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define LUMINANCE", textureType);
 
             var offsets: number[] = [];
             this.luminancePostProcess.onApply = (effect: Effect) => {
@@ -443,7 +449,7 @@ module BABYLON {
                     defines += "#define FINAL_DOWN_SAMPLER";
                 }
 
-                var postProcess = new PostProcess("HDRLuminanceDownSample" + i, "standard", ["dsOffsets", "halfDestPixelSize"], [], { width: size, height: size }, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, defines, Engine.TEXTURETYPE_FLOAT);
+                var postProcess = new PostProcess("HDRLuminanceDownSample" + i, "standard", ["dsOffsets", "halfDestPixelSize"], [], { width: size, height: size }, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, defines, textureType);
                 this.luminanceDownSamplePostProcesses.push(postProcess);
             }
 
@@ -613,7 +619,7 @@ module BABYLON {
         // Create motion blur post-process
         private _createMotionBlurPostProcess(scene: Scene, ratio: number): void {
             this.motionBlurPostProcess = new PostProcess("HDRMotionBlur", "standard",
-                ["inverseViewProjection", "prevViewProjection", "screenSize", "motionScale"],
+                ["inverseViewProjection", "prevViewProjection", "screenSize", "motionScale", "motionStrength"],
                 ["depthSampler"],
                 ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, "#define MOTION_BLUR\n#define MAX_MOTION_SAMPLES " + this.motionBlurSamples.toFixed(1), Engine.TEXTURETYPE_UNSIGNED_INT);
 
@@ -638,6 +644,7 @@ module BABYLON {
 
                 motionScale = scene.getEngine().getFps() / 60.0;
                 effect.setFloat("motionScale", motionScale);
+                effect.setFloat("motionStrength", this.motionStrength);
 
                 effect.setTexture("depthSampler", this._depthRenderer.getDepthMap());
             };

+ 2 - 1
src/Shaders/standard.fragment.fx

@@ -365,6 +365,7 @@ uniform mat4 prevViewProjection;
 uniform vec2 screenSize;
 
 uniform float motionScale;
+uniform float motionStrength;
 
 uniform sampler2D depthSampler;
 
@@ -380,7 +381,7 @@ void main(void)
 	ppos.xyz /= ppos.w;
 	ppos.xy = ppos.xy * 0.5 + 0.5;
 
-	vec2 velocity = (ppos.xy - vUV) * motionScale;
+	vec2 velocity = (ppos.xy - vUV) * motionScale * motionStrength;
 	float speed = length(velocity / texelSize);
 	int nSamples = int(clamp(speed, 1.0, MAX_MOTION_SAMPLES));