123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873 |
- /**
- * @author alteredq / http://alteredqualia.com/
- * @author MPanknin / http://www.redplant.de/
- * @author benaadams / http://blog.illyriad.co.uk/
- *
- */
- THREE.DeferredShaderChunk = {
- // decode float to vec3
- unpackFloat: [
- "vec3 float_to_vec3( float data ) {",
- "vec3 uncompressed;",
- "uncompressed.x = fract( data );",
- "float zInt = floor( data / 255.0 );",
- "uncompressed.z = fract( zInt / 255.0 );",
- "uncompressed.y = fract( floor( data - ( zInt * 255.0 ) ) / 255.0 );",
- "return uncompressed;",
- "}"
- ].join("\n"),
- computeVertexPositionVS: [
- "vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
- "vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
- "float z = normalDepth.w;",
- "if ( z == 0.0 ) discard;",
- "vec2 xy = texCoord * 2.0 - 1.0;",
- "vec4 vertexPositionProjected = vec4( xy, z, 1.0 );",
- "vec4 vertexPositionVS = matProjInverse * vertexPositionProjected;",
- "vertexPositionVS.xyz /= vertexPositionVS.w;",
- "vertexPositionVS.w = 1.0;"
- ].join("\n"),
- computeNormal: [
- "vec3 normal = normalDepth.xyz * 2.0 - 1.0;"
- ].join("\n"),
- unpackColorMap: [
- "vec4 colorMap = texture2D( samplerColor, texCoord );",
- "vec3 albedo = float_to_vec3( abs( colorMap.x ) );",
- "vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
- "float shininess = abs( colorMap.z );",
- "float wrapAround = sign( colorMap.z );",
- "float additiveSpecular = sign( colorMap.y );"
- ].join("\n"),
- computeDiffuse: [
- "float dotProduct = dot( normal, lightVector );",
- "float diffuseFull = max( dotProduct, 0.0 );",
- "vec3 diffuse;",
- "if ( wrapAround < 0.0 ) {",
- // wrap around lighting
- "float diffuseHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
- "const vec3 wrapRGB = vec3( 1.0, 1.0, 1.0 );",
- "diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
- "} else {",
- // simple lighting
- "diffuse = vec3( diffuseFull );",
- "}"
- ].join("\n"),
- computeSpecular: [
- "vec3 halfVector = normalize( lightVector - normalize( vertexPositionVS.xyz ) );",
- "float dotNormalHalf = max( dot( normal, halfVector ), 0.0 );",
- // simple specular
- //"vec3 specular = specularColor * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse;",
- // physically based specular
- "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
- "vec3 schlick = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightVector, halfVector ), 5.0 );",
- "vec3 specular = schlick * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse * specularNormalization;"
- ].join("\n"),
- combine: [
- "vec3 light = lightIntensity * lightColor;",
- "gl_FragColor = vec4( light * ( albedo * diffuse + specular ), attenuation );"
- ].join("\n")
- };
- THREE.ShaderDeferred = {
- "color" : {
- uniforms: THREE.UniformsUtils.merge( [
- THREE.UniformsLib[ "common" ],
- THREE.UniformsLib[ "fog" ],
- THREE.UniformsLib[ "shadowmap" ],
- {
- "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 },
- "samplerNormalDepth": { type: "t", value: null },
- "viewWidth": { type: "f", value: 800 },
- "viewHeight": { type: "f", value: 600 }
- }
- ] ),
- fragmentShader : [
- "uniform vec3 diffuse;",
- "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" ],
- THREE.ShaderChunk[ "lightmap_pars_fragment" ],
- "#ifdef USE_ENVMAP",
- "varying vec3 vWorldPosition;",
- "uniform float reflectivity;",
- "uniform samplerCube envMap;",
- "uniform float flipEnvMap;",
- "uniform int combine;",
- "uniform bool useRefract;",
- "uniform float refractionRatio;",
- "uniform sampler2D samplerNormalDepth;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- "#endif",
- THREE.ShaderChunk[ "fog_pars_fragment" ],
- THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
- THREE.ShaderChunk[ "specularmap_pars_fragment" ],
- "const float unit = 255.0/256.0;",
- "float vec3_to_float( vec3 data ) {",
- "highp float compressed = fract( data.x * unit ) + floor( data.y * unit * 255.0 ) + floor( data.z * unit * 255.0 ) * 255.0;",
- "return compressed;",
- "}",
- "void main() {",
- "const float opacity = 1.0;",
- "gl_FragColor = vec4( diffuse, opacity );",
- THREE.ShaderChunk[ "map_fragment" ],
- THREE.ShaderChunk[ "alphatest_fragment" ],
- THREE.ShaderChunk[ "specularmap_fragment" ],
- THREE.ShaderChunk[ "lightmap_fragment" ],
- THREE.ShaderChunk[ "color_fragment" ],
- "#ifdef USE_ENVMAP",
- "vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
- "vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
- "vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
- "vec3 reflectVec;",
- "vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
- "if ( useRefract ) {",
- "reflectVec = refract( cameraToVertex, normal, refractionRatio );",
- "} else { ",
- "reflectVec = reflect( cameraToVertex, normal );",
- "}",
- "#ifdef DOUBLE_SIDED",
- "float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
- "vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
- "#else",
- "vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
- "#endif",
- "#ifdef GAMMA_INPUT",
- "cubeColor.xyz *= cubeColor.xyz;",
- "#endif",
- "if ( combine == 1 ) {",
- "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );",
- "} else if ( combine == 2 ) {",
- "gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;",
- "} else {",
- "gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
- "}",
- "#endif",
- THREE.ShaderChunk[ "shadowmap_fragment" ],
- THREE.ShaderChunk[ "fog_fragment" ],
- //
- "const float compressionScale = 0.999;",
- //
- "vec3 diffuseMapColor;",
- "#ifdef USE_MAP",
- "diffuseMapColor = texelColor.xyz;",
- "#else",
- "diffuseMapColor = vec3( 1.0 );",
- "#endif",
- // diffuse color
- "gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
- // specular color
- "if ( additiveSpecular < 0.0 ) {",
- "gl_FragColor.y = vec3_to_float( compressionScale * specular );",
- "} else {",
- "gl_FragColor.y = vec3_to_float( compressionScale * specular * diffuseMapColor );",
- "}",
- "gl_FragColor.y *= additiveSpecular;",
- // shininess
- "gl_FragColor.z = wrapAround * shininess;",
- // emissive color
- "gl_FragColor.w = vec3_to_float( compressionScale * emissive * diffuseMapColor );",
- "}"
- ].join("\n"),
- vertexShader : [
- THREE.ShaderChunk[ "map_pars_vertex" ],
- THREE.ShaderChunk[ "lightmap_pars_vertex" ],
- THREE.ShaderChunk[ "color_pars_vertex" ],
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
- "#ifdef USE_ENVMAP",
- "varying vec3 vWorldPosition;",
- "#endif",
- "void main() {",
- THREE.ShaderChunk[ "map_vertex" ],
- THREE.ShaderChunk[ "lightmap_vertex" ],
- THREE.ShaderChunk[ "color_vertex" ],
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "default_vertex" ],
- THREE.ShaderChunk[ "worldpos_vertex" ],
- THREE.ShaderChunk[ "shadowmap_vertex" ],
- "#ifdef USE_ENVMAP",
- "vWorldPosition = worldPosition.xyz;",
- "#endif",
- "}"
- ].join("\n")
- },
- "normalDepth" : {
- uniforms: {
- bumpMap: { type: "t", value: null },
- bumpScale: { type: "f", value: 1 },
- offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
- },
- fragmentShader : [
- "#ifdef USE_BUMPMAP",
- "#extension GL_OES_standard_derivatives : enable\n",
- "varying vec2 vUv;",
- "varying vec3 vViewPosition;",
- THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
- "#endif",
- "varying vec3 normalView;",
- "varying vec4 clipPos;",
- "void main() {",
- "vec3 normal = normalize( normalView );",
- "#ifdef USE_BUMPMAP",
- "normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
- "#endif",
- "gl_FragColor.xyz = normal * 0.5 + 0.5;",
- "gl_FragColor.w = clipPos.z / clipPos.w;",
- "}"
- ].join("\n"),
- vertexShader : [
- "varying vec3 normalView;",
- "varying vec4 clipPos;",
- "#ifdef USE_BUMPMAP",
- "varying vec2 vUv;",
- "varying vec3 vViewPosition;",
- "uniform vec4 offsetRepeat;",
- "#endif",
- THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
- THREE.ShaderChunk[ "skinning_pars_vertex" ],
- "void main() {",
- THREE.ShaderChunk[ "morphnormal_vertex" ],
- THREE.ShaderChunk[ "skinbase_vertex" ],
- THREE.ShaderChunk[ "skinnormal_vertex" ],
- THREE.ShaderChunk[ "defaultnormal_vertex" ],
- THREE.ShaderChunk[ "morphtarget_vertex" ],
- THREE.ShaderChunk[ "skinning_vertex" ],
- THREE.ShaderChunk[ "default_vertex" ],
- "normalView = normalize( normalMatrix * objectNormal );",
- "#ifdef USE_BUMPMAP",
- "vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
- "vViewPosition = -mvPosition.xyz;",
- "#endif",
- "clipPos = gl_Position;",
- "}"
- ].join("\n")
- },
- "composite" : {
- uniforms: {
- samplerLight: { type: "t", value: null },
- brightness: { type: "f", value: 1 }
- },
- fragmentShader : [
- "varying vec2 texCoord;",
- "uniform sampler2D samplerLight;",
- "uniform float brightness;",
- "void main() {",
- "vec3 color = texture2D( samplerLight, texCoord ).xyz;",
- "gl_FragColor = vec4( brightness * sqrt( color ), 1.0 );",
- "}"
- ].join("\n"),
- vertexShader : [
- "varying vec2 texCoord;",
- "void main() {",
- "vec4 pos = vec4( sign( position.xy ), 0.0, 1.0 );",
- "texCoord = pos.xy * vec2( 0.5 ) + 0.5;",
- "gl_Position = pos;",
- "}"
- ].join("\n")
- },
- "pointLight" : {
- uniforms: {
- samplerNormalDepth: { type: "t", value: null },
- samplerColor: { type: "t", value: null },
- matProjInverse: { type: "m4", value: new THREE.Matrix4() },
- viewWidth: { type: "f", value: 800 },
- viewHeight: { type: "f", value: 600 },
- lightPositionVS:{ type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
- lightColor: { type: "c", value: new THREE.Color( 0x000000 ) },
- lightIntensity: { type: "f", value: 1.0 },
- lightRadius: { type: "f", value: 1.0 }
- },
- fragmentShader : [
- "uniform sampler2D samplerColor;",
- "uniform sampler2D samplerNormalDepth;",
- "uniform float lightRadius;",
- "uniform float lightIntensity;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- "uniform vec3 lightColor;",
- "uniform vec3 lightPositionVS;",
- "uniform mat4 matProjInverse;",
- THREE.DeferredShaderChunk[ "unpackFloat" ],
- "void main() {",
- THREE.DeferredShaderChunk[ "computeVertexPositionVS" ],
- // bail out early when pixel outside of light sphere
- "vec3 lightVector = lightPositionVS - vertexPositionVS.xyz;",
- "float distance = length( lightVector );",
- "if ( distance > lightRadius ) discard;",
- THREE.DeferredShaderChunk[ "computeNormal" ],
- THREE.DeferredShaderChunk[ "unpackColorMap" ],
- // compute light
- "lightVector = normalize( lightVector );",
- THREE.DeferredShaderChunk[ "computeDiffuse" ],
- THREE.DeferredShaderChunk[ "computeSpecular" ],
- // combine
- "float cutoff = 0.3;",
- "float denom = distance / lightRadius + 1.0;",
- "float attenuation = 1.0 / ( denom * denom );",
- "attenuation = ( attenuation - cutoff ) / ( 1.0 - cutoff );",
- "attenuation = max( attenuation, 0.0 );",
- "attenuation *= attenuation;",
- THREE.DeferredShaderChunk[ "combine" ],
- "}"
- ].join("\n"),
- vertexShader : [
- "void main() { ",
- // sphere proxy needs real position
- "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
- "gl_Position = projectionMatrix * mvPosition;",
- "}"
- ].join("\n")
- },
- "spotLight" : {
- uniforms: {
- samplerNormalDepth: { type: "t", value: null },
- samplerColor: { type: "t", value: null },
- matProjInverse: { type: "m4", value: new THREE.Matrix4() },
- viewWidth: { type: "f", value: 800 },
- viewHeight: { type: "f", value: 600 },
- lightPositionVS :{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
- lightDirectionVS:{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
- lightColor: { type: "c", value: new THREE.Color( 0x000000 ) },
- lightIntensity: { type: "f", value: 1.0 },
- lightDistance: { type: "f", value: 1.0 },
- lightAngle: { type: "f", value: 1.0 }
- },
- fragmentShader : [
- "uniform vec3 lightPositionVS;",
- "uniform vec3 lightDirectionVS;",
- "uniform sampler2D samplerColor;",
- "uniform sampler2D samplerNormalDepth;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- "uniform float lightAngle;"+
- "uniform float lightIntensity;"+
- "uniform vec3 lightColor;",
- "uniform mat4 matProjInverse;",
- THREE.DeferredShaderChunk[ "unpackFloat" ],
- "void main() {",
- THREE.DeferredShaderChunk[ "computeVertexPositionVS" ],
- THREE.DeferredShaderChunk[ "computeNormal" ],
- THREE.DeferredShaderChunk[ "unpackColorMap" ],
- // compute light
- "vec3 lightVector = normalize( lightPositionVS.xyz - vertexPositionVS.xyz );",
- "float rho = dot( lightDirectionVS, lightVector );",
- "float rhoMax = cos( lightAngle * 0.5 );",
- "if ( rho <= rhoMax ) discard;",
- "float theta = rhoMax + 0.0001;",
- "float phi = rhoMax + 0.05;",
- "float falloff = 4.0;",
- "float spot = 0.0;",
- "if ( rho >= phi ) {",
- "spot = 1.0;",
- "} else if ( rho <= theta ) {",
- "spot = 0.0;",
- "} else { ",
- "spot = pow( ( rho - theta ) / ( phi - theta ), falloff );",
- "}",
- THREE.DeferredShaderChunk[ "computeDiffuse" ],
- "diffuse *= spot;",
- THREE.DeferredShaderChunk[ "computeSpecular" ],
- // combine
- "const float attenuation = 1.0;",
- THREE.DeferredShaderChunk[ "combine" ],
- "}"
- ].join("\n"),
- vertexShader : [
- "void main() { ",
- // full screen quad proxy
- "gl_Position = vec4( sign( position.xy ), 0.0, 1.0 );",
- "}"
- ].join("\n")
- },
- "directionalLight" : {
- uniforms: {
- samplerNormalDepth: { type: "t", value: null },
- samplerColor: { type: "t", value: null },
- matProjInverse: { type: "m4", value: new THREE.Matrix4() },
- viewWidth: { type: "f", value: 800 },
- viewHeight: { type: "f", value: 600 },
- lightDirectionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
- lightColor: { type: "c", value: new THREE.Color( 0x000000 ) },
- lightIntensity: { type: "f", value: 1.0 }
- },
- fragmentShader : [
- "uniform sampler2D samplerColor;",
- "uniform sampler2D samplerNormalDepth;",
- "uniform float lightRadius;",
- "uniform float lightIntensity;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- "uniform vec3 lightColor;",
- "uniform vec3 lightDirectionVS;",
- "uniform mat4 matProjInverse;",
- THREE.DeferredShaderChunk[ "unpackFloat" ],
- "void main() {",
- THREE.DeferredShaderChunk[ "computeVertexPositionVS" ],
- THREE.DeferredShaderChunk[ "computeNormal" ],
- THREE.DeferredShaderChunk[ "unpackColorMap" ],
- // compute light
- "vec3 lightVector = lightDirectionVS;",
- THREE.DeferredShaderChunk[ "computeDiffuse" ],
- THREE.DeferredShaderChunk[ "computeSpecular" ],
- // combine
- "const float attenuation = 1.0;",
- THREE.DeferredShaderChunk[ "combine" ],
- "}"
- ].join("\n"),
- vertexShader : [
- "void main() { ",
- // full screen quad proxy
- "gl_Position = vec4( sign( position.xy ), 0.0, 1.0 );",
- "}"
- ].join("\n")
- },
- "hemisphereLight" : {
- uniforms: {
- samplerNormalDepth: { type: "t", value: null },
- samplerColor: { type: "t", value: null },
- matProjInverse: { type: "m4", value: new THREE.Matrix4() },
- viewWidth: { type: "f", value: 800 },
- viewHeight: { type: "f", value: 600 },
- lightDirectionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
- lightColorSky: { type: "c", value: new THREE.Color( 0x000000 ) },
- lightColorGround: { type: "c", value: new THREE.Color( 0x000000 ) },
- lightIntensity: { type: "f", value: 1.0 }
- },
- fragmentShader : [
- "uniform sampler2D samplerColor;",
- "uniform sampler2D samplerNormalDepth;",
- "uniform float lightRadius;",
- "uniform float lightIntensity;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- "uniform vec3 lightColorSky;",
- "uniform vec3 lightColorGround;",
- "uniform vec3 lightDirectionVS;",
- "uniform mat4 matProjInverse;",
- THREE.DeferredShaderChunk[ "unpackFloat" ],
- "void main() {",
- THREE.DeferredShaderChunk[ "computeVertexPositionVS" ],
- THREE.DeferredShaderChunk[ "computeNormal" ],
- THREE.DeferredShaderChunk[ "unpackColorMap" ],
- // compute light
- "vec3 lightVector = lightDirectionVS;",
- // diffuse
- "float dotProduct = dot( normal, lightVector );",
- "float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
- "vec3 hemiColor = mix( lightColorGround, lightColorSky, hemiDiffuseWeight );",
- "vec3 diffuse = hemiColor;",
- // specular (sky light)
- "vec3 hemiHalfVectorSky = normalize( lightVector - vertexPositionVS.xyz );",
- "float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
- "float hemiSpecularWeightSky = max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
- // specular (ground light)
- "vec3 lVectorGround = -lightVector;",
- "vec3 hemiHalfVectorGround = normalize( lVectorGround - vertexPositionVS.xyz );",
- "float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
- "float hemiSpecularWeightGround = max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
- "float dotProductGround = dot( normal, lVectorGround );",
- "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
- "vec3 schlickSky = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightVector, hemiHalfVectorSky ), 5.0 );",
- "vec3 schlickGround = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
- "vec3 specular = hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
- // combine
- "gl_FragColor = vec4( lightIntensity * ( albedo * diffuse + specular ), 1.0 );",
- "}"
- ].join("\n"),
- vertexShader : [
- "void main() { ",
- // full screen quad proxy
- "gl_Position = vec4( sign( position.xy ), 0.0, 1.0 );",
- "}"
- ].join("\n")
- },
- "emissiveLight" : {
- uniforms: {
- samplerColor: { type: "t", value: null },
- viewWidth: { type: "f", value: 800 },
- viewHeight: { type: "f", value: 600 },
- },
- fragmentShader : [
- "uniform sampler2D samplerColor;",
- "uniform float viewHeight;",
- "uniform float viewWidth;",
- THREE.DeferredShaderChunk[ "unpackFloat" ],
- "void main() {",
- "vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
- "vec4 colorMap = texture2D( samplerColor, texCoord );",
- "vec3 emissiveColor = float_to_vec3( abs( colorMap.w ) );",
- "gl_FragColor = vec4( emissiveColor, 1.0 );",
- "}"
- ].join("\n"),
- vertexShader : [
- "void main() { ",
- // full screen quad proxy
- "gl_Position = vec4( sign( position.xy ), 0.0, 1.0 );",
- "}"
- ].join("\n")
- }
- };
|