瀏覽代碼

Returned to Blinn-Phong equation for more pleasing specular highlights.

Lasse Öörni 14 年之前
父節點
當前提交
8f921642cd

+ 3 - 4
SourceAssets/GLSLShaders/Forward.frag

@@ -51,7 +51,6 @@ void main()
         vec3 lightColor;
         vec3 lightColor;
         vec3 lightDir;
         vec3 lightDir;
         float diff;
         float diff;
-        float NdotL;
 
 
         #ifdef NORMALMAP
         #ifdef NORMALMAP
             vec3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
             vec3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
@@ -65,9 +64,9 @@ void main()
             #else
             #else
                 lightDir = vLightVec.xyz;
                 lightDir = vLightVec.xyz;
             #endif
             #endif
-            diff = GetDiffuseDir(normal, lightDir, NdotL);
+            diff = GetDiffuseDir(normal, lightDir);
         #else
         #else
-            diff = GetDiffusePointOrSpot(normal, vLightVec.xyz, lightDir, NdotL);
+            diff = GetDiffusePointOrSpot(normal, vLightVec.xyz, lightDir);
         #endif
         #endif
 
 
         #ifdef SHADOW
         #ifdef SHADOW
@@ -103,7 +102,7 @@ void main()
             #else
             #else
                 float specStrength = cMatSpecProperties.x;
                 float specStrength = cMatSpecProperties.x;
             #endif
             #endif
-            float spec = GetSpecular(normal, vEyeVec, lightDir, NdotL, cMatSpecProperties.y);
+            float spec = GetSpecular(normal, vEyeVec, lightDir, cMatSpecProperties.y);
             vec3 finalColor = diff * lightColor * (diffColor.rgb + spec * specStrength * cLightColor.a);
             vec3 finalColor = diff * lightColor * (diffColor.rgb + spec * specStrength * cLightColor.a);
         #else
         #else
             vec3 finalColor = diff * lightColor * diffColor.rgb;
             vec3 finalColor = diff * lightColor * diffColor.rgb;

+ 6 - 8
SourceAssets/GLSLShaders/Lighting.frag

@@ -1,15 +1,13 @@
-float GetDiffuseDir(vec3 normal, vec3 lightDir, out float NdotL)
+float GetDiffuseDir(vec3 normal, vec3 lightDir)
 {
 {
-    NdotL = max(dot(normal, lightDir), 0.0);
-    return NdotL;
+    return max(dot(normal, lightDir), 0.0);
 }
 }
 
 
 float GetDiffusePointOrSpot(vec3 normal, vec3 lightVec, out vec3 lightDir, out float NdotL)
 float GetDiffusePointOrSpot(vec3 normal, vec3 lightVec, out vec3 lightDir, out float NdotL)
 {
 {
     float lightDist = length(lightVec);
     float lightDist = length(lightVec);
     lightDir = lightVec / lightDist;
     lightDir = lightVec / lightDist;
-    NdotL = max(dot(normal, lightDir), 0.0);
-    return NdotL * texture2D(sLightRampMap, vec2(lightDist, 0.0)).r;
+    return max(dot(normal, lightDir), 0.0) * texture2D(sLightRampMap, vec2(lightDist, 0.0)).r;
 }
 }
 
 
 float GetDiffuseDirVolumetric()
 float GetDiffuseDirVolumetric()
@@ -23,10 +21,10 @@ float GetDiffusePointOrSpotVolumetric(vec3 lightVec)
     return texture2D(sLightRampMap, vec2(lightDist, 0.0)).r;
     return texture2D(sLightRampMap, vec2(lightDist, 0.0)).r;
 }
 }
 
 
-float GetSpecular(vec3 normal, vec3 eyeVec, vec3 lightDir, float NdotL, float specularPower)
+float GetSpecular(vec3 normal, vec3 eyeVec, vec3 lightDir, float specularPower)
 {
 {
-    vec3 reflectDir = 2.0 * NdotL * normal - lightDir;
-    return pow(max(dot(reflectDir, normalize(eyeVec)), 0.0), specularPower);
+    vec3 halfVec = normalize(normalize(eyeVec) + lightDir);
+    return pow(dot(normal, halfVec), specularPower);
 }
 }
 
 
 float GetShadow(vec4 shadowPos)
 float GetShadow(vec4 shadowPos)

+ 3 - 4
SourceAssets/HLSLShaders/Forward.hlsl

@@ -180,7 +180,6 @@ void PS(float2 iTexCoord : TEXCOORD0,
         float3 lightColor;
         float3 lightColor;
         float3 lightDir;
         float3 lightDir;
         float diff;
         float diff;
-        float NdotL;
 
 
         #ifdef NORMALMAP
         #ifdef NORMALMAP
             float3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
             float3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
@@ -194,9 +193,9 @@ void PS(float2 iTexCoord : TEXCOORD0,
             #else
             #else
                 lightDir = iLightVec.xyz;
                 lightDir = iLightVec.xyz;
             #endif
             #endif
-            diff = GetDiffuseDir(normal, lightDir, NdotL);
+            diff = GetDiffuseDir(normal, lightDir);
         #else
         #else
-            diff = GetDiffusePointOrSpot(normal, iLightVec.xyz, lightDir, NdotL);
+            diff = GetDiffusePointOrSpot(normal, iLightVec.xyz, lightDir);
         #endif
         #endif
 
 
         #ifdef SHADOW
         #ifdef SHADOW
@@ -232,7 +231,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
             #else
             #else
                 float specStrength = cMatSpecProperties.x;
                 float specStrength = cMatSpecProperties.x;
             #endif
             #endif
-            float spec = GetSpecular(normal, iEyeVec, lightDir, NdotL, cMatSpecProperties.y);
+            float spec = GetSpecular(normal, iEyeVec, lightDir, cMatSpecProperties.y);
             float3 finalColor = diff * lightColor * (diffColor.rgb + spec * specStrength * cLightColor.a);
             float3 finalColor = diff * lightColor * (diffColor.rgb + spec * specStrength * cLightColor.a);
         #else
         #else
             float3 finalColor = diff * lightColor * diffColor.rgb;
             float3 finalColor = diff * lightColor * diffColor.rgb;

+ 7 - 9
SourceAssets/HLSLShaders/Lighting.hlsl

@@ -1,17 +1,15 @@
 #pragma warning(disable:3571)
 #pragma warning(disable:3571)
 
 
-float GetDiffuseDir(float3 normal, float3 lightDir, out float NdotL)
+float GetDiffuseDir(float3 normal, float3 lightDir)
 {
 {
-    NdotL = saturate(dot(normal, lightDir));
-    return NdotL;
+    return saturate(dot(normal, lightDir));
 }
 }
 
 
-float GetDiffusePointOrSpot(float3 normal, float3 lightVec, out float3 lightDir, out float NdotL)
+float GetDiffusePointOrSpot(float3 normal, float3 lightVec, out float3 lightDir)
 {
 {
     float lightDist = length(lightVec);
     float lightDist = length(lightVec);
     lightDir = lightVec / lightDist;
     lightDir = lightVec / lightDist;
-    NdotL = saturate(dot(normal, lightDir));
-    return NdotL * tex1D(sLightRampMap, lightDist).r;
+    return saturate(dot(normal, lightDir)) * tex1D(sLightRampMap, lightDist).r;
 }
 }
 
 
 float GetDiffuseDirVolumetric()
 float GetDiffuseDirVolumetric()
@@ -25,10 +23,10 @@ float GetDiffusePointOrSpotVolumetric(float3 lightVec)
     return tex1D(sLightRampMap, lightDist).r;
     return tex1D(sLightRampMap, lightDist).r;
 }
 }
 
 
-float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float NdotL, float specularPower)
+float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularPower)
 {
 {
-    float3 reflectDir = 2.0 * NdotL * normal - lightDir;
-    return pow(saturate(dot(reflectDir, normalize(eyeVec))), specularPower);
+    float3 halfVec = normalize(normalize(eyeVec) + lightDir);
+    return pow(dot(normal, halfVec), specularPower);
 }
 }
 
 
 float GetShadow(float4 shadowPos)
 float GetShadow(float4 shadowPos)