|
@@ -1,34 +1,33 @@
|
|
vec3 viewDir = normalize( vViewPosition );
|
|
vec3 viewDir = normalize( vViewPosition );
|
|
|
|
|
|
-vec3 totalDiffuseLight = vec3( 0.0 );
|
|
|
|
-vec3 totalSpecularLight = vec3( 0.0 );
|
|
|
|
|
|
+vec3 totalReflectedLight = vec3( 0.0 );
|
|
|
|
|
|
-#if MAX_POINT_LIGHTS > 0
|
|
|
|
-
|
|
|
|
- for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
|
|
|
|
-
|
|
|
|
- vec3 lightColor = pointLightColor[ i ];
|
|
|
|
-
|
|
|
|
- vec3 lightPosition = pointLightPosition[ i ];
|
|
|
|
- vec3 lVector = lightPosition + vViewPosition.xyz;
|
|
|
|
- vec3 lightDir = normalize( lVector );
|
|
|
|
|
|
+#ifdef METAL
|
|
|
|
|
|
- // attenuation
|
|
|
|
|
|
+ diffuseColor.rgb = diffuseColor.rgb * specular;
|
|
|
|
|
|
- float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
- // diffuse
|
|
|
|
|
|
+#if MAX_POINT_LIGHTS > 0
|
|
|
|
|
|
- float cosineTerm = saturate( dot( normal, lightDir ) );
|
|
|
|
|
|
+ for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
|
|
|
|
|
|
- totalDiffuseLight += lightColor * attenuation * cosineTerm;
|
|
|
|
|
|
+ vec3 lightDir, lightIntensity;
|
|
|
|
+ getSpotLight( i, lightDir, lightIntensity );
|
|
|
|
|
|
- // specular
|
|
|
|
|
|
+ if( dot( lightIntensity, lightIntensity ) > 0.0 ) {
|
|
|
|
|
|
- vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );
|
|
|
|
|
|
+ vec3 halfDir = normalize( lightDir + viewDir );
|
|
|
|
+ float dotNL = saturate( dot( normal, lightDir ) );
|
|
|
|
+ float dotNH = saturate( dot( normal, halfDir ) );
|
|
|
|
+ float dotLH = saturate( dot( lightDir, halfDir ) );
|
|
|
|
|
|
- totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;
|
|
|
|
|
|
+ totalReflectedLight += (
|
|
|
|
+ BRDF_Lambert( diffuseColor.rgb, dotNL ) +
|
|
|
|
+ BRDF_BlinnPhong( specular, shininess, dotNH, dotLH )
|
|
|
|
+ ) * lightIntensity;
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -38,35 +37,20 @@ vec3 totalSpecularLight = vec3( 0.0 );
|
|
|
|
|
|
for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
|
|
for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
|
|
|
|
|
|
- vec3 lightColor = spotLightColor[ i ];
|
|
|
|
-
|
|
|
|
- vec3 lightPosition = spotLightPosition[ i ];
|
|
|
|
- vec3 lVector = lightPosition + vViewPosition.xyz;
|
|
|
|
- vec3 lightDir = normalize( lVector );
|
|
|
|
-
|
|
|
|
- float spotEffect = dot( spotLightDirection[ i ], lightDir );
|
|
|
|
-
|
|
|
|
- if ( spotEffect > spotLightAngleCos[ i ] ) {
|
|
|
|
-
|
|
|
|
- spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );
|
|
|
|
-
|
|
|
|
- // attenuation
|
|
|
|
|
|
+ vec3 lightDir, lightIntensity;
|
|
|
|
+ getSpotLight( i, lightDir, lightIntensity );
|
|
|
|
|
|
- float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );
|
|
|
|
|
|
+ if( dot( lightIntensity, lightIntensity ) > 0.0 ) {
|
|
|
|
|
|
- attenuation *= spotEffect;
|
|
|
|
|
|
+ vec3 halfDir = normalize( lightDir + viewDir );
|
|
|
|
+ float dotNL = saturate( dot( normal, lightDir ) );
|
|
|
|
+ float dotNH = saturate( dot( normal, halfDir ) );
|
|
|
|
+ float dotLH = saturate( dot( lightDir, halfDir ) );
|
|
|
|
|
|
- // diffuse
|
|
|
|
-
|
|
|
|
- float cosineTerm = saturate( dot( normal, lightDir ) );
|
|
|
|
-
|
|
|
|
- totalDiffuseLight += lightColor * attenuation * cosineTerm;
|
|
|
|
-
|
|
|
|
- // specular
|
|
|
|
-
|
|
|
|
- vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );
|
|
|
|
-
|
|
|
|
- totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;
|
|
|
|
|
|
+ totalReflectedLight += (
|
|
|
|
+ BRDF_Lambert( diffuseColor.rgb, dotNL ) +
|
|
|
|
+ BRDF_BlinnPhong( specular, shininess, dotNH, dotLH )
|
|
|
|
+ ) * lightIntensity;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,32 +62,25 @@ vec3 totalSpecularLight = vec3( 0.0 );
|
|
|
|
|
|
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
|
|
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
|
|
|
|
|
|
- vec3 lightColor = directionalLightColor[ i ];
|
|
|
|
-
|
|
|
|
- vec3 lightDir = directionalLightDirection[ i ];
|
|
|
|
-
|
|
|
|
- // diffuse
|
|
|
|
-
|
|
|
|
- float cosineTerm = saturate( dot( normal, lightDir ) );
|
|
|
|
|
|
+ vec3 lightDir, lightIntensity;
|
|
|
|
+ getDirLight( i, lightDir, lightIntensity );
|
|
|
|
|
|
- totalDiffuseLight += lightColor * cosineTerm;
|
|
|
|
|
|
+ if( dot( lightIntensity, lightIntensity ) > 0.0 ) {
|
|
|
|
|
|
- // specular
|
|
|
|
|
|
+ vec3 halfDir = normalize( lightDir + viewDir );
|
|
|
|
+ float dotNL = saturate( dot( normal, lightDir ) );
|
|
|
|
+ float dotNH = saturate( dot( normal, halfDir ) );
|
|
|
|
+ float dotLH = saturate( dot( lightDir, halfDir ) );
|
|
|
|
|
|
- vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );
|
|
|
|
|
|
+ totalReflectedLight += (
|
|
|
|
+ BRDF_Lambert( diffuseColor.rgb, dotNL ) +
|
|
|
|
+ BRDF_BlinnPhong( specular, shininess, dotNH, dotLH )
|
|
|
|
+ ) * lightIntensity;
|
|
|
|
|
|
- totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-#ifdef METAL
|
|
|
|
-
|
|
|
|
- outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;
|
|
|
|
-
|
|
|
|
-#else
|
|
|
|
-
|
|
|
|
- outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;
|
|
|
|
-
|
|
|
|
-#endif
|
|
|
|
|
|
+outgoingLight += totalReflectedLight + totalEmissiveLight;
|