Kaynağa Gözat

support pbr and background materials

Trevor Baron 6 yıl önce
ebeveyn
işleme
dfc03a8f5a

+ 11 - 0
src/Materials/Background/backgroundMaterial.ts

@@ -119,6 +119,7 @@ class BackgroundMaterialDefines extends MaterialDefines implements IImageProcess
     public SAMPLER3DBGRMAP = false;
     public IMAGEPROCESSINGPOSTPROCESS = false;
     public EXPOSURE = false;
+    public MULTIVIEW = false;
 
     // Reflection.
     public REFLECTION = false;
@@ -675,6 +676,12 @@ export class BackgroundMaterial extends PushMaterial {
         MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
         defines._needNormals = true;
 
+        // Multiview
+        if (scene.activeCamera) {
+            defines.MULTIVIEW = (scene.activeCamera.outputRenderTarget !== null && scene.activeCamera.outputRenderTarget.getViewCount() > 1);
+            defines.markAsUnprocessed();
+        }
+
         // Textures
         if (defines._areTexturesDirty) {
             defines._needUVs = false;
@@ -838,6 +845,10 @@ export class BackgroundMaterial extends PushMaterial {
                 fallbacks.addFallback(1, "POINTSIZE");
             }
 
+            if (defines.MULTIVIEW) {
+                fallbacks.addFallback(0, "MULTIVIEW");
+            }
+
             MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
 
             if (defines.NUM_BONE_INFLUENCERS > 0) {

+ 11 - 0
src/Materials/PBR/pbrBaseMaterial.ts

@@ -163,6 +163,7 @@ class PBRMaterialDefines extends MaterialDefines
     public SAMPLER3DBGRMAP = false;
     public IMAGEPROCESSINGPOSTPROCESS = false;
     public EXPOSURE = false;
+    public MULTIVIEW = false;
 
     public USEPHYSICALLIGHTFALLOFF = false;
     public USEGLTFLIGHTFALLOFF = false;
@@ -1076,6 +1077,10 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             fallbacks.addFallback(fallbackRank++, "MORPHTARGETS");
         }
 
+        if (defines.MULTIVIEW) {
+            fallbacks.addFallback(0, "MULTIVIEW");
+        }
+
         //Attributes
         var attribs = [VertexBuffer.PositionKind];
 
@@ -1166,6 +1171,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
         MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
         defines._needNormals = true;
 
+        // Multiview
+        if (scene.activeCamera) {
+            defines.MULTIVIEW = (scene.activeCamera.outputRenderTarget !== null && scene.activeCamera.outputRenderTarget.getViewCount() > 1);
+            defines.markAsUnprocessed();
+        }
+
         // Textures
         defines.METALLICWORKFLOW = this.isMetallicWorkflow();
         if (defines._areTexturesDirty) {

+ 3 - 1
src/Shaders/ShadersInclude/backgroundUboDeclaration.fx

@@ -26,6 +26,8 @@ uniform Material
 
 uniform Scene {
 	mat4 viewProjection;
-	mat4 viewProjectionR;    
+#ifdef MULTIVIEW
+	mat4 viewProjectionR;
+#endif 
 	mat4 view;
 };

+ 2 - 0
src/Shaders/ShadersInclude/defaultUboDeclaration.fx

@@ -40,6 +40,8 @@ uniform Material
 
 uniform Scene {
     mat4 viewProjection;
+#ifdef MULTIVIEW
 	mat4 viewProjectionR;
+#endif 
 	mat4 view;
 };

+ 3 - 1
src/Shaders/ShadersInclude/pbrUboDeclaration.fx

@@ -55,6 +55,8 @@ uniform Material
 
 uniform Scene {
     mat4 viewProjection;
-    mat4 viewProjectionR;
+#ifdef MULTIVIEW
+	mat4 viewProjectionR;
+#endif 
     mat4 view;
 };

+ 9 - 1
src/Shaders/background.vertex.fx

@@ -63,7 +63,15 @@ void main(void) {
 #include<instancesVertex>
 #include<bonesVertex>
 
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+#ifdef MULTIVIEW
+	if (gl_ViewID_OVR == 0u) {
+		gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+	} else {
+		gl_Position = viewProjectionR * finalWorld * vec4(positionUpdated, 1.0);
+	}
+#else
+	gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+#endif
 
 	vec4 worldPos = finalWorld * vec4(position, 1.0);
 	vPositionW = vec3(worldPos);

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

@@ -133,7 +133,15 @@ void main(void) {
 #include<instancesVertex>
 #include<bonesVertex>
 
-    gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+#ifdef MULTIVIEW
+	if (gl_ViewID_OVR == 0u) {
+		gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+	} else {
+		gl_Position = viewProjectionR * finalWorld * vec4(positionUpdated, 1.0);
+	}
+#else
+	gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+#endif
 
     vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
     vPositionW = vec3(worldPos);