Jelajahi Sumber

Making lines (color shader) work in multiview

Raanan Weber 5 tahun lalu
induk
melakukan
8790254e36
3 mengubah file dengan 30 tambahan dan 1 penghapusan
  1. 1 1
      src/Materials/effect.ts
  2. 18 0
      src/Materials/shaderMaterial.ts
  3. 11 0
      src/Shaders/color.vertex.fx

+ 1 - 1
src/Materials/effect.ts

@@ -30,7 +30,7 @@ export interface IEffectCreationOptions {
      */
     uniformsNames: string[];
     /**
-     * Uniform buffer varible names that will be set in the shader.
+     * Uniform buffer variable names that will be set in the shader.
      */
     uniformBuffersNames: string[];
     /**

+ 18 - 0
src/Materials/shaderMaterial.ts

@@ -85,6 +85,7 @@ export class ShaderMaterial extends Material {
     private _cachedWorldViewMatrix = new Matrix();
     private _cachedWorldViewProjectionMatrix = new Matrix();
     private _renderId: number;
+    private _multiview: boolean = false;
 
     /**
      * Instantiate a new shader material.
@@ -446,6 +447,19 @@ export class ShaderMaterial extends Material {
         var attribs = [];
         var fallbacks = new EffectFallbacks();
 
+        // global multiview
+        if (engine.getCaps().multiview &&
+            scene.activeCamera &&
+            scene.activeCamera.outputRenderTarget &&
+            scene.activeCamera.outputRenderTarget.getViewCount() > 1) {
+            this._multiview = true;
+            defines.push("#define MULTIVIEW");
+            if (this._options.uniforms.indexOf("viewProjection") !== -1 &&
+                this._options.uniforms.push("viewProjectionR") === -1) {
+                this._options.uniforms.push("viewProjectionR");
+            }
+        }
+
         for (var index = 0; index < this._options.defines.length; index++) {
             defines.push(this._options.defines[index]);
         }
@@ -588,6 +602,10 @@ export class ShaderMaterial extends Material {
                 this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
             }
 
+            if (this._multiview) {
+                this._effect.setMatrix("viewProjectionR", this.getScene()._transformMatrixR);
+            }
+
             // Bones
             MaterialHelper.BindBonesParameters(mesh, this._effect);
 

+ 11 - 0
src/Shaders/color.vertex.fx

@@ -13,6 +13,9 @@ attribute vec4 color;
 
 #include<instancesDeclaration>
 uniform mat4 viewProjection;
+#ifdef MULTIVIEW
+	uniform mat4 viewProjectionR;
+#endif 
 
 // Output
 #ifdef VERTEXCOLOR
@@ -24,7 +27,15 @@ void main(void) {
 #include<bonesVertex>
     vec4 worldPos = finalWorld * vec4(position, 1.0);
 
+#ifdef MULTIVIEW
+	if (gl_ViewID_OVR == 0u) {
+		gl_Position = viewProjection * worldPos;
+	} else {
+		gl_Position = viewProjectionR * worldPos;
+	}
+#else
 	gl_Position = viewProjection * worldPos;
+#endif
 
 #include<clipPlaneVertex>