Explorar o código

Moved ShaderLib["fresnel"] to examples/js/shaders/FresnelShader.

Mr.doob %!s(int64=12) %!d(string=hai) anos
pai
achega
91d9902b7f

+ 74 - 0
examples/js/shaders/FresnelShader.js

@@ -0,0 +1,74 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ *
+ * Based on Nvidia Cg tutorial
+ */
+
+THREE.FresnelShader = {
+
+	uniforms: {
+
+		"mRefractionRatio": { type: "f", value: 1.02 },
+		"mFresnelBias": { type: "f", value: 0.1 },
+		"mFresnelPower": { type: "f", value: 2.0 },
+		"mFresnelScale": { type: "f", value: 1.0 },
+		"tCube": { type: "t", value: null }
+
+	},
+
+	vertexShader: [
+
+		"uniform float mRefractionRatio;",
+		"uniform float mFresnelBias;",
+		"uniform float mFresnelScale;",
+		"uniform float mFresnelPower;",
+
+		"varying vec3 vReflect;",
+		"varying vec3 vRefract[3];",
+		"varying float vReflectionFactor;",
+
+		"void main() {",
+
+			"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
+
+			"vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
+
+			"vec3 I = worldPosition.xyz - cameraPosition;",
+
+			"vReflect = reflect( I, worldNormal );",
+			"vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
+			"vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
+			"vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
+			"vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
+
+			"gl_Position = projectionMatrix * mvPosition;",
+
+		"}"
+
+	].join("\n"),
+
+	fragmentShader: [
+
+		"uniform samplerCube tCube;",
+
+		"varying vec3 vReflect;",
+		"varying vec3 vRefract[3];",
+		"varying float vReflectionFactor;",
+
+		"void main() {",
+
+			"vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
+			"vec4 refractedColor = vec4( 1.0 );",
+
+			"refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
+			"refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
+			"refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
+
+			"gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
+
+		"}"
+
+	].join("\n")
+
+};

+ 3 - 1
examples/webgl_materials_shaders_fresnel.html

@@ -36,6 +36,8 @@
 
 		<script src="../build/three.min.js"></script>
 
+		<script src="js/shaders/FresnelShader.js"></script>
+
 		<script src="js/Detector.js"></script>
 
 		<script>
@@ -90,7 +92,7 @@
 				var textureCube = THREE.ImageUtils.loadTextureCube( urls );
 				textureCube.format = THREE.RGBFormat;
 
-				var shader = THREE.ShaderLib[ "fresnel" ];
+				var shader = THREE.FresnelShader;
 				var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 
 				uniforms[ "tCube" ].value = textureCube;

+ 0 - 74
src/renderers/WebGLShaders.js

@@ -3158,80 +3158,6 @@ THREE.ShaderLib = {
 
 	},
 
-	/* -------------------------------------------------------------------------
-	//	Fresnel shader
-	//	- based on Nvidia Cg tutorial
-	 ------------------------------------------------------------------------- */
-
-	'fresnel': {
-
-		uniforms: {
-
-			"mRefractionRatio": { type: "f", value: 1.02 },
-			"mFresnelBias": { type: "f", value: 0.1 },
-			"mFresnelPower": { type: "f", value: 2.0 },
-			"mFresnelScale": { type: "f", value: 1.0 },
-			"tCube": { type: "t", value: null }
-
-		},
-
-		fragmentShader: [
-
-			"uniform samplerCube tCube;",
-
-			"varying vec3 vReflect;",
-			"varying vec3 vRefract[3];",
-			"varying float vReflectionFactor;",
-
-			"void main() {",
-
-				"vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
-				"vec4 refractedColor = vec4( 1.0 );",
-
-				"refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
-				"refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
-				"refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
-
-				"gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
-
-			"}"
-
-		].join("\n"),
-
-		vertexShader: [
-
-			"uniform float mRefractionRatio;",
-			"uniform float mFresnelBias;",
-			"uniform float mFresnelScale;",
-			"uniform float mFresnelPower;",
-
-			"varying vec3 vReflect;",
-			"varying vec3 vRefract[3];",
-			"varying float vReflectionFactor;",
-
-			"void main() {",
-
-				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-				"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
-
-				"vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
-
-				"vec3 I = worldPosition.xyz - cameraPosition;",
-
-				"vReflect = reflect( I, worldNormal );",
-				"vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
-				"vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
-				"vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
-				"vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
-
-				"gl_Position = projectionMatrix * mvPosition;",
-
-			"}"
-
-		].join("\n")
-
-	},
-
 	// Depth encoding into RGBA texture
 	// 	based on SpiderGL shadow map example
 	// 		http://spidergl.org/example.php?id=6