Selaa lähdekoodia

Code cleaning

David Catuhe 9 vuotta sitten
vanhempi
commit
35f5ab99a0

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 10 - 10
dist/preview release/babylon.core.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2938 - 2935
dist/preview release/babylon.d.ts


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 12 - 12
dist/preview release/babylon.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 29 - 3
dist/preview release/babylon.max.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 11 - 11
dist/preview release/babylon.noworker.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 856 - 857
src/Materials/babylon.standardMaterial.js


+ 3 - 7
src/Materials/babylon.standardMaterial.ts

@@ -1,4 +1,4 @@
-module BABYLON {   
+module BABYLON {
     class StandardMaterialDefines extends MaterialDefines {
     class StandardMaterialDefines extends MaterialDefines {
         public DIFFUSE = false;
         public DIFFUSE = false;
         public AMBIENT = false;
         public AMBIENT = false;
@@ -648,7 +648,7 @@
                         "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
                         "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
                         "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                         "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                         "vFogInfos", "vFogColor", "pointSize",
                         "vFogInfos", "vFogColor", "pointSize",
-                        "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vParallaxScaleBias", "vLightmapInfos", "vRefractionInfos",
+                        "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
                         "mBones",
                         "mBones",
                         "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                         "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                         "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
                         "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
@@ -794,10 +794,6 @@
 
 
                         this._effect.setFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
                         this._effect.setFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
                         this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                         this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
-
-                        if (this.useParallax) {
-                            this._effect.setFloat("vParallaxScaleBias", this.parallaxScaleBias);
-                        }
                     }
                     }
 
 
                     if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
                     if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
@@ -967,4 +963,4 @@
         public static LightmapTextureEnabled = true;
         public static LightmapTextureEnabled = true;
         public static RefractionTextureEnabled = true;
         public static RefractionTextureEnabled = true;
     }
     }
-} 
+} 

+ 31 - 0
src/Shaders/ShadersInclude/bumpFragment.fx

@@ -0,0 +1,31 @@
+#ifdef BUMP
+	vec2 bumpUV = vBumpUV;
+#endif
+
+#if defined(BUMP) || defined(PARALLAX)
+	mat3 TBN = cotangent_frame(normalW * vBumpInfos.y, -viewDirectionW, bumpUV);
+#endif
+
+#ifdef PARALLAX
+	mat3 invTBN = transposeMat3(TBN);
+
+	#ifdef PARALLAXOCCLUSION
+		vec2 uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, bumpUV, vBumpInfos.z);
+	#else
+		vec2 uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);
+	#endif
+
+	diffuseUV += uvOffset;
+	bumpUV += uvOffset;
+
+	// Note from Loic: won't be nice with wrapping textures...
+	#ifdef PARALLAXOCCLUSION
+		if (diffuseUV.x > 1.0 || diffuseUV.y > 1.0 || diffuseUV.x < 0.0 || diffuseUV.y < 0.0) {
+			discard;
+		}
+	#endif
+#endif
+
+#ifdef BUMP
+	normalW = perturbNormal(viewDirectionW, TBN, bumpUV);
+#endif

+ 54 - 60
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -30,69 +30,63 @@
 		return normalize(cotangentFrame * map);
 		return normalize(cotangentFrame * map);
 	}
 	}
 
 
-#ifdef PARALLAX
-	const float minSamples = 4.;
-	const float maxSamples = 15.;
-	const int iMaxSamples = 15;
-
-	// http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-closer-look-at-parallax-occlusion-mapping-r3262
-	vec2 parallaxOcclusion(vec3 vViewDirCoT, vec3 vNormalCoT, vec2 texCoord, float parallaxScale) {
-
-		float parallaxLimit = length(vViewDirCoT.xy) / vViewDirCoT.z;
-		parallaxLimit *= parallaxScale;
-		vec2 vOffsetDir = normalize(vViewDirCoT.xy);
-		vec2 vMaxOffset = vOffsetDir * parallaxLimit;
-		float numSamples = maxSamples + (dot(vViewDirCoT, vNormalCoT) * (minSamples - maxSamples));
-		float stepSize = 1.0 / numSamples;
-
-		// Uncomment whevener GL_EXT_shader_texture_lod with texture2DGradEXT will work
-		//vec2 dx = dFdx(vBumpUV);
-		//vec2 dy = dFdy(vBumpUV);
-
-		// Initialize the starting view ray height and the texture offsets.
-		float currRayHeight = 1.0;
-		vec2 vCurrOffset = vec2(0, 0);
-		vec2 vLastOffset = vec2(0, 0);
-
-		float lastSampledHeight = 1.0;
-		float currSampledHeight = 1.0;
-
-		for (int i = 0; i < iMaxSamples; i++)
-		{
-			currSampledHeight = texture2D(bumpSampler, vBumpUV + vCurrOffset).w;
-
-			// Test if the view ray has intersected the surface.
-			if (currSampledHeight > currRayHeight)
+	#ifdef PARALLAX
+		const float minSamples = 4.;
+		const float maxSamples = 15.;
+		const int iMaxSamples = 15;
+
+		// http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-closer-look-at-parallax-occlusion-mapping-r3262
+		vec2 parallaxOcclusion(vec3 vViewDirCoT, vec3 vNormalCoT, vec2 texCoord, float parallaxScale) {
+
+			float parallaxLimit = length(vViewDirCoT.xy) / vViewDirCoT.z;
+			parallaxLimit *= parallaxScale;
+			vec2 vOffsetDir = normalize(vViewDirCoT.xy);
+			vec2 vMaxOffset = vOffsetDir * parallaxLimit;
+			float numSamples = maxSamples + (dot(vViewDirCoT, vNormalCoT) * (minSamples - maxSamples));
+			float stepSize = 1.0 / numSamples;
+
+			// Initialize the starting view ray height and the texture offsets.
+			float currRayHeight = 1.0;
+			vec2 vCurrOffset = vec2(0, 0);
+			vec2 vLastOffset = vec2(0, 0);
+
+			float lastSampledHeight = 1.0;
+			float currSampledHeight = 1.0;
+
+			for (int i = 0; i < iMaxSamples; i++)
 			{
 			{
-				float delta1 = currSampledHeight - currRayHeight;
-				float delta2 = (currRayHeight + stepSize) - lastSampledHeight;
-				float ratio = delta1 / (delta1 + delta2);
-				vCurrOffset = (ratio)* vLastOffset + (1.0 - ratio) * vCurrOffset;
-
-				// Force the exit of the loop
-				break;
+				currSampledHeight = texture2D(bumpSampler, vBumpUV + vCurrOffset).w;
+
+				// Test if the view ray has intersected the surface.
+				if (currSampledHeight > currRayHeight)
+				{
+					float delta1 = currSampledHeight - currRayHeight;
+					float delta2 = (currRayHeight + stepSize) - lastSampledHeight;
+					float ratio = delta1 / (delta1 + delta2);
+					vCurrOffset = (ratio)* vLastOffset + (1.0 - ratio) * vCurrOffset;
+
+					// Force the exit of the loop
+					break;
+				}
+				else
+				{
+					currRayHeight -= stepSize;
+					vLastOffset = vCurrOffset;
+					vCurrOffset += stepSize * vMaxOffset;
+
+					lastSampledHeight = currSampledHeight;
+				}
 			}
 			}
-			else
-			{
-				currRayHeight -= stepSize;
-				vLastOffset = vCurrOffset;
-				vCurrOffset += stepSize * vMaxOffset;
 
 
-				lastSampledHeight = currSampledHeight;
-			}
+			return vCurrOffset;
 		}
 		}
 
 
-		return vCurrOffset;
-	}
-
-	vec2 parallaxOffset(vec3 viewDir, float heightScale)
-	{
-		// calculate amount of offset for Parallax Mapping With Offset Limiting
-		float height = texture2D(bumpSampler, vBumpUV).w;
-		vec2 texCoordOffset = heightScale * viewDir.xy * height;
-		return -texCoordOffset;
-	}
-
-#endif
-
+		vec2 parallaxOffset(vec3 viewDir, float heightScale)
+		{
+			// calculate amount of offset for Parallax Mapping With Offset Limiting
+			float height = texture2D(bumpSampler, vBumpUV).w;
+			vec2 texCoordOffset = heightScale * viewDir.xy * height;
+			return -texCoordOffset;
+		}
+	#endif
 #endif
 #endif

+ 2 - 3
src/Shaders/ShadersInclude/helperFunctions.fx

@@ -1,5 +1,4 @@
-
-mat3 transposeMat3(mat3 inMatrix) {
+mat3 transposeMat3(mat3 inMatrix) {
 	vec3 i0 = inMatrix[0];
 	vec3 i0 = inMatrix[0];
 	vec3 i1 = inMatrix[1];
 	vec3 i1 = inMatrix[1];
 	vec3 i2 = inMatrix[2];
 	vec3 i2 = inMatrix[2];
@@ -11,4 +10,4 @@ mat3 transposeMat3(mat3 inMatrix) {
 		);
 		);
 
 
 	return outMatrix;
 	return outMatrix;
-}
+}

+ 8 - 43
src/Shaders/default.fragment.fx

@@ -1,8 +1,4 @@
-#ifdef PARALLAX
-//#extension GL_EXT_shader_texture_lod : enable		// Doesn't work right now with texture2DGradExt...
-#endif
-
-#ifdef BUMP
+#ifdef BUMP
 #extension GL_OES_standard_derivatives : enable
 #extension GL_OES_standard_derivatives : enable
 #endif
 #endif
 
 
@@ -179,38 +175,7 @@ void main(void) {
 	vec2 diffuseUV = vDiffuseUV;
 	vec2 diffuseUV = vDiffuseUV;
 #endif
 #endif
 
 
-#ifdef BUMP
-	vec2 bumpUV = vBumpUV;
-#endif
-
-#if defined(BUMP) || defined(PARALLAX)
-	mat3 TBN = cotangent_frame(normalW * vBumpInfos.y, -viewDirectionW, bumpUV);
-#endif
-
-#ifdef PARALLAX
-	mat3 invTBN = transposeMat3(TBN);
-
-#ifdef PARALLAXOCCLUSION
-	vec2 uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, bumpUV, vBumpInfos.z);
-#else
-	vec2 uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);
-#endif
-
-	diffuseUV += uvOffset;
-	bumpUV += uvOffset;
-
-	// Note by Loic: won't be nice with wrapping textures...
-#ifdef PARALLAXOCCLUSION
-	if (diffuseUV.x > 1.0 || diffuseUV.y > 1.0 || diffuseUV.x < 0.0 || diffuseUV.y < 0.0) {
-		discard;
-	}
-#endif
-
-#endif
-
-#ifdef BUMP
-	normalW = perturbNormal(viewDirectionW, TBN, bumpUV);
-#endif
+#include<bumpFragment>
 
 
 #ifdef DIFFUSE
 #ifdef DIFFUSE
 	baseColor = texture2D(diffuseSampler, diffuseUV);
 	baseColor = texture2D(diffuseSampler, diffuseUV);
@@ -298,14 +263,14 @@ void main(void) {
 
 
 #ifdef REFLECTIONMAP_3D
 #ifdef REFLECTIONMAP_3D
 #ifdef ROUGHNESS
 #ifdef ROUGHNESS
-	 float bias = vReflectionInfos.y;
+	float bias = vReflectionInfos.y;
 
 
 	#ifdef SPECULARTERM
 	#ifdef SPECULARTERM
-	#ifdef SPECULAR
-	#ifdef GLOSSINESS
-		bias *= (1.0 - specularMapColor.a);
-	#endif
-	#endif
+		#ifdef SPECULAR
+			#ifdef GLOSSINESS
+				bias *= (1.0 - specularMapColor.a);
+			#endif
+		#endif
 	#endif
 	#endif
 
 
 	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x;
 	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x;