浏览代码

Fixing spherical mapping model

David Catuhe 9 年之前
父节点
当前提交
e195bfd5a9

文件差异内容过多而无法显示
+ 8 - 8
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 551 - 551
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 14 - 14
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 1 - 8
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 14 - 14
dist/preview release/babylon.noworker.js


+ 1 - 0
dist/preview release/what's new.md

@@ -30,6 +30,7 @@
     - OimoJS Plugin now uses Quaternions exclusively and calculates body rotations correctly. [PR](https://github.com/BabylonJS/Babylon.js/pull/761) ([RaananW](https://github.com/RaananW))
     - It is now possible to get the physics engine's body and wolrd objects using the physics engine. [PR](https://github.com/BabylonJS/Babylon.js/pull/761) ([RaananW](https://github.com/RaananW))
   - **Bug fixes**
+    - Fixed a bug with spherical mapping ([deltakosh](https://github.com/deltakosh)) 
     - Fixed a bug with clone and createInstance which was forcing the recomputation of bounding boxes ([deltakosh](https://github.com/deltakosh)) 
     - Fixed a bug with CSG when submeshes are kept ([deltakosh](https://github.com/deltakosh)) 
     - Fixed a bug with texture coordinates matrices ([deltakosh](https://github.com/deltakosh))

+ 0 - 7
src/Materials/Textures/babylon.texture.js

@@ -137,13 +137,6 @@ var BABYLON;
             }
             this._cachedCoordinatesMode = this.coordinatesMode;
             switch (this.coordinatesMode) {
-                case Texture.SPHERICAL_MODE:
-                    BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
-                    this._cachedTextureMatrix[0] = -0.5 * this.uScale;
-                    this._cachedTextureMatrix[5] = -0.5 * this.vScale;
-                    this._cachedTextureMatrix[12] = 0.5 + this.uOffset;
-                    this._cachedTextureMatrix[13] = 0.5 + this.vOffset;
-                    break;
                 case Texture.PLANAR_MODE:
                     BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
                     this._cachedTextureMatrix[0] = this.uScale;

+ 0 - 7
src/Materials/Textures/babylon.texture.ts

@@ -185,13 +185,6 @@
             this._cachedCoordinatesMode = this.coordinatesMode;
 
             switch (this.coordinatesMode) {
-                case Texture.SPHERICAL_MODE:
-                    Matrix.IdentityToRef(this._cachedTextureMatrix);
-                    this._cachedTextureMatrix[0] = -0.5 * this.uScale;
-                    this._cachedTextureMatrix[5] = -0.5 * this.vScale;
-                    this._cachedTextureMatrix[12] = 0.5 + this.uOffset;
-                    this._cachedTextureMatrix[13] = 0.5 + this.vOffset;
-                    break;
                 case Texture.PLANAR_MODE:
                     Matrix.IdentityToRef(this._cachedTextureMatrix);
                     this._cachedTextureMatrix[0] = this.uScale;

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

@@ -170,7 +170,9 @@ uniform sampler2D reflection2DSampler;
 #ifdef REFLECTIONMAP_SKYBOX
 	varying vec3 vPositionUVW;
 #else
+#ifndef REFLECTIONMAP_SPHERICAL
 	uniform mat4 reflectionMatrix;
+#endif
 #if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION)
 	uniform mat4 view;
 #endif
@@ -179,9 +181,15 @@ uniform sampler2D reflection2DSampler;
 vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
 {
 #ifdef REFLECTIONMAP_SPHERICAL
-	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
+	vec3 viewDir = normalize(vec3(view * worldPos));
+	vec3 viewNormal = normalize(vec3(view * vec4(worldNormal, 0.0)));
+
+	vec3 r = reflect(viewDir, viewNormal);
+	r.z = r.z - 1.0;
+
+	float m = 2.0 * length(r);
 
-	return vec3(reflectionMatrix * vec4(coords, 1.0));
+	return vec3(r.x / m + 0.5, 1.0 - r.y / m - 0.5, 0);
 #endif
 
 #ifdef REFLECTIONMAP_PLANAR