|
@@ -17,9 +17,11 @@ THREE.ShaderDeferred = {
|
|
|
THREE.UniformsLib[ "shadowmap" ],
|
|
|
|
|
|
{
|
|
|
- "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
|
|
|
- "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
|
|
|
- "shininess": { type: "f", value: 30 }
|
|
|
+ "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
|
|
|
+ "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
|
|
|
+ "shininess": { type: "f", value: 30 },
|
|
|
+ "wrapAround": { type: "f", value: 1 },
|
|
|
+ "additiveSpecular": { type: "f", value: 1 }
|
|
|
}
|
|
|
|
|
|
] ),
|
|
@@ -30,6 +32,8 @@ THREE.ShaderDeferred = {
|
|
|
"uniform vec3 specular;",
|
|
|
"uniform vec3 emissive;",
|
|
|
"uniform float shininess;",
|
|
|
+ "uniform float wrapAround;",
|
|
|
+ "uniform float additiveSpecular;",
|
|
|
|
|
|
THREE.ShaderChunk[ "color_pars_fragment" ],
|
|
|
THREE.ShaderChunk[ "map_pars_fragment" ],
|
|
@@ -66,21 +70,33 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
THREE.ShaderChunk[ "fog_fragment" ],
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
+ "const float compressionScale = 0.999;",
|
|
|
+
|
|
|
// diffuse color
|
|
|
|
|
|
- "gl_FragColor.x = vec3_to_float( 0.999 * gl_FragColor.xyz );",
|
|
|
+ "gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
|
|
|
|
|
|
// specular color
|
|
|
|
|
|
- "gl_FragColor.y = vec3_to_float( 0.999 * specular );",
|
|
|
+ "gl_FragColor.y = additiveSpecular * vec3_to_float( compressionScale * specular );",
|
|
|
|
|
|
// shininess
|
|
|
|
|
|
- "gl_FragColor.z = shininess;",
|
|
|
+ "gl_FragColor.z = wrapAround * shininess;",
|
|
|
|
|
|
// emissive color
|
|
|
|
|
|
- "gl_FragColor.w = vec3_to_float( 0.999 * emissive );",
|
|
|
+ "#ifdef USE_MAP",
|
|
|
+
|
|
|
+ "gl_FragColor.w = vec3_to_float( compressionScale * emissive * texelColor.xyz );",
|
|
|
+
|
|
|
+ "#else",
|
|
|
+
|
|
|
+ "gl_FragColor.w = vec3_to_float( compressionScale * emissive );",
|
|
|
+
|
|
|
+ "#endif",
|
|
|
|
|
|
"}"
|
|
|
|
|
@@ -125,60 +141,62 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- "clipDepth" : {
|
|
|
+ "normalDepth" : {
|
|
|
|
|
|
- uniforms: { },
|
|
|
+ uniforms: {
|
|
|
|
|
|
- fragmentShader : [
|
|
|
+ bumpMap: { type: "t", value: null },
|
|
|
+ bumpScale: { type: "f", value: 1 },
|
|
|
+ offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
|
|
|
|
|
|
- "varying vec4 clipPos;",
|
|
|
+ },
|
|
|
|
|
|
- "void main() {",
|
|
|
+ fragmentShader : [
|
|
|
|
|
|
- "gl_FragColor = vec4( clipPos.z / clipPos.w, 1.0, 1.0, 1.0 );",
|
|
|
+ "#ifdef USE_BUMPMAP",
|
|
|
|
|
|
- "}"
|
|
|
+ "#extension GL_OES_standard_derivatives : enable\n",
|
|
|
|
|
|
- ].join("\n"),
|
|
|
+ "varying vec2 vUv;",
|
|
|
+ "varying vec3 vViewPosition;",
|
|
|
|
|
|
- vertexShader : [
|
|
|
+ THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
|
|
|
|
|
|
- "varying vec4 clipPos;",
|
|
|
+ "#endif",
|
|
|
|
|
|
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
|
|
|
+ "varying vec3 normalView;",
|
|
|
+ "varying vec4 clipPos;",
|
|
|
|
|
|
"void main() {",
|
|
|
|
|
|
- THREE.ShaderChunk[ "morphtarget_vertex" ],
|
|
|
- THREE.ShaderChunk[ "default_vertex" ],
|
|
|
+ "vec3 normal = normalize( normalView );",
|
|
|
|
|
|
- "clipPos = gl_Position;",
|
|
|
+ "#ifdef USE_BUMPMAP",
|
|
|
|
|
|
- "}"
|
|
|
+ "normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
|
|
|
|
|
|
- ].join("\n")
|
|
|
+ "#endif",
|
|
|
|
|
|
- },
|
|
|
+ "gl_FragColor.xyz = normal * 0.5 + 0.5;",
|
|
|
+ "gl_FragColor.w = clipPos.z / clipPos.w;",
|
|
|
|
|
|
- "normals" : {
|
|
|
+ "}"
|
|
|
|
|
|
- uniforms: { },
|
|
|
+ ].join("\n"),
|
|
|
|
|
|
- fragmentShader : [
|
|
|
+ vertexShader : [
|
|
|
|
|
|
"varying vec3 normalView;",
|
|
|
+ "varying vec4 clipPos;",
|
|
|
|
|
|
- "void main() {",
|
|
|
-
|
|
|
- "gl_FragColor = vec4( vec3( normalView * 0.5 + 0.5 ), 1.0 );",
|
|
|
+ "#ifdef USE_BUMPMAP",
|
|
|
|
|
|
- "}"
|
|
|
+ "varying vec2 vUv;",
|
|
|
+ "varying vec3 vViewPosition;",
|
|
|
|
|
|
- ].join("\n"),
|
|
|
+ "uniform vec4 offsetRepeat;",
|
|
|
|
|
|
- vertexShader : [
|
|
|
-
|
|
|
- "varying vec3 normalView;",
|
|
|
+ "#endif",
|
|
|
|
|
|
THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
|
|
|
|
|
@@ -204,105 +222,13 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"normalView = normalize( normalMatrix * objectNormal );",
|
|
|
|
|
|
- "}"
|
|
|
-
|
|
|
- ].join("\n")
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- "bump" : {
|
|
|
-
|
|
|
- uniforms: {
|
|
|
-
|
|
|
- bumpMap: { type: "t", value: null },
|
|
|
- bumpScale: { type: "f", value: 1 },
|
|
|
- offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- fragmentShader : [
|
|
|
-
|
|
|
- "#extension GL_OES_standard_derivatives : enable\n",
|
|
|
-
|
|
|
- "varying vec3 normalView;",
|
|
|
- "varying vec2 vUv;",
|
|
|
- "varying vec3 vViewPosition;",
|
|
|
-
|
|
|
- THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
|
|
|
+ "#ifdef USE_BUMPMAP",
|
|
|
|
|
|
- "void main() {",
|
|
|
-
|
|
|
- "vec3 normal = normalize( normalView );",
|
|
|
- "normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
|
|
|
- "gl_FragColor = vec4( vec3( normal * 0.5 + 0.5 ), 1.0 );",
|
|
|
-
|
|
|
- "}"
|
|
|
-
|
|
|
- ].join("\n"),
|
|
|
-
|
|
|
- vertexShader : [
|
|
|
+ "vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
|
|
|
+ "vViewPosition = -mvPosition.xyz;",
|
|
|
|
|
|
- "varying vec3 normalView;",
|
|
|
- "varying vec2 vUv;",
|
|
|
- "varying vec3 vViewPosition;",
|
|
|
-
|
|
|
- "uniform vec4 offsetRepeat;",
|
|
|
-
|
|
|
- "void main() {",
|
|
|
-
|
|
|
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
|
|
|
- "gl_Position = projectionMatrix * mvPosition;",
|
|
|
- "normalView = normalize( normalMatrix * normal );",
|
|
|
- "vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
|
|
|
- "vViewPosition = -mvPosition.xyz;",
|
|
|
-
|
|
|
- "}"
|
|
|
-
|
|
|
- ].join("\n")
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- "unlit" : {
|
|
|
-
|
|
|
- uniforms: {
|
|
|
-
|
|
|
- samplerDepth: { type: "t", value: null },
|
|
|
- viewWidth: { type: "f", value: 800 },
|
|
|
- viewHeight: { type: "f", value: 600 },
|
|
|
- lightColor: { type: "c", value: new THREE.Color( 0x000000 ) }
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- fragmentShader : [
|
|
|
-
|
|
|
- "varying vec4 clipPos;",
|
|
|
- "uniform sampler2D samplerDepth;",
|
|
|
-
|
|
|
- "uniform float viewHeight;",
|
|
|
- "uniform float viewWidth;",
|
|
|
-
|
|
|
- "uniform vec3 lightColor;",
|
|
|
-
|
|
|
- "void main() {",
|
|
|
-
|
|
|
- "vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
|
|
|
- "float z = texture2D( samplerDepth, texCoord ).x;",
|
|
|
- "vec4 color = vec4( lightColor, 1.0 );",
|
|
|
- "float depth = clipPos.z / clipPos.w;",
|
|
|
- "if( depth > z && z > 0.0 ) color.w = 0.0;",
|
|
|
- "gl_FragColor = color;",
|
|
|
-
|
|
|
- "}"
|
|
|
-
|
|
|
- ].join("\n"),
|
|
|
-
|
|
|
- vertexShader : [
|
|
|
-
|
|
|
- "varying vec4 clipPos;",
|
|
|
-
|
|
|
- "void main() {",
|
|
|
+ "#endif",
|
|
|
|
|
|
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
|
|
|
"clipPos = gl_Position;",
|
|
|
|
|
|
"}"
|
|
@@ -316,7 +242,7 @@ THREE.ShaderDeferred = {
|
|
|
uniforms: {
|
|
|
|
|
|
samplerLight: { type: "t", value: null },
|
|
|
- multiply: { type: "f", value: 1 }
|
|
|
+ brightness: { type: "f", value: 1 }
|
|
|
|
|
|
},
|
|
|
|
|
@@ -324,12 +250,12 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"varying vec2 texCoord;",
|
|
|
"uniform sampler2D samplerLight;",
|
|
|
- "uniform float multiply;",
|
|
|
+ "uniform float brightness;",
|
|
|
|
|
|
"void main() {",
|
|
|
|
|
|
"vec3 color = texture2D( samplerLight, texCoord ).xyz;",
|
|
|
- "gl_FragColor = vec4( multiply * sqrt( color ), 1.0 );",
|
|
|
+ "gl_FragColor = vec4( brightness * sqrt( color ), 1.0 );",
|
|
|
|
|
|
"}"
|
|
|
|
|
@@ -355,9 +281,8 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
uniforms: {
|
|
|
|
|
|
- samplerNormals: { type: "t", value: null },
|
|
|
- samplerDepth: { type: "t", value: null },
|
|
|
- samplerColor: { type: "t", value: null },
|
|
|
+ samplerNormalDepth: { type: "t", value: null },
|
|
|
+ samplerColor: { type: "t", value: null },
|
|
|
matView: { type: "m4", value: new THREE.Matrix4() },
|
|
|
matProjInverse: { type: "m4", value: new THREE.Matrix4() },
|
|
|
viewWidth: { type: "f", value: 800 },
|
|
@@ -375,8 +300,7 @@ THREE.ShaderDeferred = {
|
|
|
"varying vec4 clipPos;",
|
|
|
|
|
|
"uniform sampler2D samplerColor;",
|
|
|
- "uniform sampler2D samplerDepth;",
|
|
|
- "uniform sampler2D samplerNormals;",
|
|
|
+ "uniform sampler2D samplerNormalDepth;",
|
|
|
|
|
|
"uniform float lightRadius;",
|
|
|
"uniform float lightIntensity;",
|
|
@@ -402,17 +326,10 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
|
|
|
|
|
|
- "float z = texture2D( samplerDepth, texCoord ).x;",
|
|
|
- "float lightZ = clipPos.z / clipPos.w;",
|
|
|
-
|
|
|
- /*
|
|
|
- "if ( z == 0.0 ) {",
|
|
|
-
|
|
|
- "gl_FragColor = vec4( vec3( 0.0 ), 1.0 );",
|
|
|
- "return;",
|
|
|
+ "vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
|
|
|
|
|
|
- "}",
|
|
|
- */
|
|
|
+ "float z = normalDepth.w;",
|
|
|
+ "float lightZ = clipPos.z / clipPos.w;",
|
|
|
|
|
|
"if ( z == 0.0 || lightZ > z ) discard;",
|
|
|
|
|
@@ -441,7 +358,7 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
// normal
|
|
|
|
|
|
- "vec3 normal = texture2D( samplerNormals, texCoord ).xyz * 2.0 - 1.0;",
|
|
|
+ "vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
|
|
|
|
|
|
// color
|
|
|
|
|
@@ -449,20 +366,31 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"vec3 albedo = float_to_vec3( abs( colorMap.x ) );",
|
|
|
"vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
|
|
|
- "float shininess = colorMap.z;",
|
|
|
+ "float shininess = abs( colorMap.z );",
|
|
|
+ "float wrapAround = sign( colorMap.z );",
|
|
|
|
|
|
- // wrap around lighting
|
|
|
+ // light
|
|
|
+
|
|
|
+ "vec3 diffuse;",
|
|
|
|
|
|
"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
|
|
|
- "float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
|
|
|
|
|
|
- "const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
|
|
|
- "vec3 diffuse = mix( vec3 ( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
|
|
|
+ "if ( wrapAround < 0.0 ) {",
|
|
|
|
|
|
- // simple lighting
|
|
|
+ // wrap around lighting
|
|
|
|
|
|
- //"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
|
|
|
- //"vec3 diffuse = vec3 ( diffuseFull );",
|
|
|
+ "float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
|
|
|
+
|
|
|
+ "const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
|
|
|
+ "diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
|
|
|
+
|
|
|
+ "} else {",
|
|
|
+
|
|
|
+ // simple lighting
|
|
|
+
|
|
|
+ "diffuse = vec3( diffuseFull );",
|
|
|
+
|
|
|
+ "}",
|
|
|
|
|
|
// specular
|
|
|
|
|
@@ -484,15 +412,17 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"vec3 light = lightIntensity * lightColor;",
|
|
|
|
|
|
- "#ifdef ADDITIVE_SPECULAR",
|
|
|
+ "float additiveSpecular = sign( colorMap.y );",
|
|
|
+
|
|
|
+ "if ( additiveSpecular < 0.0 ) {",
|
|
|
|
|
|
"gl_FragColor = vec4( albedo * light * diffuse, attenuation ) + vec4( light * specular, attenuation );",
|
|
|
|
|
|
- "#else",
|
|
|
+ "} else {",
|
|
|
|
|
|
"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), attenuation );",
|
|
|
|
|
|
- "#endif",
|
|
|
+ "}",
|
|
|
|
|
|
"}"
|
|
|
|
|
@@ -522,9 +452,8 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
uniforms: {
|
|
|
|
|
|
- samplerNormals: { type: "t", value: null },
|
|
|
- samplerDepth: { type: "t", value: null },
|
|
|
- samplerColor: { type: "t", value: null },
|
|
|
+ samplerNormalDepth: { type: "t", value: null },
|
|
|
+ samplerColor: { type: "t", value: null },
|
|
|
matView: { type: "m4", value: new THREE.Matrix4() },
|
|
|
matProjInverse: { type: "m4", value: new THREE.Matrix4() },
|
|
|
viewWidth: { type: "f", value: 800 },
|
|
@@ -541,8 +470,7 @@ THREE.ShaderDeferred = {
|
|
|
"varying vec4 clipPos;",
|
|
|
|
|
|
"uniform sampler2D samplerColor;",
|
|
|
- "uniform sampler2D samplerDepth;",
|
|
|
- "uniform sampler2D samplerNormals;",
|
|
|
+ "uniform sampler2D samplerNormalDepth;",
|
|
|
|
|
|
"uniform float lightRadius;",
|
|
|
"uniform float lightIntensity;",
|
|
@@ -568,7 +496,8 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
|
|
|
|
|
|
- "float z = texture2D( samplerDepth, texCoord ).x;",
|
|
|
+ "vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
|
|
|
+ "float z = normalDepth.w;",
|
|
|
|
|
|
"if ( z == 0.0 ) discard;",
|
|
|
|
|
@@ -585,7 +514,7 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
// normal
|
|
|
|
|
|
- "vec3 normal = texture2D( samplerNormals, texCoord ).xyz * 2.0 - 1.0;",
|
|
|
+ "vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
|
|
|
|
|
|
// color
|
|
|
|
|
@@ -665,7 +594,6 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
uniforms: {
|
|
|
|
|
|
- samplerDepth: { type: "t", value: null },
|
|
|
samplerColor: { type: "t", value: null },
|
|
|
viewWidth: { type: "f", value: 800 },
|
|
|
viewHeight: { type: "f", value: 600 },
|
|
@@ -674,7 +602,6 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
fragmentShader : [
|
|
|
|
|
|
- "uniform sampler2D samplerDepth;",
|
|
|
"uniform sampler2D samplerColor;",
|
|
|
|
|
|
"uniform float viewHeight;",
|
|
@@ -695,10 +622,6 @@ THREE.ShaderDeferred = {
|
|
|
|
|
|
"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
|
|
|
|
|
|
- "float z = texture2D( samplerDepth, texCoord ).x;",
|
|
|
-
|
|
|
- "if ( z == 0.0 ) discard;",
|
|
|
-
|
|
|
"vec4 colorMap = texture2D( samplerColor, texCoord );",
|
|
|
"vec3 emissiveColor = float_to_vec3( abs( colorMap.w ) );",
|
|
|
|