未验证 提交 f4cc357a 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #17538 from gkjohnson/lint-example-shaders-3

Linting: Lint Example Shaders PR 3
......@@ -19,9 +19,9 @@ THREE.LuminosityShader = {
"void main() {",
"vUv = uv;",
" vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -37,11 +37,11 @@ THREE.LuminosityShader = {
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
" vec4 texel = texture2D( tDiffuse, vUv );",
"float l = linearToRelativeLuminance( texel.rgb );",
" float l = linearToRelativeLuminance( texel.rgb );",
"gl_FragColor = vec4( l, l, l, texel.w );",
" gl_FragColor = vec4( l, l, l, texel.w );",
"}"
......
......@@ -22,8 +22,8 @@ THREE.MirrorShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -38,18 +38,18 @@ THREE.MirrorShader = {
"void main() {",
"vec2 p = vUv;",
"if (side == 0){",
"if (p.x > 0.5) p.x = 1.0 - p.x;",
"}else if (side == 1){",
"if (p.x < 0.5) p.x = 1.0 - p.x;",
"}else if (side == 2){",
"if (p.y < 0.5) p.y = 1.0 - p.y;",
"}else if (side == 3){",
"if (p.y > 0.5) p.y = 1.0 - p.y;",
"} ",
"vec4 color = texture2D(tDiffuse, p);",
"gl_FragColor = color;",
" vec2 p = vUv;",
" if (side == 0){",
" if (p.x > 0.5) p.x = 1.0 - p.x;",
" }else if (side == 1){",
" if (p.x < 0.5) p.x = 1.0 - p.x;",
" }else if (side == 2){",
" if (p.y < 0.5) p.y = 1.0 - p.y;",
" }else if (side == 3){",
" if (p.y > 0.5) p.y = 1.0 - p.y;",
" } ",
" vec4 color = texture2D(tDiffuse, p);",
" gl_FragColor = color;",
"}"
......
......@@ -22,8 +22,8 @@ THREE.NormalMapShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -39,12 +39,12 @@ THREE.NormalMapShader = {
"void main() {",
"float val = texture2D( heightMap, vUv ).x;",
" float val = texture2D( heightMap, vUv ).x;",
"float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
"float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
" float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
" float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
"gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
" gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
"}"
......
......@@ -28,11 +28,11 @@ THREE.ParallaxShader = {
"void main() {",
"vUv = uv;",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vViewPosition = -mvPosition.xyz;",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * mvPosition;",
" vUv = uv;",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" vViewPosition = -mvPosition.xyz;",
" vNormal = normalize( normalMatrix * normal );",
" gl_Position = projectionMatrix * mvPosition;",
"}"
......@@ -52,130 +52,130 @@ THREE.ParallaxShader = {
"#ifdef USE_BASIC_PARALLAX",
"vec2 parallaxMap( in vec3 V ) {",
" vec2 parallaxMap( in vec3 V ) {",
"float initialHeight = texture2D( bumpMap, vUv ).r;",
" float initialHeight = texture2D( bumpMap, vUv ).r;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
"vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
"return vUv - texCoordOffset;",
" vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
" return vUv - texCoordOffset;",
"}",
" }",
"#else",
"vec2 parallaxMap( in vec3 V ) {",
" vec2 parallaxMap( in vec3 V ) {",
// Determine number of layers from angle between V and N
"float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
" float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
"float layerHeight = 1.0 / numLayers;",
"float currentLayerHeight = 0.0;",
" float layerHeight = 1.0 / numLayers;",
" float currentLayerHeight = 0.0;",
// Shift of texture coordinates for each iteration
"vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
" vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
"vec2 currentTextureCoords = vUv;",
" vec2 currentTextureCoords = vUv;",
"float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
"for ( int i = 0; i < 30; i += 1 ) {",
"if ( heightFromTexture <= currentLayerHeight ) {",
"break;",
"}",
"currentLayerHeight += layerHeight;",
" for ( int i = 0; i < 30; i += 1 ) {",
" if ( heightFromTexture <= currentLayerHeight ) {",
" break;",
" }",
" currentLayerHeight += layerHeight;",
// Shift texture coordinates along vector V
"currentTextureCoords -= dtex;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
"}",
" currentTextureCoords -= dtex;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" }",
"#ifdef USE_STEEP_PARALLAX",
" #ifdef USE_STEEP_PARALLAX",
"return currentTextureCoords;",
" return currentTextureCoords;",
"#elif defined( USE_RELIEF_PARALLAX )",
" #elif defined( USE_RELIEF_PARALLAX )",
"vec2 deltaTexCoord = dtex / 2.0;",
"float deltaHeight = layerHeight / 2.0;",
" vec2 deltaTexCoord = dtex / 2.0;",
" float deltaHeight = layerHeight / 2.0;",
// Return to the mid point of previous layer
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
// Binary search to increase precision of Steep Parallax Mapping
"const int numSearches = 5;",
"for ( int i = 0; i < numSearches; i += 1 ) {",
" const int numSearches = 5;",
" for ( int i = 0; i < numSearches; i += 1 ) {",
"deltaTexCoord /= 2.0;",
"deltaHeight /= 2.0;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" deltaTexCoord /= 2.0;",
" deltaHeight /= 2.0;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// Shift along or against vector V
"if( heightFromTexture > currentLayerHeight ) {", // Below the surface
" if( heightFromTexture > currentLayerHeight ) {", // Below the surface
"currentTextureCoords -= deltaTexCoord;",
"currentLayerHeight += deltaHeight;",
" currentTextureCoords -= deltaTexCoord;",
" currentLayerHeight += deltaHeight;",
"} else {", // above the surface
" } else {", // above the surface
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
"}",
" }",
"}",
"return currentTextureCoords;",
" }",
" return currentTextureCoords;",
"#elif defined( USE_OCLUSION_PARALLAX )",
" #elif defined( USE_OCLUSION_PARALLAX )",
"vec2 prevTCoords = currentTextureCoords + dtex;",
" vec2 prevTCoords = currentTextureCoords + dtex;",
// Heights for linear interpolation
"float nextH = heightFromTexture - currentLayerHeight;",
"float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
" float nextH = heightFromTexture - currentLayerHeight;",
" float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
// Proportions for linear interpolation
"float weight = nextH / ( nextH - prevH );",
" float weight = nextH / ( nextH - prevH );",
// Interpolation of texture coordinates
"return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
" return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
"#else", // NO_PARALLAX
" #else", // NO_PARALLAX
"return vUv;",
" return vUv;",
"#endif",
" #endif",
"}",
" }",
"#endif",
"vec2 perturbUv( vec3 surfPosition, vec3 surfNormal, vec3 viewPosition ) {",
"vec2 texDx = dFdx( vUv );",
"vec2 texDy = dFdy( vUv );",
" vec2 texDx = dFdx( vUv );",
" vec2 texDy = dFdy( vUv );",
"vec3 vSigmaX = dFdx( surfPosition );",
"vec3 vSigmaY = dFdy( surfPosition );",
"vec3 vR1 = cross( vSigmaY, surfNormal );",
"vec3 vR2 = cross( surfNormal, vSigmaX );",
"float fDet = dot( vSigmaX, vR1 );",
" vec3 vSigmaX = dFdx( surfPosition );",
" vec3 vSigmaY = dFdy( surfPosition );",
" vec3 vR1 = cross( vSigmaY, surfNormal );",
" vec3 vR2 = cross( surfNormal, vSigmaX );",
" float fDet = dot( vSigmaX, vR1 );",
"vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );",
"vec3 vProjVtex;",
"vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;",
"vProjVtex.z = dot( surfNormal, viewPosition );",
" vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );",
" vec3 vProjVtex;",
" vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;",
" vProjVtex.z = dot( surfNormal, viewPosition );",
"return parallaxMap( vProjVtex );",
" return parallaxMap( vProjVtex );",
"}",
"void main() {",
"vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );",
"gl_FragColor = texture2D( map, mapUv );",
" vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );",
" gl_FragColor = texture2D( map, mapUv );",
"}"
......
......@@ -26,8 +26,8 @@ THREE.RGBShiftShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -43,11 +43,11 @@ THREE.RGBShiftShader = {
"void main() {",
"vec2 offset = amount * vec2( cos(angle), sin(angle));",
"vec4 cr = texture2D(tDiffuse, vUv + offset);",
"vec4 cga = texture2D(tDiffuse, vUv);",
"vec4 cb = texture2D(tDiffuse, vUv - offset);",
"gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
" vec2 offset = amount * vec2( cos(angle), sin(angle));",
" vec4 cr = texture2D(tDiffuse, vUv + offset);",
" vec4 cga = texture2D(tDiffuse, vUv);",
" vec4 cb = texture2D(tDiffuse, vUv - offset);",
" gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
"}"
......
......@@ -21,8 +21,8 @@ THREE.SepiaShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -38,14 +38,14 @@ THREE.SepiaShader = {
"void main() {",
"vec4 color = texture2D( tDiffuse, vUv );",
"vec3 c = color.rgb;",
" vec4 color = texture2D( tDiffuse, vUv );",
" vec3 c = color.rgb;",
"color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
"color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
"color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
" color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
" color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
" color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
"gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
" gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
"}"
......
......@@ -22,9 +22,9 @@ THREE.SobelOperatorShader = {
"void main() {",
"vUv = uv;",
" vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -38,50 +38,50 @@ THREE.SobelOperatorShader = {
"void main() {",
"vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
" vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
// kernel definition (in glsl matrices are filled in column-major order)
"const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
"const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
" const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
" const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
// fetch the 3x3 neighbourhood of a fragment
// first column
"float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
"float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
"float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
" float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
" float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
" float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
// second column
"float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
"float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
"float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
" float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
" float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
" float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
// third column
"float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
"float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
"float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
" float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
" float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
" float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
// gradient value in x direction
"float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
"Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
"Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
" float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
" Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
" Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
// gradient value in y direction
"float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
"Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
"Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
" float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
" Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
" Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
// magnitute of the total gradient
"float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
" float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
"gl_FragColor = vec4( vec3( G ), 1 );",
" gl_FragColor = vec4( vec3( G ), 1 );",
"}"
......
......@@ -21,8 +21,8 @@ THREE.TechnicolorShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -35,10 +35,10 @@ THREE.TechnicolorShader = {
"void main() {",
"vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
"vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);",
" vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
" vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);",
"gl_FragColor = newTex;",
" gl_FragColor = newTex;",
"}"
......
......@@ -90,151 +90,151 @@ THREE.TerrainShader = {
THREE.ShaderChunk[ "fog_pars_fragment" ],
"float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {",
"if ( decayExponent > 0.0 ) {",
"return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );",
"}",
"return 1.0;",
"}",
" if ( decayExponent > 0.0 ) {",
" return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );",
" }",
" return 1.0;",
" }",
"void main() {",
"vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
"vec4 diffuseColor = vec4( diffuse, opacity );",
" vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
" vec4 diffuseColor = vec4( diffuse, opacity );",
"vec3 specularTex = vec3( 1.0 );",
" vec3 specularTex = vec3( 1.0 );",
"vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;",
"vec2 uvBase = uRepeatBase * vUv;",
" vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;",
" vec2 uvBase = uRepeatBase * vUv;",
"vec3 normalTex = texture2D( tDetail, uvOverlay ).xyz * 2.0 - 1.0;",
"normalTex.xy *= uNormalScale;",
"normalTex = normalize( normalTex );",
" vec3 normalTex = texture2D( tDetail, uvOverlay ).xyz * 2.0 - 1.0;",
" normalTex.xy *= uNormalScale;",
" normalTex = normalize( normalTex );",
"if( enableDiffuse1 && enableDiffuse2 ) {",
" if( enableDiffuse1 && enableDiffuse2 ) {",
"vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
"vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
" vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
" vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
"colDiffuse1 = GammaToLinear( colDiffuse1, float( GAMMA_FACTOR ) );",
"colDiffuse2 = GammaToLinear( colDiffuse2, float( GAMMA_FACTOR ) );",
" colDiffuse1 = GammaToLinear( colDiffuse1, float( GAMMA_FACTOR ) );",
" colDiffuse2 = GammaToLinear( colDiffuse2, float( GAMMA_FACTOR ) );",
"diffuseColor *= mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
" diffuseColor *= mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
" } else if( enableDiffuse1 ) {",
" } else if( enableDiffuse1 ) {",
"diffuseColor *= texture2D( tDiffuse1, uvOverlay );",
" diffuseColor *= texture2D( tDiffuse1, uvOverlay );",
"} else if( enableDiffuse2 ) {",
" } else if( enableDiffuse2 ) {",
"diffuseColor *= texture2D( tDiffuse2, uvOverlay );",
" diffuseColor *= texture2D( tDiffuse2, uvOverlay );",
"}",
" }",
"if( enableSpecular )",
"specularTex = texture2D( tSpecular, uvOverlay ).xyz;",
" if( enableSpecular )",
" specularTex = texture2D( tSpecular, uvOverlay ).xyz;",
"mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
"vec3 finalNormal = tsb * normalTex;",
" mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
" vec3 finalNormal = tsb * normalTex;",
"vec3 normal = normalize( finalNormal );",
"vec3 viewPosition = normalize( vViewPosition );",
" vec3 normal = normalize( finalNormal );",
" vec3 viewPosition = normalize( vViewPosition );",
"vec3 totalDiffuseLight = vec3( 0.0 );",
"vec3 totalSpecularLight = vec3( 0.0 );",
" vec3 totalDiffuseLight = vec3( 0.0 );",
" vec3 totalSpecularLight = vec3( 0.0 );",
// point lights
"#if NUM_POINT_LIGHTS > 0",
" #if NUM_POINT_LIGHTS > 0",
"for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {",
" for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {",
"vec3 lVector = pointLights[ i ].position + vViewPosition.xyz;",
" vec3 lVector = pointLights[ i ].position + vViewPosition.xyz;",
"float attenuation = calcLightAttenuation( length( lVector ), pointLights[ i ].distance, pointLights[ i ].decay );",
" float attenuation = calcLightAttenuation( length( lVector ), pointLights[ i ].distance, pointLights[ i ].decay );",
"lVector = normalize( lVector );",
" lVector = normalize( lVector );",
"vec3 pointHalfVector = normalize( lVector + viewPosition );",
" vec3 pointHalfVector = normalize( lVector + viewPosition );",
"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
"float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
" float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
" float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
" float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
"totalDiffuseLight += attenuation * pointLights[ i ].color * pointDiffuseWeight;",
"totalSpecularLight += attenuation * pointLights[ i ].color * specular * pointSpecularWeight * pointDiffuseWeight;",
" totalDiffuseLight += attenuation * pointLights[ i ].color * pointDiffuseWeight;",
" totalSpecularLight += attenuation * pointLights[ i ].color * specular * pointSpecularWeight * pointDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
// directional lights
"#if NUM_DIR_LIGHTS > 0",
" #if NUM_DIR_LIGHTS > 0",
"vec3 dirDiffuse = vec3( 0.0 );",
"vec3 dirSpecular = vec3( 0.0 );",
" vec3 dirDiffuse = vec3( 0.0 );",
" vec3 dirSpecular = vec3( 0.0 );",
"for( int i = 0; i < NUM_DIR_LIGHTS; i++ ) {",
" for( int i = 0; i < NUM_DIR_LIGHTS; i++ ) {",
"vec3 dirVector = directionalLights[ i ].direction;",
"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
" vec3 dirVector = directionalLights[ i ].direction;",
" vec3 dirHalfVector = normalize( dirVector + viewPosition );",
"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
" float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
" float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
" float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
"totalDiffuseLight += directionalLights[ i ].color * dirDiffuseWeight;",
"totalSpecularLight += directionalLights[ i ].color * specular * dirSpecularWeight * dirDiffuseWeight;",
" totalDiffuseLight += directionalLights[ i ].color * dirDiffuseWeight;",
" totalSpecularLight += directionalLights[ i ].color * specular * dirSpecularWeight * dirDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
// hemisphere lights
"#if NUM_HEMI_LIGHTS > 0",
" #if NUM_HEMI_LIGHTS > 0",
"vec3 hemiDiffuse = vec3( 0.0 );",
"vec3 hemiSpecular = vec3( 0.0 );",
" vec3 hemiDiffuse = vec3( 0.0 );",
" vec3 hemiSpecular = vec3( 0.0 );",
"for( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {",
" for( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {",
"vec3 lVector = hemisphereLightDirection[ i ];",
" vec3 lVector = hemisphereLightDirection[ i ];",
// diffuse
"float dotProduct = dot( normal, lVector );",
"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
" float dotProduct = dot( normal, lVector );",
" float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
"totalDiffuseLight += mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight );",
" totalDiffuseLight += mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight );",
// specular (sky light)
"float hemiSpecularWeight = 0.0;",
" float hemiSpecularWeight = 0.0;",
"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
" vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
" float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
" hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
// specular (ground light)
"vec3 lVectorGround = -lVector;",
" vec3 lVectorGround = -lVector;",
"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
" vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
" float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
" hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
"totalSpecularLight += specular * mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
" totalSpecularLight += specular * mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
"outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor + totalSpecularLight );",
" outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor + totalSpecularLight );",
"gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
THREE.ShaderChunk[ "fog_fragment" ],
......@@ -252,9 +252,9 @@ THREE.TerrainShader = {
"#ifdef VERTEX_TEXTURES",
"uniform sampler2D tDisplacement;",
"uniform float uDisplacementScale;",
"uniform float uDisplacementBias;",
" uniform sampler2D tDisplacement;",
" uniform float uDisplacementScale;",
" uniform float uDisplacementBias;",
"#endif",
......@@ -270,45 +270,45 @@ THREE.TerrainShader = {
"void main() {",
"vNormal = normalize( normalMatrix * normal );",
" vNormal = normalize( normalMatrix * normal );",
// tangent and binormal vectors
"vTangent = normalize( normalMatrix * tangent.xyz );",
" vTangent = normalize( normalMatrix * tangent.xyz );",
"vBinormal = cross( vNormal, vTangent ) * tangent.w;",
"vBinormal = normalize( vBinormal );",
" vBinormal = cross( vNormal, vTangent ) * tangent.w;",
" vBinormal = normalize( vBinormal );",
// texture coordinates
"vUv = uv;",
" vUv = uv;",
"vec2 uvBase = uv * uRepeatBase;",
" vec2 uvBase = uv * uRepeatBase;",
// displacement mapping
"#ifdef VERTEX_TEXTURES",
" #ifdef VERTEX_TEXTURES",
"vec3 dv = texture2D( tDisplacement, uvBase ).xyz;",
"float df = uDisplacementScale * dv.x + uDisplacementBias;",
"vec3 displacedPosition = normal * df + position;",
" vec3 dv = texture2D( tDisplacement, uvBase ).xyz;",
" float df = uDisplacementScale * dv.x + uDisplacementBias;",
" vec3 displacedPosition = normal * df + position;",
"vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
" vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
" vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
"#else",
" #else",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"#endif",
" #endif",
"gl_Position = projectionMatrix * mvPosition;",
" gl_Position = projectionMatrix * mvPosition;",
"vViewPosition = -mvPosition.xyz;",
" vViewPosition = -mvPosition.xyz;",
"vec3 normalTex = texture2D( tNormal, uvBase ).xyz * 2.0 - 1.0;",
"vNormal = normalMatrix * normalTex;",
" vec3 normalTex = texture2D( tNormal, uvBase ).xyz * 2.0 - 1.0;",
" vNormal = normalMatrix * normalTex;",
THREE.ShaderChunk[ "shadowmap_vertex" ],
THREE.ShaderChunk[ "fog_vertex" ],
......
......@@ -22,8 +22,8 @@ THREE.ToneMapShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -41,34 +41,34 @@ THREE.ToneMapShader = {
"uniform float minLuminance;",
"uniform float maxLuminance;",
"#ifdef ADAPTED_LUMINANCE",
"uniform sampler2D luminanceMap;",
" uniform sampler2D luminanceMap;",
"#else",
"uniform float averageLuminance;",
" uniform float averageLuminance;",
"#endif",
"vec3 ToneMap( vec3 vColor ) {",
"#ifdef ADAPTED_LUMINANCE",
" #ifdef ADAPTED_LUMINANCE",
// Get the calculated average luminance
"float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;",
"#else",
"float fLumAvg = averageLuminance;",
"#endif",
" float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;",
" #else",
" float fLumAvg = averageLuminance;",
" #endif",
// Calculate the luminance of the current pixel
"float fLumPixel = linearToRelativeLuminance( vColor );",
" float fLumPixel = linearToRelativeLuminance( vColor );",
// Apply the modified operator (Eq. 4)
"float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );",
" float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );",
"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);",
"return fLumCompressed * vColor;",
" float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);",
" return fLumCompressed * vColor;",
"}",
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
" vec4 texel = texture2D( tDiffuse, vUv );",
"gl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );",
" gl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );",
"}"
......
......@@ -25,8 +25,8 @@ THREE.TriangleBlurShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -45,25 +45,25 @@ THREE.TriangleBlurShader = {
"void main() {",
"vec4 color = vec4( 0.0 );",
" vec4 color = vec4( 0.0 );",
"float total = 0.0;",
" float total = 0.0;",
// randomize the lookup values to hide the fixed number of samples
"float offset = rand( vUv );",
" float offset = rand( vUv );",
"for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
" for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
"float percent = ( t + offset - 0.5 ) / ITERATIONS;",
"float weight = 1.0 - abs( percent );",
" float percent = ( t + offset - 0.5 ) / ITERATIONS;",
" float weight = 1.0 - abs( percent );",
"color += texture2D( texture, vUv + delta * percent ) * weight;",
"total += weight;",
" color += texture2D( texture, vUv + delta * percent ) * weight;",
" total += weight;",
"}",
" }",
"gl_FragColor = color / total;",
" gl_FragColor = color / total;",
"}"
......
......@@ -20,8 +20,8 @@ THREE.UnpackDepthRGBAShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -39,8 +39,8 @@ THREE.UnpackDepthRGBAShader = {
"void main() {",
"float depth = 1.0 - unpackRGBAToDepth( texture2D( tDiffuse, vUv ) );",
"gl_FragColor = vec4( vec3( depth ), opacity );",
" float depth = 1.0 - unpackRGBAToDepth( texture2D( tDiffuse, vUv ) );",
" gl_FragColor = vec4( vec3( depth ), opacity );",
"}"
......
......@@ -25,8 +25,8 @@ THREE.VerticalBlurShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -41,19 +41,19 @@ THREE.VerticalBlurShader = {
"void main() {",
"vec4 sum = vec4( 0.0 );",
" vec4 sum = vec4( 0.0 );",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
"gl_FragColor = sum;",
" gl_FragColor = sum;",
"}"
......
......@@ -25,8 +25,8 @@ THREE.VerticalTiltShiftShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -42,21 +42,21 @@ THREE.VerticalTiltShiftShader = {
"void main() {",
"vec4 sum = vec4( 0.0 );",
" vec4 sum = vec4( 0.0 );",
"float vv = v * abs( r - vUv.y );",
" float vv = v * abs( r - vUv.y );",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
"gl_FragColor = sum;",
" gl_FragColor = sum;",
"}"
......
......@@ -22,8 +22,8 @@ THREE.VignetteShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -42,19 +42,19 @@ THREE.VignetteShader = {
// Eskil's vignette
"vec4 texel = texture2D( tDiffuse, vUv );",
"vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
"gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
" vec4 texel = texture2D( tDiffuse, vUv );",
" vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
" gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
/*
// alternative version from glfx.js
// this one makes more "dusty" look (as opposed to "burned")
/*
// alternative version from glfx.js
// this one makes more "dusty" look (as opposed to "burned")
"vec4 color = texture2D( tDiffuse, vUv );",
"float dist = distance( vUv, vec2( 0.5 ) );",
"color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
"gl_FragColor = color;",
*/
" vec4 color = texture2D( tDiffuse, vUv );",
" float dist = distance( vUv, vec2( 0.5 ) );",
" color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
" gl_FragColor = color;",
*/
"}"
......
......@@ -21,9 +21,9 @@ var LuminosityShader = {
"void main() {",
"vUv = uv;",
" vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -39,11 +39,11 @@ var LuminosityShader = {
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
" vec4 texel = texture2D( tDiffuse, vUv );",
"float l = linearToRelativeLuminance( texel.rgb );",
" float l = linearToRelativeLuminance( texel.rgb );",
"gl_FragColor = vec4( l, l, l, texel.w );",
" gl_FragColor = vec4( l, l, l, texel.w );",
"}"
......
......@@ -24,8 +24,8 @@ var MirrorShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -40,18 +40,18 @@ var MirrorShader = {
"void main() {",
"vec2 p = vUv;",
"if (side == 0){",
"if (p.x > 0.5) p.x = 1.0 - p.x;",
"}else if (side == 1){",
"if (p.x < 0.5) p.x = 1.0 - p.x;",
"}else if (side == 2){",
"if (p.y < 0.5) p.y = 1.0 - p.y;",
"}else if (side == 3){",
"if (p.y > 0.5) p.y = 1.0 - p.y;",
"} ",
"vec4 color = texture2D(tDiffuse, p);",
"gl_FragColor = color;",
" vec2 p = vUv;",
" if (side == 0){",
" if (p.x > 0.5) p.x = 1.0 - p.x;",
" }else if (side == 1){",
" if (p.x < 0.5) p.x = 1.0 - p.x;",
" }else if (side == 2){",
" if (p.y < 0.5) p.y = 1.0 - p.y;",
" }else if (side == 3){",
" if (p.y > 0.5) p.y = 1.0 - p.y;",
" } ",
" vec4 color = texture2D(tDiffuse, p);",
" gl_FragColor = color;",
"}"
......
......@@ -26,8 +26,8 @@ var NormalMapShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -43,12 +43,12 @@ var NormalMapShader = {
"void main() {",
"float val = texture2D( heightMap, vUv ).x;",
" float val = texture2D( heightMap, vUv ).x;",
"float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
"float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
" float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
" float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
"gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
" gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
"}"
......
......@@ -28,11 +28,11 @@ var ParallaxShader = {
"void main() {",
"vUv = uv;",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vViewPosition = -mvPosition.xyz;",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * mvPosition;",
" vUv = uv;",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" vViewPosition = -mvPosition.xyz;",
" vNormal = normalize( normalMatrix * normal );",
" gl_Position = projectionMatrix * mvPosition;",
"}"
......@@ -52,130 +52,130 @@ var ParallaxShader = {
"#ifdef USE_BASIC_PARALLAX",
"vec2 parallaxMap( in vec3 V ) {",
" vec2 parallaxMap( in vec3 V ) {",
"float initialHeight = texture2D( bumpMap, vUv ).r;",
" float initialHeight = texture2D( bumpMap, vUv ).r;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
"vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
"return vUv - texCoordOffset;",
" vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
" return vUv - texCoordOffset;",
"}",
" }",
"#else",
"vec2 parallaxMap( in vec3 V ) {",
" vec2 parallaxMap( in vec3 V ) {",
// Determine number of layers from angle between V and N
"float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
" float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
"float layerHeight = 1.0 / numLayers;",
"float currentLayerHeight = 0.0;",
" float layerHeight = 1.0 / numLayers;",
" float currentLayerHeight = 0.0;",
// Shift of texture coordinates for each iteration
"vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
" vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
"vec2 currentTextureCoords = vUv;",
" vec2 currentTextureCoords = vUv;",
"float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
"for ( int i = 0; i < 30; i += 1 ) {",
"if ( heightFromTexture <= currentLayerHeight ) {",
"break;",
"}",
"currentLayerHeight += layerHeight;",
" for ( int i = 0; i < 30; i += 1 ) {",
" if ( heightFromTexture <= currentLayerHeight ) {",
" break;",
" }",
" currentLayerHeight += layerHeight;",
// Shift texture coordinates along vector V
"currentTextureCoords -= dtex;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
"}",
" currentTextureCoords -= dtex;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" }",
"#ifdef USE_STEEP_PARALLAX",
" #ifdef USE_STEEP_PARALLAX",
"return currentTextureCoords;",
" return currentTextureCoords;",
"#elif defined( USE_RELIEF_PARALLAX )",
" #elif defined( USE_RELIEF_PARALLAX )",
"vec2 deltaTexCoord = dtex / 2.0;",
"float deltaHeight = layerHeight / 2.0;",
" vec2 deltaTexCoord = dtex / 2.0;",
" float deltaHeight = layerHeight / 2.0;",
// Return to the mid point of previous layer
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
// Binary search to increase precision of Steep Parallax Mapping
"const int numSearches = 5;",
"for ( int i = 0; i < numSearches; i += 1 ) {",
" const int numSearches = 5;",
" for ( int i = 0; i < numSearches; i += 1 ) {",
"deltaTexCoord /= 2.0;",
"deltaHeight /= 2.0;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" deltaTexCoord /= 2.0;",
" deltaHeight /= 2.0;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// Shift along or against vector V
"if( heightFromTexture > currentLayerHeight ) {", // Below the surface
" if( heightFromTexture > currentLayerHeight ) {", // Below the surface
"currentTextureCoords -= deltaTexCoord;",
"currentLayerHeight += deltaHeight;",
" currentTextureCoords -= deltaTexCoord;",
" currentLayerHeight += deltaHeight;",
"} else {", // above the surface
" } else {", // above the surface
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
"}",
" }",
"}",
"return currentTextureCoords;",
" }",
" return currentTextureCoords;",
"#elif defined( USE_OCLUSION_PARALLAX )",
" #elif defined( USE_OCLUSION_PARALLAX )",
"vec2 prevTCoords = currentTextureCoords + dtex;",
" vec2 prevTCoords = currentTextureCoords + dtex;",
// Heights for linear interpolation
"float nextH = heightFromTexture - currentLayerHeight;",
"float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
" float nextH = heightFromTexture - currentLayerHeight;",
" float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
// Proportions for linear interpolation
"float weight = nextH / ( nextH - prevH );",
" float weight = nextH / ( nextH - prevH );",
// Interpolation of texture coordinates
"return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
" return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
"#else", // NO_PARALLAX
" #else", // NO_PARALLAX
"return vUv;",
" return vUv;",
"#endif",
" #endif",
"}",
" }",
"#endif",
"vec2 perturbUv( vec3 surfPosition, vec3 surfNormal, vec3 viewPosition ) {",
"vec2 texDx = dFdx( vUv );",
"vec2 texDy = dFdy( vUv );",
" vec2 texDx = dFdx( vUv );",
" vec2 texDy = dFdy( vUv );",
"vec3 vSigmaX = dFdx( surfPosition );",
"vec3 vSigmaY = dFdy( surfPosition );",
"vec3 vR1 = cross( vSigmaY, surfNormal );",
"vec3 vR2 = cross( surfNormal, vSigmaX );",
"float fDet = dot( vSigmaX, vR1 );",
" vec3 vSigmaX = dFdx( surfPosition );",
" vec3 vSigmaY = dFdy( surfPosition );",
" vec3 vR1 = cross( vSigmaY, surfNormal );",
" vec3 vR2 = cross( surfNormal, vSigmaX );",
" float fDet = dot( vSigmaX, vR1 );",
"vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );",
"vec3 vProjVtex;",
"vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;",
"vProjVtex.z = dot( surfNormal, viewPosition );",
" vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );",
" vec3 vProjVtex;",
" vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;",
" vProjVtex.z = dot( surfNormal, viewPosition );",
"return parallaxMap( vProjVtex );",
" return parallaxMap( vProjVtex );",
"}",
"void main() {",
"vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );",
"gl_FragColor = texture2D( map, mapUv );",
" vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );",
" gl_FragColor = texture2D( map, mapUv );",
"}"
......
......@@ -28,8 +28,8 @@ var RGBShiftShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -45,11 +45,11 @@ var RGBShiftShader = {
"void main() {",
"vec2 offset = amount * vec2( cos(angle), sin(angle));",
"vec4 cr = texture2D(tDiffuse, vUv + offset);",
"vec4 cga = texture2D(tDiffuse, vUv);",
"vec4 cb = texture2D(tDiffuse, vUv - offset);",
"gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
" vec2 offset = amount * vec2( cos(angle), sin(angle));",
" vec4 cr = texture2D(tDiffuse, vUv + offset);",
" vec4 cga = texture2D(tDiffuse, vUv);",
" vec4 cb = texture2D(tDiffuse, vUv - offset);",
" gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
"}"
......
......@@ -23,8 +23,8 @@ var SepiaShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -40,14 +40,14 @@ var SepiaShader = {
"void main() {",
"vec4 color = texture2D( tDiffuse, vUv );",
"vec3 c = color.rgb;",
" vec4 color = texture2D( tDiffuse, vUv );",
" vec3 c = color.rgb;",
"color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
"color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
"color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
" color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
" color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
" color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
"gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
" gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
"}"
......
......@@ -26,9 +26,9 @@ var SobelOperatorShader = {
"void main() {",
"vUv = uv;",
" vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -42,50 +42,50 @@ var SobelOperatorShader = {
"void main() {",
"vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
" vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
// kernel definition (in glsl matrices are filled in column-major order)
"const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
"const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
" const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
" const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
// fetch the 3x3 neighbourhood of a fragment
// first column
"float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
"float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
"float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
" float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
" float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
" float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
// second column
"float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
"float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
"float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
" float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
" float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
" float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
// third column
"float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
"float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
"float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
" float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
" float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
" float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
// gradient value in x direction
"float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
"Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
"Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
" float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
" Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
" Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
// gradient value in y direction
"float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
"Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
"Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
" float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
" Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
" Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
// magnitute of the total gradient
"float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
" float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
"gl_FragColor = vec4( vec3( G ), 1 );",
" gl_FragColor = vec4( vec3( G ), 1 );",
"}"
......
......@@ -23,8 +23,8 @@ var TechnicolorShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -37,10 +37,10 @@ var TechnicolorShader = {
"void main() {",
"vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
"vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);",
" vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
" vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);",
"gl_FragColor = newTex;",
" gl_FragColor = newTex;",
"}"
......
......@@ -98,151 +98,151 @@ var TerrainShader = {
ShaderChunk[ "fog_pars_fragment" ],
"float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {",
"if ( decayExponent > 0.0 ) {",
"return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );",
"}",
"return 1.0;",
"}",
" if ( decayExponent > 0.0 ) {",
" return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );",
" }",
" return 1.0;",
" }",
"void main() {",
"vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
"vec4 diffuseColor = vec4( diffuse, opacity );",
" vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
" vec4 diffuseColor = vec4( diffuse, opacity );",
"vec3 specularTex = vec3( 1.0 );",
" vec3 specularTex = vec3( 1.0 );",
"vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;",
"vec2 uvBase = uRepeatBase * vUv;",
" vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;",
" vec2 uvBase = uRepeatBase * vUv;",
"vec3 normalTex = texture2D( tDetail, uvOverlay ).xyz * 2.0 - 1.0;",
"normalTex.xy *= uNormalScale;",
"normalTex = normalize( normalTex );",
" vec3 normalTex = texture2D( tDetail, uvOverlay ).xyz * 2.0 - 1.0;",
" normalTex.xy *= uNormalScale;",
" normalTex = normalize( normalTex );",
"if( enableDiffuse1 && enableDiffuse2 ) {",
" if( enableDiffuse1 && enableDiffuse2 ) {",
"vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
"vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
" vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
" vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
"colDiffuse1 = GammaToLinear( colDiffuse1, float( GAMMA_FACTOR ) );",
"colDiffuse2 = GammaToLinear( colDiffuse2, float( GAMMA_FACTOR ) );",
" colDiffuse1 = GammaToLinear( colDiffuse1, float( GAMMA_FACTOR ) );",
" colDiffuse2 = GammaToLinear( colDiffuse2, float( GAMMA_FACTOR ) );",
"diffuseColor *= mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
" diffuseColor *= mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
" } else if( enableDiffuse1 ) {",
" } else if( enableDiffuse1 ) {",
"diffuseColor *= texture2D( tDiffuse1, uvOverlay );",
" diffuseColor *= texture2D( tDiffuse1, uvOverlay );",
"} else if( enableDiffuse2 ) {",
" } else if( enableDiffuse2 ) {",
"diffuseColor *= texture2D( tDiffuse2, uvOverlay );",
" diffuseColor *= texture2D( tDiffuse2, uvOverlay );",
"}",
" }",
"if( enableSpecular )",
"specularTex = texture2D( tSpecular, uvOverlay ).xyz;",
" if( enableSpecular )",
" specularTex = texture2D( tSpecular, uvOverlay ).xyz;",
"mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
"vec3 finalNormal = tsb * normalTex;",
" mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
" vec3 finalNormal = tsb * normalTex;",
"vec3 normal = normalize( finalNormal );",
"vec3 viewPosition = normalize( vViewPosition );",
" vec3 normal = normalize( finalNormal );",
" vec3 viewPosition = normalize( vViewPosition );",
"vec3 totalDiffuseLight = vec3( 0.0 );",
"vec3 totalSpecularLight = vec3( 0.0 );",
" vec3 totalDiffuseLight = vec3( 0.0 );",
" vec3 totalSpecularLight = vec3( 0.0 );",
// point lights
"#if NUM_POINT_LIGHTS > 0",
" #if NUM_POINT_LIGHTS > 0",
"for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {",
" for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {",
"vec3 lVector = pointLights[ i ].position + vViewPosition.xyz;",
" vec3 lVector = pointLights[ i ].position + vViewPosition.xyz;",
"float attenuation = calcLightAttenuation( length( lVector ), pointLights[ i ].distance, pointLights[ i ].decay );",
" float attenuation = calcLightAttenuation( length( lVector ), pointLights[ i ].distance, pointLights[ i ].decay );",
"lVector = normalize( lVector );",
" lVector = normalize( lVector );",
"vec3 pointHalfVector = normalize( lVector + viewPosition );",
" vec3 pointHalfVector = normalize( lVector + viewPosition );",
"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
"float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
" float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
" float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
" float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
"totalDiffuseLight += attenuation * pointLights[ i ].color * pointDiffuseWeight;",
"totalSpecularLight += attenuation * pointLights[ i ].color * specular * pointSpecularWeight * pointDiffuseWeight;",
" totalDiffuseLight += attenuation * pointLights[ i ].color * pointDiffuseWeight;",
" totalSpecularLight += attenuation * pointLights[ i ].color * specular * pointSpecularWeight * pointDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
// directional lights
"#if NUM_DIR_LIGHTS > 0",
" #if NUM_DIR_LIGHTS > 0",
"vec3 dirDiffuse = vec3( 0.0 );",
"vec3 dirSpecular = vec3( 0.0 );",
" vec3 dirDiffuse = vec3( 0.0 );",
" vec3 dirSpecular = vec3( 0.0 );",
"for( int i = 0; i < NUM_DIR_LIGHTS; i++ ) {",
" for( int i = 0; i < NUM_DIR_LIGHTS; i++ ) {",
"vec3 dirVector = directionalLights[ i ].direction;",
"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
" vec3 dirVector = directionalLights[ i ].direction;",
" vec3 dirHalfVector = normalize( dirVector + viewPosition );",
"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
" float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
" float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
" float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
"totalDiffuseLight += directionalLights[ i ].color * dirDiffuseWeight;",
"totalSpecularLight += directionalLights[ i ].color * specular * dirSpecularWeight * dirDiffuseWeight;",
" totalDiffuseLight += directionalLights[ i ].color * dirDiffuseWeight;",
" totalSpecularLight += directionalLights[ i ].color * specular * dirSpecularWeight * dirDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
// hemisphere lights
"#if NUM_HEMI_LIGHTS > 0",
" #if NUM_HEMI_LIGHTS > 0",
"vec3 hemiDiffuse = vec3( 0.0 );",
"vec3 hemiSpecular = vec3( 0.0 );",
" vec3 hemiDiffuse = vec3( 0.0 );",
" vec3 hemiSpecular = vec3( 0.0 );",
"for( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {",
" for( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {",
"vec3 lVector = hemisphereLightDirection[ i ];",
" vec3 lVector = hemisphereLightDirection[ i ];",
// diffuse
"float dotProduct = dot( normal, lVector );",
"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
" float dotProduct = dot( normal, lVector );",
" float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
"totalDiffuseLight += mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight );",
" totalDiffuseLight += mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight );",
// specular (sky light)
"float hemiSpecularWeight = 0.0;",
" float hemiSpecularWeight = 0.0;",
"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
" vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
" float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
" hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
// specular (ground light)
"vec3 lVectorGround = -lVector;",
" vec3 lVectorGround = -lVector;",
"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
" vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
" float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
" hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
"totalSpecularLight += specular * mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
" totalSpecularLight += specular * mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
"}",
" }",
"#endif",
" #endif",
"outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor + totalSpecularLight );",
" outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor + totalSpecularLight );",
"gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
ShaderChunk[ "fog_fragment" ],
......@@ -260,9 +260,9 @@ var TerrainShader = {
"#ifdef VERTEX_TEXTURES",
"uniform sampler2D tDisplacement;",
"uniform float uDisplacementScale;",
"uniform float uDisplacementBias;",
" uniform sampler2D tDisplacement;",
" uniform float uDisplacementScale;",
" uniform float uDisplacementBias;",
"#endif",
......@@ -278,45 +278,45 @@ var TerrainShader = {
"void main() {",
"vNormal = normalize( normalMatrix * normal );",
" vNormal = normalize( normalMatrix * normal );",
// tangent and binormal vectors
"vTangent = normalize( normalMatrix * tangent.xyz );",
" vTangent = normalize( normalMatrix * tangent.xyz );",
"vBinormal = cross( vNormal, vTangent ) * tangent.w;",
"vBinormal = normalize( vBinormal );",
" vBinormal = cross( vNormal, vTangent ) * tangent.w;",
" vBinormal = normalize( vBinormal );",
// texture coordinates
"vUv = uv;",
" vUv = uv;",
"vec2 uvBase = uv * uRepeatBase;",
" vec2 uvBase = uv * uRepeatBase;",
// displacement mapping
"#ifdef VERTEX_TEXTURES",
" #ifdef VERTEX_TEXTURES",
"vec3 dv = texture2D( tDisplacement, uvBase ).xyz;",
"float df = uDisplacementScale * dv.x + uDisplacementBias;",
"vec3 displacedPosition = normal * df + position;",
" vec3 dv = texture2D( tDisplacement, uvBase ).xyz;",
" float df = uDisplacementScale * dv.x + uDisplacementBias;",
" vec3 displacedPosition = normal * df + position;",
"vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
" vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
" vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
"#else",
" #else",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"#endif",
" #endif",
"gl_Position = projectionMatrix * mvPosition;",
" gl_Position = projectionMatrix * mvPosition;",
"vViewPosition = -mvPosition.xyz;",
" vViewPosition = -mvPosition.xyz;",
"vec3 normalTex = texture2D( tNormal, uvBase ).xyz * 2.0 - 1.0;",
"vNormal = normalMatrix * normalTex;",
" vec3 normalTex = texture2D( tNormal, uvBase ).xyz * 2.0 - 1.0;",
" vNormal = normalMatrix * normalTex;",
ShaderChunk[ "shadowmap_vertex" ],
ShaderChunk[ "fog_vertex" ],
......
......@@ -24,8 +24,8 @@ var ToneMapShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -43,34 +43,34 @@ var ToneMapShader = {
"uniform float minLuminance;",
"uniform float maxLuminance;",
"#ifdef ADAPTED_LUMINANCE",
"uniform sampler2D luminanceMap;",
" uniform sampler2D luminanceMap;",
"#else",
"uniform float averageLuminance;",
" uniform float averageLuminance;",
"#endif",
"vec3 ToneMap( vec3 vColor ) {",
"#ifdef ADAPTED_LUMINANCE",
" #ifdef ADAPTED_LUMINANCE",
// Get the calculated average luminance
"float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;",
"#else",
"float fLumAvg = averageLuminance;",
"#endif",
" float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;",
" #else",
" float fLumAvg = averageLuminance;",
" #endif",
// Calculate the luminance of the current pixel
"float fLumPixel = linearToRelativeLuminance( vColor );",
" float fLumPixel = linearToRelativeLuminance( vColor );",
// Apply the modified operator (Eq. 4)
"float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );",
" float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );",
"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);",
"return fLumCompressed * vColor;",
" float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);",
" return fLumCompressed * vColor;",
"}",
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
" vec4 texel = texture2D( tDiffuse, vUv );",
"gl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );",
" gl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );",
"}"
......
......@@ -29,8 +29,8 @@ var TriangleBlurShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -49,25 +49,25 @@ var TriangleBlurShader = {
"void main() {",
"vec4 color = vec4( 0.0 );",
" vec4 color = vec4( 0.0 );",
"float total = 0.0;",
" float total = 0.0;",
// randomize the lookup values to hide the fixed number of samples
"float offset = rand( vUv );",
" float offset = rand( vUv );",
"for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
" for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
"float percent = ( t + offset - 0.5 ) / ITERATIONS;",
"float weight = 1.0 - abs( percent );",
" float percent = ( t + offset - 0.5 ) / ITERATIONS;",
" float weight = 1.0 - abs( percent );",
"color += texture2D( texture, vUv + delta * percent ) * weight;",
"total += weight;",
" color += texture2D( texture, vUv + delta * percent ) * weight;",
" total += weight;",
"}",
" }",
"gl_FragColor = color / total;",
" gl_FragColor = color / total;",
"}"
......
......@@ -22,8 +22,8 @@ var UnpackDepthRGBAShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -41,8 +41,8 @@ var UnpackDepthRGBAShader = {
"void main() {",
"float depth = 1.0 - unpackRGBAToDepth( texture2D( tDiffuse, vUv ) );",
"gl_FragColor = vec4( vec3( depth ), opacity );",
" float depth = 1.0 - unpackRGBAToDepth( texture2D( tDiffuse, vUv ) );",
" gl_FragColor = vec4( vec3( depth ), opacity );",
"}"
......
......@@ -27,8 +27,8 @@ var VerticalBlurShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -43,19 +43,19 @@ var VerticalBlurShader = {
"void main() {",
"vec4 sum = vec4( 0.0 );",
" vec4 sum = vec4( 0.0 );",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
"gl_FragColor = sum;",
" gl_FragColor = sum;",
"}"
......
......@@ -27,8 +27,8 @@ var VerticalTiltShiftShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -44,21 +44,21 @@ var VerticalTiltShiftShader = {
"void main() {",
"vec4 sum = vec4( 0.0 );",
" vec4 sum = vec4( 0.0 );",
"float vv = v * abs( r - vUv.y );",
" float vv = v * abs( r - vUv.y );",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
" sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
"gl_FragColor = sum;",
" gl_FragColor = sum;",
"}"
......
......@@ -24,8 +24,8 @@ var VignetteShader = {
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
......@@ -44,19 +44,19 @@ var VignetteShader = {
// Eskil's vignette
"vec4 texel = texture2D( tDiffuse, vUv );",
"vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
"gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
" vec4 texel = texture2D( tDiffuse, vUv );",
" vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
" gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
/*
// alternative version from glfx.js
// this one makes more "dusty" look (as opposed to "burned")
/*
// alternative version from glfx.js
// this one makes more "dusty" look (as opposed to "burned")
"vec4 color = texture2D( tDiffuse, vUv );",
"float dist = distance( vUv, vec2( 0.5 ) );",
"color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
"gl_FragColor = color;",
*/
" vec4 color = texture2D( tDiffuse, vUv );",
" float dist = distance( vUv, vec2( 0.5 ) );",
" color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
" gl_FragColor = color;",
*/
"}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册