Bläddra i källkod

LogDepth + clipplane + bump (includes)

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

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


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


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


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


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


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 6 - 4
materialsLibrary/dist/babylon.pbrMaterial.js


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


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


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
materialsLibrary/dist/babylon.simpleMaterial.min.js


+ 1 - 0
materialsLibrary/dist/dts/babylon.pbrMaterial.d.ts

@@ -74,6 +74,7 @@ declare module BABYLON {
         private static _scaledReflectivity;
         private static _scaledEmissive;
         private static _scaledReflection;
+        private static _lightRadiuses;
         static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines): void;
         isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
         unbind(): void;

+ 6 - 49
materialsLibrary/materials/pbr/pbr.fragment.fx

@@ -659,49 +659,9 @@ float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, flo
 
 #endif
 
-// Bump
-#ifdef BUMP
-varying vec2 vBumpUV;
-uniform vec2 vBumpInfos;
-uniform sampler2D bumpSampler;
-
-// Thanks to http://www.thetenthplanet.de/archives/1180
-mat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)
-{
-    // get edge vectors of the pixel triangle
-    vec3 dp1 = dFdx(p);
-    vec3 dp2 = dFdy(p);
-    vec2 duv1 = dFdx(uv);
-    vec2 duv2 = dFdy(uv);
-
-    // solve the linear system
-    vec3 dp2perp = cross(dp2, normal);
-    vec3 dp1perp = cross(normal, dp1);
-    vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;
-    vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;
-
-    // construct a scale-invariant frame 
-    float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));
-    return mat3(tangent * invmax, binormal * invmax, normal);
-}
-
-vec3 perturbNormal(vec3 viewDir)
-{
-    vec3 map = texture2D(bumpSampler, vBumpUV).xyz;
-    map = map * 255. / 127. - 128. / 127.;
-    mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -viewDir, vBumpUV);
-    return normalize(TBN * map);
-}
-#endif
-
-#ifdef CLIPPLANE
-varying float fClipDistance;
-#endif
-
-#ifdef LOGARITHMICDEPTH
-uniform float logarithmicDepthConstant;
-varying float vFragmentDepth;
-#endif
+#include<bumpFragmentFunctions>
+#include<clipPlaneFragmentDeclaration>
+#include<logDepthDeclaration>
 
 // Fog
 #include<fogFragmentDeclaration>
@@ -842,16 +802,12 @@ lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4
 }
 
 void main(void) {
+#include<clipPlaneFragment>
+
     #ifdef PoissonSamplingEnvironment
         initSamplers();
     #endif
 
-    // Clip plane
-    #ifdef CLIPPLANE
-        if (fClipDistance > 0.0)
-            discard;
-    #endif
-
     vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
 
     // Albedo
@@ -1447,6 +1403,7 @@ vec3 surfaceEmissiveColor = vEmissiveColor;
     //vec2 test = vEmissiveUV * 0.5 + 0.5;
     //gl_FragColor = vec4(test.x, test.y, 1.0, 1.0);
 
+#include<logDepthFragment>
 #include<fogFragment>(color, finalColor)
 
     gl_FragColor = finalColor;

+ 4 - 15
materialsLibrary/materials/pbr/pbr.vertex.fx

@@ -79,11 +79,8 @@ varying vec3 vNormalW;
 varying vec4 vColor;
 #endif
 
-#ifdef CLIPPLANE
-uniform vec4 vClipPlane;
-varying float fClipDistance;
-#endif
 
+#include<clipPlaneVertexDeclaration>
 #include<fogVertexDeclaration>
 #include<shadowsVertexDeclaration>
 
@@ -95,10 +92,7 @@ varying vec3 vPositionUVW;
 varying vec3 vDirectionW;
 #endif
 
-#ifdef LOGARITHMICDEPTH
-uniform float logarithmicDepthConstant;
-varying float vFragmentDepth;
-#endif
+#include<logDepthDeclaration>
 
 void main(void) {
 #ifdef REFLECTIONMAP_SKYBOX
@@ -207,9 +201,7 @@ void main(void) {
 #endif
 
     // Clip plane
-#ifdef CLIPPLANE
-    fClipDistance = dot(worldPos, vClipPlane);
-#endif
+#include<clipPlaneVertex>
 
     // Fog
 #include<fogVertex>
@@ -228,8 +220,5 @@ void main(void) {
 #endif
 
     // Log. depth
-#ifdef LOGARITHMICDEPTH
-    vFragmentDepth = 1.0 + gl_Position.w;
-    gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;
-#endif
+#include<logDepthVertex>
 }

+ 2 - 8
materialsLibrary/materials/simple/simple.fragment.fx

@@ -33,19 +33,13 @@ uniform vec2 vDiffuseInfos;
 
 #endif
 
-#ifdef CLIPPLANE
-varying float fClipDistance;
-#endif
+#include<clipPlaneFragmentDeclaration>
 
 // Fog
 #include<fogFragmentDeclaration>
 
 void main(void) {
-	// Clip plane
-#ifdef CLIPPLANE
-	if (fClipDistance > 0.0)
-		discard;
-#endif
+#include<clipPlaneFragment>
 
 	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
 

+ 3 - 7
materialsLibrary/materials/simple/simple.vertex.fx

@@ -43,10 +43,8 @@ varying vec3 vNormalW;
 varying vec4 vColor;
 #endif
 
-#ifdef CLIPPLANE
-uniform vec4 vClipPlane;
-varying float fClipDistance;
-#endif
+
+#include<clipPlaneVertexDeclaration>
 
 #include<fogVertexDeclaration>
 #include<shadowsVertexDeclaration>
@@ -85,9 +83,7 @@ void main(void) {
 #endif
 
 	// Clip plane
-#ifdef CLIPPLANE
-	fClipDistance = dot(worldPos, vClipPlane);
-#endif
+#include<clipPlaneVertex>
 
     // Fog
 #include<fogVertex>

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 8 - 2
materialsLibrary/test/refs/babylon.max.js


+ 6 - 0
src/Lights/babylon.light.js

@@ -17,6 +17,8 @@ var BABYLON;
             this.includedOnlyMeshes = new Array();
             this.excludedMeshes = new Array();
             this.excludeWithLayerMask = 0;
+            // PBR Properties.
+            this.radius = 0.00001;
             this._excludedMeshesIds = new Array();
             this._includedOnlyMeshesIds = new Array();
             scene.addLight(this);
@@ -86,6 +88,7 @@ var BABYLON;
                 serializationObject.parentId = this.parent.id;
             }
             serializationObject.range = this.range;
+            serializationObject.radius = this.radius;
             serializationObject.diffuse = this.diffuse.asArray();
             serializationObject.specular = this.specular.asArray();
             return serializationObject;
@@ -116,6 +119,9 @@ var BABYLON;
             if (parsedLight.range) {
                 light.range = parsedLight.range;
             }
+            if (parsedLight.radius) {
+                light.radius = parsedLight.radius;
+            }
             light.diffuse = BABYLON.Color3.FromArray(parsedLight.diffuse);
             light.specular = BABYLON.Color3.FromArray(parsedLight.specular);
             if (parsedLight.excludedMeshesIds) {

+ 2 - 2
src/Lights/babylon.light.ts

@@ -171,7 +171,7 @@
             if (parsedLight.range) {
                 light.range = parsedLight.range;
             }
-            
+
             if (parsedLight.radius) {
                 light.radius = parsedLight.radius;
             }
@@ -209,4 +209,4 @@
             return light;
         }
     }
-}
+}

+ 33 - 0
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -0,0 +1,33 @@
+#ifdef BUMP
+	varying vec2 vBumpUV;
+	uniform vec2 vBumpInfos;
+	uniform sampler2D bumpSampler;
+
+	// Thanks to http://www.thetenthplanet.de/archives/1180
+	mat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)
+	{
+		// get edge vectors of the pixel triangle
+		vec3 dp1 = dFdx(p);
+		vec3 dp2 = dFdy(p);
+		vec2 duv1 = dFdx(uv);
+		vec2 duv2 = dFdy(uv);
+
+		// solve the linear system
+		vec3 dp2perp = cross(dp2, normal);
+		vec3 dp1perp = cross(normal, dp1);
+		vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;
+		vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;
+
+		// construct a scale-invariant frame 
+		float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));
+		return mat3(tangent * invmax, binormal * invmax, normal);
+	}
+
+	vec3 perturbNormal(vec3 viewDir)
+	{
+		vec3 map = texture2D(bumpSampler, vBumpUV).xyz;
+		map = map * 255. / 127. - 128. / 127.;
+		mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -viewDir, vBumpUV);
+		return normalize(TBN * map);
+	}
+#endif

+ 6 - 0
src/Shaders/ShadersInclude/clipPlaneFragment.fx

@@ -0,0 +1,6 @@
+#ifdef CLIPPLANE
+	if (fClipDistance > 0.0)
+	{
+		discard;
+	}
+#endif

+ 3 - 0
src/Shaders/ShadersInclude/clipPlaneFragmentDeclaration.fx

@@ -0,0 +1,3 @@
+#ifdef CLIPPLANE
+	varying float fClipDistance;
+#endif

+ 3 - 0
src/Shaders/ShadersInclude/clipPlaneVertex.fx

@@ -0,0 +1,3 @@
+#ifdef CLIPPLANE
+	fClipDistance = dot(worldPos, vClipPlane);
+#endif

+ 4 - 0
src/Shaders/ShadersInclude/clipPlaneVertexDeclaration.fx

@@ -0,0 +1,4 @@
+#ifdef CLIPPLANE
+	uniform vec4 vClipPlane;
+	varying float fClipDistance;
+#endif

+ 4 - 0
src/Shaders/ShadersInclude/logDepthDeclaration.fx

@@ -0,0 +1,4 @@
+#ifdef LOGARITHMICDEPTH
+	uniform float logarithmicDepthConstant;
+	varying float vFragmentDepth;
+#endif

+ 3 - 0
src/Shaders/ShadersInclude/logDepthFragment.fx

@@ -0,0 +1,3 @@
+#ifdef LOGARITHMICDEPTH
+	gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;
+#endif

+ 4 - 0
src/Shaders/ShadersInclude/logDepthVertex.fx

@@ -0,0 +1,4 @@
+#ifdef LOGARITHMICDEPTH
+	vFragmentDepth = 1.0 + gl_Position.w;
+	gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;
+#endif

+ 5 - 53
src/Shaders/default.fragment.fx

@@ -210,58 +210,13 @@ uniform vec4 reflectionRightColor;
 
 #endif
 
-// Bump
-#ifdef BUMP
-varying vec2 vBumpUV;
-uniform vec2 vBumpInfos;
-uniform sampler2D bumpSampler;
-
-// Thanks to http://www.thetenthplanet.de/archives/1180
-mat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)
-{
-	// get edge vectors of the pixel triangle
-	vec3 dp1 = dFdx(p);
-	vec3 dp2 = dFdy(p);
-	vec2 duv1 = dFdx(uv);
-	vec2 duv2 = dFdy(uv);
-
-	// solve the linear system
-	vec3 dp2perp = cross(dp2, normal);
-	vec3 dp1perp = cross(normal, dp1);
-	vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;
-	vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;
-
-	// construct a scale-invariant frame 
-	float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));
-	return mat3(tangent * invmax, binormal * invmax, normal);
-}
-
-vec3 perturbNormal(vec3 viewDir)
-{
-	vec3 map = texture2D(bumpSampler, vBumpUV).xyz;
-	map = map * 255. / 127. - 128. / 127.;
-	mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -viewDir, vBumpUV);
-	return normalize(TBN * map);
-}
-#endif
-
-#ifdef CLIPPLANE
-varying float fClipDistance;
-#endif
-
-#ifdef LOGARITHMICDEPTH
-uniform float logarithmicDepthConstant;
-varying float vFragmentDepth;
-#endif
-
+#include<bumpFragmentFunctions>
+#include<clipPlaneFragmentDeclaration>
+#include<logDepthDeclaration>
 #include<fogFragmentDeclaration>
 
 void main(void) {
-	// Clip plane
-#ifdef CLIPPLANE
-	if (fClipDistance > 0.0)
-		discard;
-#endif
+#include<clipPlaneFragment>
 
 	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
 
@@ -497,10 +452,7 @@ void main(void) {
 #endif
 #endif
 
-#ifdef LOGARITHMICDEPTH
-	gl_FragDepthEXT = log2(vFragmentDepth) * logarithmicDepthConstant * 0.5;
-#endif
-
+#include<logDepthFragment>
 #include<fogFragment>
 
 	gl_FragColor = color;

+ 5 - 18
src/Shaders/default.vertex.fx

@@ -79,10 +79,7 @@ varying vec3 vNormalW;
 varying vec4 vColor;
 #endif
 
-#ifdef CLIPPLANE
-uniform vec4 vClipPlane;
-varying float fClipDistance;
-#endif
+#include<clipPlaneVertexDeclaration>
 
 #include<fogVertexDeclaration>
 #include<shadowsVertexDeclaration>
@@ -95,10 +92,7 @@ varying vec3 vPositionUVW;
 varying vec3 vDirectionW;
 #endif
 
-#ifdef LOGARITHMICDEPTH
-uniform float logarithmicDepthConstant;
-varying float vFragmentDepth;
-#endif
+#include<logDepthDeclaration>
 
 void main(void) {
 #ifdef REFLECTIONMAP_SKYBOX
@@ -206,11 +200,7 @@ void main(void) {
 	}
 #endif
 
-	// Clip plane
-#ifdef CLIPPLANE
-	fClipDistance = dot(worldPos, vClipPlane);
-#endif
-
+#include<clipPlaneVertex>
 #include<fogVertex>
 #include<shadowsVertex>
 
@@ -224,9 +214,6 @@ void main(void) {
 	gl_PointSize = pointSize;
 #endif
 
-	// Log. depth
-#ifdef LOGARITHMICDEPTH
-	vFragmentDepth = 1.0 + gl_Position.w;
-	gl_Position.z = log2(max(0.000001, vFragmentDepth)) * logarithmicDepthConstant;
-#endif
+#include<logDepthVertex>
+
 }