Bläddra i källkod

Fixing Y direction issue with cubemap and Refraction

David Catuhe 9 år sedan
förälder
incheckning
b58d3e4a72

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 2 - 2
dist/preview release/babylon.core.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1316 - 1309
dist/preview release/babylon.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 2 - 2
dist/preview release/babylon.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 10 - 3
dist/preview release/babylon.max.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 2 - 2
dist/preview release/babylon.noworker.js


+ 6 - 0
src/Materials/Textures/babylon.mirrorTexture.js

@@ -51,6 +51,12 @@ var BABYLON;
         return MirrorTexture;
         return MirrorTexture;
     })(BABYLON.RenderTargetTexture);
     })(BABYLON.RenderTargetTexture);
     BABYLON.MirrorTexture = MirrorTexture;
     BABYLON.MirrorTexture = MirrorTexture;
+    /**
+    * Creates a refraction texture used by refraction channel of the standard material.
+    * @param name the texture name
+    * @param size size of the underlying texture
+    * @param scene root scene
+    */
     var RefractionTexture = (function (_super) {
     var RefractionTexture = (function (_super) {
         __extends(RefractionTexture, _super);
         __extends(RefractionTexture, _super);
         function RefractionTexture(name, size, scene, generateMipMaps) {
         function RefractionTexture(name, size, scene, generateMipMaps) {

+ 2 - 1
src/Materials/babylon.standardMaterial.js

@@ -148,6 +148,7 @@ var BABYLON;
             this.disableLighting = false;
             this.disableLighting = false;
             this.roughness = 0;
             this.roughness = 0;
             this.indexOfRefraction = 1.05;
             this.indexOfRefraction = 1.05;
+            this.invertRefractionY = true;
             this.useLightmapAsShadowmap = false;
             this.useLightmapAsShadowmap = false;
             this.useGlossinessFromSpecularMapAlpha = false;
             this.useGlossinessFromSpecularMapAlpha = false;
             this._renderTargets = new BABYLON.SmartArray(16);
             this._renderTargets = new BABYLON.SmartArray(16);
@@ -791,7 +792,7 @@ var BABYLON;
                                 depth = this.refractionTexture.depth;
                                 depth = this.refractionTexture.depth;
                             }
                             }
                         }
                         }
-                        this._effect.setFloat3("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth);
+                        this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                     }
                     }
                 }
                 }
                 // Clip plane
                 // Clip plane

+ 2 - 1
src/Materials/babylon.standardMaterial.ts

@@ -157,6 +157,7 @@
         public roughness = 0;
         public roughness = 0;
 
 
         public indexOfRefraction = 1.05;
         public indexOfRefraction = 1.05;
+        public invertRefractionY = true;
 
 
         public useLightmapAsShadowmap = false;
         public useLightmapAsShadowmap = false;
 
 
@@ -947,7 +948,7 @@
                                 depth = (<any>this.refractionTexture).depth;
                                 depth = (<any>this.refractionTexture).depth;
                             }
                             }
                         }
                         }
-                        this._effect.setFloat3("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth);
+                        this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                     }
                     }
                 }
                 }
 
 

+ 2 - 2
src/Shaders/default.fragment.fx

@@ -159,7 +159,7 @@ uniform mat4 view;
 #endif
 #endif
 
 
 #ifdef REFRACTION
 #ifdef REFRACTION
-uniform vec3 vRefractionInfos;
+uniform vec4 vRefractionInfos;
 
 
 #ifdef REFRACTIONMAP_3D
 #ifdef REFRACTIONMAP_3D
 uniform samplerCube refractionCubeSampler;
 uniform samplerCube refractionCubeSampler;
@@ -871,7 +871,7 @@ void main(void) {
 	vec3 refractionVector = normalize(refract(-viewDirectionW, normalW, vRefractionInfos.y));
 	vec3 refractionVector = normalize(refract(-viewDirectionW, normalW, vRefractionInfos.y));
 #ifdef REFRACTIONMAP_3D
 #ifdef REFRACTIONMAP_3D
 
 
-	refractionVector.y = -refractionVector.y;
+	refractionVector.y = refractionVector.y * vRefractionInfos.w;
 
 
 	if (dot(refractionVector, viewDirectionW) < 1.0)
 	if (dot(refractionVector, viewDirectionW) < 1.0)
 	{
 	{

+ 1 - 1
src/babylon.engine.js

@@ -1727,7 +1727,7 @@ var BABYLON;
             var framebuffer = gl.createFramebuffer();
             var framebuffer = gl.createFramebuffer();
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
-            // mipmaps
+            // Mipmaps
             if (texture.generateMipMaps) {
             if (texture.generateMipMaps) {
                 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
                 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
                 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
                 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);

+ 1 - 1
src/babylon.engine.ts

@@ -2043,7 +2043,7 @@
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
 
 
-            // mipmaps
+            // Mipmaps
             if (texture.generateMipMaps) {
             if (texture.generateMipMaps) {
                 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
                 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
                 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
                 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);