ソースを参照

default and PBR ok with MRT output

Benjamin Guignabert 5 年 前
コミット
1af08f0d8b

+ 2 - 5
src/Materials/PBR/pbrBaseMaterial.ts

@@ -155,6 +155,7 @@ export class PBRMaterialDefines extends MaterialDefines
     public INSTANCES = false;
     
     public HIGH_DEFINITION_PIPELINE = false;
+    public SCENE_MRT_COUNT = 0;
 
     public NUM_BONE_INFLUENCERS = 0;
     public BonesPerMesh = 0;
@@ -1284,11 +1285,6 @@ export abstract class PBRBaseMaterial extends PushMaterial {
         const scene = this.getScene();
         const engine = scene.getEngine();
 
-        if (scene.highDefinitionPipeline) {
-            defines.HIGH_DEFINITION_PIPELINE = true;
-        } else {
-            defines.HIGH_DEFINITION_PIPELINE = false;
-        }
 
         // Lights
         MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
@@ -1296,6 +1292,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
 
         // Multiview
         MaterialHelper.PrepareDefinesForMultiview(scene, defines);
+        MaterialHelper.PrepareDefinesForDeferred(scene, defines);
 
         // Textures
         defines.METALLICWORKFLOW = this.isMetallicWorkflow();

+ 14 - 0
src/Materials/materialHelper.ts

@@ -289,6 +289,20 @@ export class MaterialHelper {
     }
 
     /**
+     * Prepares the defines related to defferred shading
+     * @param scene The scene we are intending to draw
+     * @param defines The defines to update
+     */
+    public static PrepareDefinesForDeferred(scene: Scene, defines: any) {
+        if (scene.highDefinitionPipeline) {
+            defines.HIGH_DEFINITION_PIPELINE = true;
+            defines.SCENE_MRT_COUNT = scene.mrtCount;
+        } else {
+            defines.HIGH_DEFINITION_PIPELINE = false;
+        }
+    }
+
+    /**
      * Prepares the defines related to the light information passed in parameter
      * @param scene The scene we are intending to draw
      * @param mesh The mesh the effect is compiling for

+ 4 - 0
src/Materials/standardMaterial.ts

@@ -120,6 +120,9 @@ export class StandardMaterialDefines extends MaterialDefines implements IImagePr
     public ALPHATEST_AFTERALLALPHACOMPUTATIONS = false;
     public ALPHABLEND = true;
 
+    public HIGH_DEFINITION_PIPELINE = false;
+    public SCENE_MRT_COUNT = 0;
+
     public RGBDLIGHTMAP = false;
     public RGBDREFLECTION = false;
     public RGBDREFRACTION = false;
@@ -811,6 +814,7 @@ export class StandardMaterial extends PushMaterial {
 
         // Multiview
         MaterialHelper.PrepareDefinesForMultiview(scene, defines);
+        MaterialHelper.PrepareDefinesForDeferred(scene, defines);
 
         // Textures
         if (defines._areTexturesDirty) {

+ 7 - 0
src/Shaders/ShadersInclude/mrtInput.fx

@@ -0,0 +1,7 @@
+#ifdef HIGH_DEFINITION_PIPELINE
+#if __VERSION__ >= 200
+#extension GL_EXT_draw_buffers : require
+layout(location = 0) out vec4 glFragData[{X}];
+vec4 gl_FragColor;
+#endif
+#endif

+ 7 - 0
src/Shaders/ShadersInclude/mrtOutput.fx

@@ -0,0 +1,7 @@
+#ifdef HIGH_DEFINITION_PIPELINE
+	gl_FragData[0] = gl_FragColor;
+	gl_FragData[1] = gl_FragColor;
+	gl_FragData[2] = gl_FragColor;
+	gl_FragData[3] = gl_FragColor;
+	gl_FragData[4] = vec4(gl_FragColor.rgb, 1.0);
+#endif

+ 7 - 1
src/Shaders/default.fragment.fx

@@ -44,6 +44,8 @@ varying vec4 vColor;
 #include<lightsFragmentFunctions>
 #include<shadowsFragmentFunctions>
 
+#include<mrtInput>[SCENE_MRT_COUNT]
+
 // Samplers
 #ifdef DIFFUSE
 	#if DIFFUSEDIRECTUV == 1
@@ -470,5 +472,9 @@ color.rgb = max(color.rgb, 0.);
 #endif
 
 #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
-	gl_FragColor = color;
+
+gl_FragColor = color;
+
+#include<mrtOutput>
+
 }

+ 0 - 2
src/Shaders/geometry.fragment.fx

@@ -1,5 +1,3 @@
-#extension GL_EXT_draw_buffers : require
-
 #if defined(BUMP) || !defined(NORMAL)
 #extension GL_OES_standard_derivatives : enable
 #endif

+ 1 - 4
src/Shaders/pbr.fragment.fx

@@ -14,10 +14,7 @@
 
 precision highp float;
 
-#ifdef HIGH_DEFINITION_PIPELINE
-#extension GL_EXT_draw_buffers : require
-#include<mrtFragmentDeclaration>[5]
-#endif
+#include<mrtInput>[SCENE_MRT_COUNT]
 
 // Forces linear space for image processing
 #ifndef FROMLINEARSPACE

+ 3 - 2
src/scene.ts

@@ -258,6 +258,7 @@ export class Scene extends AbstractScene implements IAnimatable {
         this._highDefinitionPipeline = b;
     }
 
+    public mrtCount: number = 5;
     public highDefinitionMRT: MultiRenderTarget;
     public sceneCompositorPostProcess: SceneCompositorPostProcess;
     public subSurfaceScatteringPostProcess: SubSurfaceScatteringPostProcess;
@@ -1453,9 +1454,9 @@ export class Scene extends AbstractScene implements IAnimatable {
             Constants.TEXTURETYPE_UNSIGNED_INT,
         ];
 
-        this.highDefinitionMRT = new MultiRenderTarget("sceneHighDefinitionMRT", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, 5, this,
+        this.highDefinitionMRT = new MultiRenderTarget("sceneHighDefinitionMRT", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this.mrtCount, this,
             { generateMipMaps: false, generateDepthTexture: true, defaultType: Constants.TEXTURETYPE_UNSIGNED_INT, types: types });
-        this.highDefinitionMRT.samples = 4;
+        this.highDefinitionMRT.samples = 1;
         this.sceneCompositorPostProcess = new SceneCompositorPostProcess("sceneCompositor", 1, null, undefined, this._engine);
         this.sceneCompositorPostProcess.inputTexture = this.highDefinitionMRT.getInternalTexture()!;
         this.subSurfaceScatteringPostProcess = new SubSurfaceScatteringPostProcess("subSurfaceScattering", this, 1, null, undefined, this._engine);