diff --git a/build/Three.js b/build/Three.js index 3f41e2eed87d81e6c7a671bf7c8e8f96f8fc67f8..8fae2fa8c4509ddef2ca98b5ef8db6f9534cf687 100644 --- a/build/Three.js +++ b/build/Three.js @@ -354,12 +354,13 @@ value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color( THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( 1.0 );\nvec4 mColor = vec4( uDiffuseColor, uOpacity );\nvec4 mSpecular = vec4( uSpecularColor, uOpacity );\nvec3 specularTex = vec3( 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ngl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );\nif( enableAO )\ngl_FragColor = gl_FragColor * texture2D( tAO, vUv );\nif( enableSpecular )\nspecularTex = texture2D( tSpecular, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointTotal = vec4( vec3( 0.0 ), 1.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );\npointTotal += pointDistance * vec4( pointLightColor[ i ], 1.0 ) * ( mColor * pointDiffuseWeight + mSpecular * pointSpecularWeight * pointDiffuseWeight );\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirTotal = vec4( vec3( 0.0 ), 1.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );\ndirTotal += vec4( directionalLightColor[ i ], 1.0 ) * ( mColor * dirDiffuseWeight + mSpecular * dirSpecularWeight * dirDiffuseWeight );\n}\n#endif\nvec4 totalLight = vec4( ambientLightColor * uAmbientColor, uOpacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirTotal;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointTotal;\n#endif\ngl_FragColor = gl_FragColor * totalLight;", THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:"attribute vec4 tangent;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"}, cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},convolution:{uniforms:{tDiffuse:{type:"t", -value:0,texture:null},uImageIncrement:{type:"v2",value:new THREE.Vector2(0.001953125,0)},cKernel:{type:"fv1",value:[]}},vertexShader:"varying vec2 vUv;\nuniform vec2 uImageIncrement;\nvoid main(void) {\nvUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform vec2 uImageIncrement;\nuniform float cKernel[KERNEL_SIZE];\nvoid main(void) {\nvec2 imageCoord = vUv;\nvec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );\nfor( int i=0; i25&&(j=25);g=(j-1)*0.5;e=Array(j);for(c=f=0;c 0\nvec4 pointTotal = vec4( vec3( 0.0 ), 1.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );\npointTotal += pointDistance * vec4( pointLightColor[ i ], 1.0 ) * ( mColor * pointDiffuseWeight + mSpecular * pointSpecularWeight * pointDiffuseWeight );\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirTotal = vec4( vec3( 0.0 ), 1.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );\ndirTotal += vec4( directionalLightColor[ i ], 1.0 ) * ( mColor * dirDiffuseWeight + mSpecular * dirSpecularWeight * dirDiffuseWeight );\n}\n#endif\nvec4 totalLight = vec4( ambientLightColor * uAmbientColor, uOpacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirTotal;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointTotal;\n#endif\ngl_FragColor = gl_FragColor * totalLight;", THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:"attribute vec4 tangent;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"}, cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},convolution:{uniforms:{tDiffuse:{type:"t", -value:0,texture:null},uImageIncrement:{type:"v2",value:new THREE.Vector2(0.001953125,0)},cKernel:{type:"fv1",value:[]}},vertexShader:"varying vec2 vUv;\nuniform vec2 uImageIncrement;\nvoid main(void) {\nvUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform vec2 uImageIncrement;\nuniform float cKernel[KERNEL_SIZE];\nvoid main(void) {\nvec2 imageCoord = vUv;\nvec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );\nfor( int i=0; i25&&(h=25);f=(h-1)*0.5;c=Array(h);for(b=e=0;b - + @@ -153,7 +153,9 @@ var renderModel = new THREE.RenderPass( scene, camera ); var effectBloom = new THREE.BloomPass( 1.3 ); - var effectScreen = new THREE.ScreenPass(); + var effectScreen = new THREE.ShaderPass( THREE.ShaderUtils.lib[ "screen" ] ); + + effectScreen.renderToScreen = true; composer = new THREE.EffectComposer( renderer ); diff --git a/examples/webgl_postprocessing.html b/examples/webgl_postprocessing.html index 82c92bd9baa34b797878eeec1ff77801ae48275f..eafb9539b4147f1a7cfc5b719e7f30af92b5e601 100644 --- a/examples/webgl_postprocessing.html +++ b/examples/webgl_postprocessing.html @@ -11,7 +11,7 @@ text-align:center; font-weight: bold; - background-color: #fff; + background-color: #000; margin: 0px; overflow: hidden; } @@ -20,7 +20,7 @@ color:#fff; background-color: rgba( 0, 0, 0, 0.5 ); position: relative; - margin: 0 auto -2em; + margin: 0 auto -2.1em; top: 0px; width: 550px; padding: 5px; @@ -45,10 +45,9 @@ - - - + + @@ -99,7 +98,7 @@ var halfWidth = window.innerWidth / 2; var halfHeight = window.innerHeight / 2; - var rtTexture, materialColor, material2D, quadBG1, quadBG2; + var materialColor, material2D, quadBG, renderScene; var delta = 0.01; @@ -144,10 +143,10 @@ var plane = new THREE.PlaneGeometry( 1, 1 ); - quadBG1 = new THREE.Mesh( plane, materialColor ); - quadBG1.position.z = -500; - quadBG1.scale.set( window.innerWidth, window.innerHeight, 1 ); - sceneBG.addObject( quadBG1 ); + quadBG = new THREE.Mesh( plane, materialColor ); + quadBG.position.z = -500; + quadBG.scale.set( window.innerWidth, window.innerHeight, 1 ); + sceneBG.addObject( quadBG ); // @@ -162,22 +161,38 @@ stats = new Stats(); stats.domElement.style.position = 'absolute'; stats.domElement.style.top = '0px'; - //container.appendChild( stats.domElement ); + container.appendChild( stats.domElement ); // - var effectBloom = new THREE.BloomPass( 0.75 ); - var effectFilm = new THREE.FilmPass( 0.75, 0.025, 648, false ); + var shaderBleach = THREE.ShaderUtils.lib[ "bleachbypass" ]; + var shaderSepia = THREE.ShaderUtils.lib[ "sepia" ]; + var shaderVignette = THREE.ShaderUtils.lib[ "vignette" ]; + var shaderScreen = THREE.ShaderUtils.lib[ "screen" ]; + + var effectBleach = new THREE.ShaderPass( shaderBleach ); + var effectSepia = new THREE.ShaderPass( shaderSepia ); + var effectVignette = new THREE.ShaderPass( shaderVignette ); + var effectScreen = new THREE.ShaderPass( shaderScreen ); + + effectBleach.uniforms[ "opacity" ].value = 0.95; + + effectSepia.uniforms[ "amount" ].value = 0.6; + + effectVignette.uniforms[ "offset" ].value = 0.95; + effectVignette.uniforms[ "darkness" ].value = 1.6; + + var effectBloom = new THREE.BloomPass( 0.5 ); + var effectFilm = new THREE.FilmPass( 0.5, 0.025, 648, false ); var effectFilmBW = new THREE.FilmPass( 0.35, 0.5, 2048, true ); - var effectSepia = new THREE.SepiaPass( 1.0 ); - var effectScreen = new THREE.ScreenPass(); var effectDotScreen = new THREE.DotScreenPass( new THREE.Vector2( 0, 0 ), 0.5, 0.4 ); - var effectVignette = new THREE.VignettePass( 0.95, 1.6 ); //effectFilm.renderToScreen = true; //effectFilmBW.renderToScreen = true; //effectDotScreen.renderToScreen = true; + //effectBleach.renderToScreen = true; effectVignette.renderToScreen = true; + //effectScreen.renderToScreen = true; // @@ -193,33 +208,13 @@ // - scene2D = new THREE.Scene(); - - var shader = THREE.ShaderUtils.lib[ "screen" ]; - - material2D = new THREE.MeshShaderMaterial( { - - uniforms: THREE.UniformsUtils.clone( shader.uniforms ), - vertexShader: shader.vertexShader, - fragmentShader: shader.fragmentShader - - } ); - - material2D.uniforms[ "tDiffuse" ].texture = composerScene.renderTarget; - - quadBG2 = new THREE.Mesh( plane, material2D ); - quadBG2.position.z = -500; - quadBG2.scale.set( window.innerWidth, window.innerHeight, 1 ); - scene2D.addObject( quadBG2 ); - - var renderScene = new THREE.RenderPass( scene2D, cameraOrtho ); + renderScene = new THREE.TexturePass( composerScene.renderTarget ); // composer1 = new THREE.EffectComposer( renderer ); composer1.addPass( renderScene ); - composer1.addPass( effectBloom ); composer1.addPass( effectFilmBW ); composer1.addPass( effectVignette ); @@ -246,6 +241,8 @@ composer4.addPass( renderScene ); composer4.addPass( effectBloom ); + composer4.addPass( effectFilm ); + composer4.addPass( effectBleach ); composer4.addPass( effectVignette ); // @@ -280,10 +277,9 @@ composer3.reset(); composer4.reset(); - material2D.uniforms[ "tDiffuse" ].texture = composerScene.renderTarget; + renderScene.uniforms[ "tDiffuse" ].texture = composerScene.renderTarget; - quadBG1.scale.set( window.innerWidth, window.innerHeight, 1 ); - quadBG2.scale.set( window.innerWidth, window.innerHeight, 1 ); + quadBG.scale.set( window.innerWidth, window.innerHeight, 1 ); } diff --git a/examples/webgl_ribbons.html b/examples/webgl_ribbons.html index b78de97f89b2474619efc722c035ebf4ba3460bb..a7ff76b23d131538b784350152a431c328054c55 100644 --- a/examples/webgl_ribbons.html +++ b/examples/webgl_ribbons.html @@ -35,7 +35,7 @@ - + @@ -198,7 +198,9 @@ var renderModel = new THREE.RenderPass( scene, camera ); var effectBloom = new THREE.BloomPass( 1.0 ); - var effectScreen = new THREE.ScreenPass(); + var effectScreen = new THREE.ShaderPass( THREE.ShaderUtils.lib[ "screen" ] ); + + effectScreen.renderToScreen = true; composer = new THREE.EffectComposer( renderer ); diff --git a/src/extras/ShaderUtils.js b/src/extras/ShaderUtils.js index 6a7ddaf7d4ebed05455b47695434cff7b6059b80..76a85faaaea86daee234671376775844c64b8c85 100644 --- a/src/extras/ShaderUtils.js +++ b/src/extras/ShaderUtils.js @@ -420,14 +420,15 @@ THREE.ShaderUtils = { vertexShader: [ - "varying vec2 vUv;", + //"#define KERNEL_SIZE 25.0", "uniform vec2 uImageIncrement;", - //"#define KERNEL_SIZE 25.0", - "void main(void) {", + "varying vec2 vUv;", + + "void main() {", - "vUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;", + "vUv = uv - ( ( KERNEL_SIZE - 1.0 ) / 2.0 ) * uImageIncrement;", "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}" @@ -436,22 +437,26 @@ THREE.ShaderUtils = { fragmentShader: [ - "varying vec2 vUv;", + //"#define KERNEL_SIZE 25", + "uniform float cKernel[ KERNEL_SIZE ];", "uniform sampler2D tDiffuse;", "uniform vec2 uImageIncrement;", - //"#define KERNEL_SIZE 25", - "uniform float cKernel[KERNEL_SIZE];", + "varying vec2 vUv;", - "void main(void) {", + "void main() {", "vec2 imageCoord = vUv;", "vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );", - "for( int i=0; i