Browse Source

Put fov feature behind define, clenaup, and tweaks.

David 7 năm trước cách đây
mục cha
commit
7218ebfaef

+ 4 - 2
src/Helpers/babylon.videoDome.ts

@@ -64,7 +64,7 @@ module BABYLON {
             // create
             let tempOptions:VideoTextureSettings = {loop: options.loop, autoPlay: options.autoPlay, autoUpdateTexture: true};
             let material = this._material = new BABYLON.BackgroundMaterial(name+"_material", scene);
-            this._videoTexture = new BABYLON.VideoTexture(name+"_texture", urlsOrVideo, scene, false, false, Texture.TRILINEAR_SAMPLINGMODE, tempOptions);
+            let texture = this._videoTexture = new BABYLON.VideoTexture(name+"_texture", urlsOrVideo, scene, false, false, Texture.TRILINEAR_SAMPLINGMODE, tempOptions);
             this._mesh = BABYLON.MeshBuilder.CreateIcoSphere(name+"_mesh", {
                 flat: false, // saves on vertex data
                 radius: options.size,
@@ -73,8 +73,10 @@ module BABYLON {
             }, scene);
 
             // configure material
-            this._videoTexture.coordinatesMode = BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE; // matches src
+            texture.coordinatesMode = BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE; // matches orientation
+            texture.wrapV = Texture.CLAMP_ADDRESSMODE; // always clamp the up/down
             material.reflectionTexture = this._videoTexture;
+            material.useEquirectangularFOV = true;
             material.fovMultiplier = 1.0;
 
             // configure mesh

+ 11 - 1
src/Materials/Background/babylon.backgroundMaterial.ts

@@ -95,6 +95,7 @@
         public REFLECTIONMAP_OPPOSITEZ = false;
         public LODINREFLECTIONALPHA = false;
         public GAMMAREFLECTION = false;
+        public EQUIRECTANGULAR_RELFECTION_FOV = false;
 
         // Default BJS.
         public MAINUV1 = false;
@@ -344,6 +345,14 @@
             }
             this._fovMultiplier = Math.max(0.0, Math.min(2.0, value));
         }
+        private _fovMultiplier: float = 1.0;
+
+        /**
+         * Enable the FOV adjustment feature controlled by fovMultiplier.
+         * @type {boolean}
+         */
+        public useEquirectangularFOV: boolean = false;
+
         @serialize()
         private _maxSimultaneousLights: int = 4;
         /**
@@ -625,6 +634,7 @@
                         defines.REFLECTIONBLUR = this._reflectionBlur > 0;
                         defines.REFLECTIONMAP_OPPOSITEZ = this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;
                         defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;
+                        defines.EQUIRECTANGULAR_RELFECTION_FOV = this.useEquirectangularFOV;
 
                         if (reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
                             defines.INVERTCUBICMAP = true;
@@ -1056,4 +1066,4 @@
             return SerializationHelper.Parse(() => new BackgroundMaterial(source.name, scene), source, scene, rootUrl);
         }
     }
-}
+}

+ 1 - 0
src/Shaders/ShadersInclude/backgroundVertexDeclaration.fx

@@ -11,6 +11,7 @@ uniform vec2 vDiffuseInfos;
     uniform vec2 vReflectionInfos;
     uniform mat4 reflectionMatrix;
     uniform vec3 vReflectionMicrosurfaceInfos;
+    uniform float fFovMultiplier;
 #endif
 
 #ifdef POINTSIZE

+ 4 - 3
src/Shaders/background.vertex.fx

@@ -81,15 +81,16 @@ void main(void) {
 #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
     vDirectionW = normalize(vec3(finalWorld * vec4(position, 0.0)));
 
-    if (fFovMultiplier != 1.0) {
+
+    #ifdef EQUIRECTANGULAR_RELFECTION_FOV
         mat3 screenToWorld = inverseMat3(mat3(finalWorld * viewProjection));
         vec3 segment = mix(vDirectionW, screenToWorld * vec3(0.0,0.0, 1.0), abs(fFovMultiplier - 1.0));
-        if (fFovMultiplier < 1.0) {
+        if (fFovMultiplier <= 1.0) {
             vDirectionW = normalize(segment);
         } else {
             vDirectionW = normalize(vDirectionW + (vDirectionW - segment));
         }
-    }
+    #endif
 #endif
 
 #ifndef UV1