|
@@ -135,7 +135,8 @@ THREE.NormalDisplacementShader = {
|
|
|
"void main() {",
|
|
|
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
|
|
|
|
|
|
- " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
|
|
|
+ " vec3 outgoingLight = vec3( 0.0, 0.0, 0.0 );", // outgoing light does not have an alpha, the surface does
|
|
|
+ " vec4 diffuseColor = vec4( diffuse, opacity );",
|
|
|
|
|
|
" vec3 specularTex = vec3( 1.0 );",
|
|
|
|
|
@@ -150,11 +151,11 @@ THREE.NormalDisplacementShader = {
|
|
|
" vec4 texelColor = texture2D( tDiffuse, vUv );",
|
|
|
" texelColor.xyz *= texelColor.xyz;",
|
|
|
|
|
|
- " gl_FragColor = gl_FragColor * texelColor;",
|
|
|
+ " diffuseColor *= texelColor;",
|
|
|
|
|
|
" #else",
|
|
|
|
|
|
- " gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
|
|
|
+ " diffuseColor *= texture2D( tDiffuse, vUv );",
|
|
|
|
|
|
" #endif",
|
|
|
|
|
@@ -167,11 +168,11 @@ THREE.NormalDisplacementShader = {
|
|
|
" vec4 aoColor = texture2D( tAO, vUv );",
|
|
|
" aoColor.xyz *= aoColor.xyz;",
|
|
|
|
|
|
- " gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
|
|
|
+ " diffuseColor.rgb *= aoColor.xyz;",
|
|
|
|
|
|
" #else",
|
|
|
|
|
|
- " gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
|
|
|
+ " diffuseColor.rgb *= texture2D( tAO, vUv ).xyz;",
|
|
|
|
|
|
" #endif",
|
|
|
|
|
@@ -194,13 +195,13 @@ THREE.NormalDisplacementShader = {
|
|
|
" vec3 normal = normalize( finalNormal );",
|
|
|
" vec3 viewPosition = normalize( vViewPosition );",
|
|
|
|
|
|
+ " vec3 totalDiffuseLight = vec3( 0.0 );",
|
|
|
+ " vec3 totalSpecularLight = vec3( 0.0 );",
|
|
|
+
|
|
|
// point lights
|
|
|
|
|
|
" #if MAX_POINT_LIGHTS > 0",
|
|
|
|
|
|
- " vec3 pointDiffuse = vec3( 0.0 );",
|
|
|
- " vec3 pointSpecular = vec3( 0.0 );",
|
|
|
-
|
|
|
" for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
|
|
|
|
|
|
" vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
|
|
@@ -227,7 +228,7 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #endif",
|
|
|
|
|
|
- " pointDiffuse += pointDistance * pointLightColor[ i ] * diffuse * pointDiffuseWeight;",
|
|
|
+ " totalDiffuseLight += pointDistance * pointLightColor[ i ] * pointDiffuseWeight;",
|
|
|
|
|
|
// specular
|
|
|
|
|
@@ -238,7 +239,7 @@ THREE.NormalDisplacementShader = {
|
|
|
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
|
|
|
|
|
|
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( pointVector, pointHalfVector ), 0.0 ), 5.0 );",
|
|
|
- " pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
|
|
|
+ " totalSpecularLight += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
|
|
|
|
|
|
" }",
|
|
|
|
|
@@ -248,9 +249,6 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #if MAX_SPOT_LIGHTS > 0",
|
|
|
|
|
|
- " vec3 spotDiffuse = vec3( 0.0 );",
|
|
|
- " vec3 spotSpecular = vec3( 0.0 );",
|
|
|
-
|
|
|
" for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
|
|
|
|
|
|
" vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
|
|
@@ -283,7 +281,7 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #endif",
|
|
|
|
|
|
- " spotDiffuse += spotDistance * spotLightColor[ i ] * diffuse * spotDiffuseWeight * spotEffect;",
|
|
|
+ " totalDiffuseLight += spotDistance * spotLightColor[ i ] * spotDiffuseWeight * spotEffect;",
|
|
|
|
|
|
// specular
|
|
|
|
|
@@ -294,7 +292,7 @@ THREE.NormalDisplacementShader = {
|
|
|
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
|
|
|
|
|
|
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( spotVector, spotHalfVector ), 0.0 ), 5.0 );",
|
|
|
- " spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
|
|
|
+ " totalSpecularLight += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
|
|
|
|
|
|
" }",
|
|
|
|
|
@@ -306,9 +304,6 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #if MAX_DIR_LIGHTS > 0",
|
|
|
|
|
|
- " vec3 dirDiffuse = vec3( 0.0 );",
|
|
|
- " vec3 dirSpecular = vec3( 0.0 );",
|
|
|
-
|
|
|
" for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
|
|
|
|
|
|
" vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
|
|
@@ -329,7 +324,7 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #endif",
|
|
|
|
|
|
- " dirDiffuse += directionalLightColor[ i ] * diffuse * dirDiffuseWeight;",
|
|
|
+ " totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;",
|
|
|
|
|
|
// specular
|
|
|
|
|
@@ -340,7 +335,7 @@ THREE.NormalDisplacementShader = {
|
|
|
" float specularNormalization = ( shininess + 2.0 ) / 8.0;",
|
|
|
|
|
|
" vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );",
|
|
|
- " dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
|
|
|
+ " totalSpecularLight += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
|
|
|
|
|
|
" }",
|
|
|
|
|
@@ -350,9 +345,6 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #if MAX_HEMI_LIGHTS > 0",
|
|
|
|
|
|
- " vec3 hemiDiffuse = vec3( 0.0 );",
|
|
|
- " vec3 hemiSpecular = vec3( 0.0 );" ,
|
|
|
-
|
|
|
" for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
|
|
|
|
|
|
" vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
|
|
@@ -365,7 +357,7 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
|
|
|
|
|
|
- " hemiDiffuse += diffuse * hemiColor;",
|
|
|
+ " totalDiffuseLight += hemiColor;",
|
|
|
|
|
|
// specular (sky light)
|
|
|
|
|
@@ -388,52 +380,19 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );",
|
|
|
" vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );",
|
|
|
- " hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
|
|
|
+ " totalSpecularLight += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
|
|
|
|
|
|
" }",
|
|
|
|
|
|
- " #endif",
|
|
|
-
|
|
|
- // all lights contribution summation
|
|
|
-
|
|
|
- " vec3 totalDiffuse = vec3( 0.0 );",
|
|
|
- " vec3 totalSpecular = vec3( 0.0 );",
|
|
|
-
|
|
|
- " #if MAX_DIR_LIGHTS > 0",
|
|
|
-
|
|
|
- " totalDiffuse += dirDiffuse;",
|
|
|
- " totalSpecular += dirSpecular;",
|
|
|
-
|
|
|
- " #endif",
|
|
|
-
|
|
|
- " #if MAX_HEMI_LIGHTS > 0",
|
|
|
-
|
|
|
- " totalDiffuse += hemiDiffuse;",
|
|
|
- " totalSpecular += hemiSpecular;",
|
|
|
-
|
|
|
- " #endif",
|
|
|
-
|
|
|
- " #if MAX_POINT_LIGHTS > 0",
|
|
|
-
|
|
|
- " totalDiffuse += pointDiffuse;",
|
|
|
- " totalSpecular += pointSpecular;",
|
|
|
-
|
|
|
- " #endif",
|
|
|
-
|
|
|
- " #if MAX_SPOT_LIGHTS > 0",
|
|
|
-
|
|
|
- " totalDiffuse += spotDiffuse;",
|
|
|
- " totalSpecular += spotSpecular;",
|
|
|
-
|
|
|
" #endif",
|
|
|
|
|
|
" #ifdef METAL",
|
|
|
|
|
|
- " gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );",
|
|
|
+ " outgoingLight.xyz += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor * ambient + totalSpecularLight );",
|
|
|
|
|
|
" #else",
|
|
|
|
|
|
- " gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
|
|
|
+ " outgoingLight.xyz += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor * ambient ) + totalSpecularLight;",
|
|
|
|
|
|
" #endif",
|
|
|
|
|
@@ -459,7 +418,7 @@ THREE.NormalDisplacementShader = {
|
|
|
|
|
|
" #endif",
|
|
|
|
|
|
- " gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * reflectivity );",
|
|
|
+ " outgoingLight.xyz = mix( outgoingLight.xyz, cubeColor.xyz, specularTex.r * reflectivity );",
|
|
|
|
|
|
" }",
|
|
|
|
|
@@ -467,6 +426,9 @@ THREE.NormalDisplacementShader = {
|
|
|
THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
|
|
|
THREE.ShaderChunk[ "fog_fragment" ],
|
|
|
|
|
|
+ " gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
|
|
|
+
|
|
|
+
|
|
|
"}"
|
|
|
|
|
|
].join("\n"),
|