|
@@ -392,7 +392,7 @@ struct lightingInfo
|
|
|
#endif
|
|
|
};
|
|
|
|
|
|
-lightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range) {
|
|
|
+lightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {
|
|
|
lightingInfo result;
|
|
|
|
|
|
vec3 lightVectorW;
|
|
@@ -417,14 +417,14 @@ lightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData,
|
|
|
// Specular
|
|
|
vec3 angleW = normalize(viewDirectionW + lightVectorW);
|
|
|
float specComp = max(0., dot(vNormal, angleW));
|
|
|
- specComp = pow(specComp, max(1., vSpecularColor.a));
|
|
|
+ specComp = pow(specComp, max(1., glossiness));
|
|
|
|
|
|
result.specular = specComp * specularColor * attenuation;
|
|
|
#endif
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range) {
|
|
|
+lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {
|
|
|
lightingInfo result;
|
|
|
|
|
|
vec3 direction = lightData.xyz - vPositionW;
|
|
@@ -448,7 +448,7 @@ lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightDa
|
|
|
// Specular
|
|
|
vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);
|
|
|
float specComp = max(0., dot(vNormal, angleW));
|
|
|
- specComp = pow(specComp, vSpecularColor.a);
|
|
|
+ specComp = pow(specComp, glossiness);
|
|
|
|
|
|
result.specular = specComp * specularColor * spotAtten * attenuation;
|
|
|
#endif
|
|
@@ -464,7 +464,7 @@ lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightDa
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {
|
|
|
+lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor, float glossiness) {
|
|
|
lightingInfo result;
|
|
|
|
|
|
// Diffuse
|
|
@@ -475,7 +475,7 @@ lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4
|
|
|
// Specular
|
|
|
vec3 angleW = normalize(viewDirectionW + lightData.xyz);
|
|
|
float specComp = max(0., dot(vNormal, angleW));
|
|
|
- specComp = pow(specComp, vSpecularColor.a);
|
|
|
+ specComp = pow(specComp, glossiness);
|
|
|
|
|
|
result.specular = specComp * specularColor;
|
|
|
#endif
|
|
@@ -530,7 +530,6 @@ void main(void) {
|
|
|
normalW = perturbNormal(viewDirectionW);
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
// Ambient color
|
|
|
vec3 baseAmbientColor = vec3(1., 1., 1.);
|
|
|
|
|
@@ -538,6 +537,21 @@ void main(void) {
|
|
|
baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
+ // Specular map
|
|
|
+ float glossiness = vSpecularColor.a;
|
|
|
+#ifdef SPECULARTERM
|
|
|
+ vec3 specularColor = vSpecularColor.rgb;
|
|
|
+
|
|
|
+ #ifdef SPECULAR
|
|
|
+ vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);
|
|
|
+ specularColor = specularMapColor.rgb;
|
|
|
+ #ifdef GLOSSINESS
|
|
|
+ glossiness = specularMapColor.a;
|
|
|
+ #endif
|
|
|
+ #endif
|
|
|
+#endif
|
|
|
+
|
|
|
// Lighting
|
|
|
vec3 diffuseBase = vec3(0., 0., 0.);
|
|
|
#ifdef SPECULARTERM
|
|
@@ -550,13 +564,13 @@ void main(void) {
|
|
|
vec3 vLightSpecular0 = vec3(0.0);
|
|
|
#endif
|
|
|
#ifdef SPOTLIGHT0
|
|
|
- lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);
|
|
|
+ lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef HEMILIGHT0
|
|
|
- lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0);
|
|
|
+ lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0, glossiness);
|
|
|
#endif
|
|
|
#ifdef POINTDIRLIGHT0
|
|
|
- lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);
|
|
|
+ lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef SHADOW0
|
|
|
#ifdef SHADOWVSM0
|
|
@@ -582,13 +596,13 @@ void main(void) {
|
|
|
vec3 vLightSpecular1 = vec3(0.0);
|
|
|
#endif
|
|
|
#ifdef SPOTLIGHT1
|
|
|
- info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);
|
|
|
+ info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef HEMILIGHT1
|
|
|
- info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1);
|
|
|
+ info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1, glossiness);
|
|
|
#endif
|
|
|
#ifdef POINTDIRLIGHT1
|
|
|
- info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);
|
|
|
+ info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef SHADOW1
|
|
|
#ifdef SHADOWVSM1
|
|
@@ -614,13 +628,13 @@ void main(void) {
|
|
|
vec3 vLightSpecular2 = vec3(0.0);
|
|
|
#endif
|
|
|
#ifdef SPOTLIGHT2
|
|
|
- info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);
|
|
|
+ info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef HEMILIGHT2
|
|
|
- info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2);
|
|
|
+ info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2, glossiness);
|
|
|
#endif
|
|
|
#ifdef POINTDIRLIGHT2
|
|
|
- info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);
|
|
|
+ info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef SHADOW2
|
|
|
#ifdef SHADOWVSM2
|
|
@@ -646,13 +660,13 @@ void main(void) {
|
|
|
vec3 vLightSpecular3 = vec3(0.0);
|
|
|
#endif
|
|
|
#ifdef SPOTLIGHT3
|
|
|
- info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);
|
|
|
+ info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef HEMILIGHT3
|
|
|
- info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3);
|
|
|
+ info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3, glossiness);
|
|
|
#endif
|
|
|
#ifdef POINTDIRLIGHT3
|
|
|
- info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);
|
|
|
+ info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);
|
|
|
#endif
|
|
|
#ifdef SHADOW3
|
|
|
#ifdef SHADOWVSM3
|
|
@@ -738,14 +752,6 @@ void main(void) {
|
|
|
emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;
|
|
|
#endif
|
|
|
|
|
|
- // Specular map
|
|
|
-#ifdef SPECULARTERM
|
|
|
- vec3 specularColor = vSpecularColor.rgb;
|
|
|
-#ifdef SPECULAR
|
|
|
- specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;
|
|
|
-#endif
|
|
|
-#endif
|
|
|
-
|
|
|
// Fresnel
|
|
|
#ifdef DIFFUSEFRESNEL
|
|
|
float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);
|