Browse Source

some nits and code simplification

Benjamin Guignabert 4 years ago
parent
commit
8b8ee52be4

+ 1 - 1
dist/preview release/what's new.md

@@ -243,7 +243,7 @@
 
 ### Post Processes
 
-- SSAO 2 is now using the brand new `PrePassRenderer` to avoid rendering the scene twice ([CraigFeldpsar](https://github.com/craigfeldspar)
+- SSAO 2, motion blur and screen space reflections are now using the brand new `PrePassRenderer` to avoid rendering the scene twice ([CraigFeldpsar](https://github.com/craigfeldspar)
 - Added Screen Space Curvature post process: [Doc](https://doc.babylonjs.com/how_to/how_to_use_postprocesses#screen-space-curvature) ([Popov72](https://github.com/Popov72) and [Sebavan](https://github.com/sebavan/))
 
 ## Bugs

+ 1 - 1
package.json

@@ -113,4 +113,4 @@
         "xhr2": "^0.2.0",
         "xmlbuilder": "15.1.1"
     }
-}
+}

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

@@ -1762,9 +1762,11 @@ export abstract class PBRBaseMaterial extends PushMaterial {
         // Matrices
         if (!defines.INSTANCES || defines.THIN_INSTANCES) {
             this.bindOnlyWorldMatrix(world);
-            this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
         }
 
+        // PrePass
+        this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
+
         // Normal Matrix
         if (defines.OBJECTSPACE_NORMALMAP) {
             world.toNormalMatrix(this._normalMatrix);

+ 1 - 3
src/Materials/materialHelper.ts

@@ -871,9 +871,7 @@ export class MaterialHelper {
 
     // Copies the bones transformation matrices into the target array and returns the target's reference
     private static _CopyBonesTransformationMatrices(source: Float32Array, target: Float32Array): Float32Array {
-        for (let i = 0; i < source.length; i++) {
-            target[i] = source[i];
-        }
+        target.set(source)
 
         return target;
     }

+ 1 - 1
src/Materials/prePassConfiguration.ts

@@ -42,7 +42,7 @@ export class PrePassConfiguration {
 
     /**
      * Binds the material data.
-     * @param effect defines theeffect to update
+     * @param effect defines the effect to update
      * @param scene defines the scene the material belongs to.
      * @param mesh The mesh
      * @param world World matrix of this mesh

+ 3 - 1
src/Materials/standardMaterial.ts

@@ -1377,9 +1377,11 @@ export class StandardMaterial extends PushMaterial {
         // Matrices
         if (!defines.INSTANCES || defines.THIN_INSTANCES) {
             this.bindOnlyWorldMatrix(world);
-            this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
         }
 
+        // PrePass
+        this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
+
         // Normal Matrix
         if (defines.OBJECTSPACE_NORMALMAP) {
             world.toNormalMatrix(this._normalMatrix);

+ 1 - 1
src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts

@@ -447,7 +447,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
         this._ssaoCombinePostProcess.samples = this.textureSamples;
 
         if (!this._forceGeometryBuffer) {
-            this._ssaoCombinePostProcess.prePassEffectConfiguration = new SSAO2Configuration();
+            this._ssaoCombinePostProcess._prePassEffectConfiguration = new SSAO2Configuration();
         }
     }
 

+ 2 - 1
src/PostProcesses/motionBlurPostProcess.ts

@@ -82,6 +82,7 @@ export class MotionBlurPostProcess extends PostProcess {
      * @param reusable If the post process can be reused on the same frame. (default: false)
      * @param textureType Type of textures used when performing the post process. (default: 0)
      * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
+     * @param forceGeometryBuffer If this post process should use geometry buffer instead of prepass (default: false)
      */
     constructor(name: string, scene: Scene, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false, forceGeometryBuffer = false) {
         super(name, "motionBlur", ["motionStrength", "motionScale", "screenSize"], ["velocitySampler"], options, camera, samplingMode, engine, reusable, "#define GEOMETRY_SUPPORTED\n#define SAMPLES 64.0", textureType, undefined, null, blockCompilation);
@@ -98,7 +99,7 @@ export class MotionBlurPostProcess extends PostProcess {
         } else {
             this._prePassRenderer = <PrePassRenderer>scene.enablePrePassRenderer();
             this._prePassRenderer.markAsDirty();
-            this.prePassEffectConfiguration = new MotionBlurConfiguration();
+            this._prePassEffectConfiguration = new MotionBlurConfiguration();
         }
 
         if (!this._geometryBufferRenderer && !this._prePassRenderer) {

+ 4 - 4
src/PostProcesses/postProcess.ts

@@ -192,7 +192,7 @@ export class PostProcess {
     * Prepass configuration in case this post process needs a texture from prepass
     * @hidden
     */
-    public prePassEffectConfiguration: PrePassEffectConfiguration;
+    public _prePassEffectConfiguration: PrePassEffectConfiguration;
 
     /**
      * Returns the fragment url or shader name used in the post process.
@@ -692,9 +692,9 @@ export class PostProcess {
      * @returns true if the pre pass is needed.
      */
     public setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean {
-        if (this.prePassEffectConfiguration) {
-            this.prePassEffectConfiguration = prePassRenderer.addEffectConfiguration(this.prePassEffectConfiguration);
-            this.prePassEffectConfiguration.enabled = true;
+        if (this._prePassEffectConfiguration) {
+            this._prePassEffectConfiguration = prePassRenderer.addEffectConfiguration(this._prePassEffectConfiguration);
+            this._prePassEffectConfiguration.enabled = true;
             return true;
         }
 

+ 2 - 1
src/PostProcesses/screenSpaceReflectionPostProcess.ts

@@ -71,6 +71,7 @@ export class ScreenSpaceReflectionPostProcess extends PostProcess {
      * @param reusable If the post process can be reused on the same frame. (default: false)
      * @param textureType Type of textures used when performing the post process. (default: 0)
      * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
+     * @param forceGeometryBuffer If this post process should use geometry buffer instead of prepass (default: false)
      */
     constructor(name: string, scene: Scene, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false, forceGeometryBuffer = false) {
         super(name, "screenSpaceReflection", [
@@ -96,7 +97,7 @@ export class ScreenSpaceReflectionPostProcess extends PostProcess {
         } else {
             this._prePassRenderer = <PrePassRenderer>scene.enablePrePassRenderer();
             this._prePassRenderer.markAsDirty();
-            this.prePassEffectConfiguration = new ScreenSpaceReflectionsConfiguration();
+            this._prePassEffectConfiguration = new ScreenSpaceReflectionsConfiguration();
         }
 
         this._updateEffectDefines();

+ 1 - 39
src/Shaders/default.vertex.fx

@@ -165,45 +165,7 @@ void main(void) {
 
 	vPositionW = vec3(worldPos);
 	
-#ifdef PREPASS
-	#ifdef PREPASS_DEPTHNORMAL
-	    vViewPos = (view * worldPos).rgb;
-	#endif
-
-	#if defined(PREPASS_VELOCITY) && defined(BONES_VELOCITY_ENABLED)
-	    vCurrentPosition = viewProjection * worldPos;
-
-	#if NUM_BONE_INFLUENCERS > 0
-	    mat4 previousInfluence;
-	    previousInfluence = mPreviousBones[int(matricesIndices[0])] * matricesWeights[0];
-	    #if NUM_BONE_INFLUENCERS > 1
-	        previousInfluence += mPreviousBones[int(matricesIndices[1])] * matricesWeights[1];
-	    #endif  
-	    #if NUM_BONE_INFLUENCERS > 2
-	        previousInfluence += mPreviousBones[int(matricesIndices[2])] * matricesWeights[2];
-	    #endif  
-	    #if NUM_BONE_INFLUENCERS > 3
-	        previousInfluence += mPreviousBones[int(matricesIndices[3])] * matricesWeights[3];
-	    #endif
-	    #if NUM_BONE_INFLUENCERS > 4
-	        previousInfluence += mPreviousBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
-	    #endif  
-	    #if NUM_BONE_INFLUENCERS > 5
-	        previousInfluence += mPreviousBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
-	    #endif  
-	    #if NUM_BONE_INFLUENCERS > 6
-	        previousInfluence += mPreviousBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
-	    #endif  
-	    #if NUM_BONE_INFLUENCERS > 7
-	        previousInfluence += mPreviousBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
-	    #endif
-
-	    vPreviousPosition = previousViewProjection * previousWorld * previousInfluence * vec4(positionUpdated, 1.0);
-	#else
-	    vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
-	#endif
-	#endif
-#endif
+#include<prePassVertex>
 
 #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
 	vDirectionW = normalize(vec3(finalWorld * vec4(positionUpdated, 0.0)));

+ 1 - 38
src/Shaders/pbr.vertex.fx

@@ -182,44 +182,7 @@ void main(void) {
     vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
     vPositionW = vec3(worldPos);
 
-    #ifdef PREPASS_DEPTHNORMAL
-        vViewPos = (view * worldPos).rgb;
-    #endif
-
-    #if defined(PREPASS_VELOCITY) && defined(BONES_VELOCITY_ENABLED)
-        vCurrentPosition = viewProjection * worldPos;
-
-    #if NUM_BONE_INFLUENCERS > 0
-        mat4 previousInfluence;
-        previousInfluence = mPreviousBones[int(matricesIndices[0])] * matricesWeights[0];
-        #if NUM_BONE_INFLUENCERS > 1
-            previousInfluence += mPreviousBones[int(matricesIndices[1])] * matricesWeights[1];
-        #endif  
-        #if NUM_BONE_INFLUENCERS > 2
-            previousInfluence += mPreviousBones[int(matricesIndices[2])] * matricesWeights[2];
-        #endif  
-        #if NUM_BONE_INFLUENCERS > 3
-            previousInfluence += mPreviousBones[int(matricesIndices[3])] * matricesWeights[3];
-        #endif
-        #if NUM_BONE_INFLUENCERS > 4
-            previousInfluence += mPreviousBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
-        #endif  
-        #if NUM_BONE_INFLUENCERS > 5
-            previousInfluence += mPreviousBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
-        #endif  
-        #if NUM_BONE_INFLUENCERS > 6
-            previousInfluence += mPreviousBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
-        #endif  
-        #if NUM_BONE_INFLUENCERS > 7
-            previousInfluence += mPreviousBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
-        #endif
-
-        vPreviousPosition = previousViewProjection * previousWorld * previousInfluence * vec4(positionUpdated, 1.0);
-    #else
-        vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
-    #endif
-    #endif
-
+#include<prePassVertex>
 
 #ifdef NORMAL
     mat3 normalWorld = mat3(finalWorld);