Browse Source

Restored earlier use of forward lighting shader interpolators to fix rendering bugs on Intel 3150.

Lasse Öörni 14 years ago
parent
commit
2d5cfd889e

+ 5 - 5
SourceAssets/GLSLShaders/Ambient.frag

@@ -3,16 +3,16 @@
 #include "Fog.frag"
 #include "Lighting.frag"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vVertexLighting;
+varying vec4 vVertexLighting;
 
 void main()
 {
     #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord.xy);
+        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
     #else
         vec4 diffColor = cMatDiffColor;
     #endif
@@ -21,6 +21,6 @@ void main()
         diffColor *= vColor;
     #endif
 
-    vec3 finalColor = vVertexLighting * diffColor.rgb;
-    gl_FragColor = vec4(GetFog(finalColor, vTexCoord.z), diffColor.a);
+    vec3 finalColor = vVertexLighting.rgb * diffColor.rgb;
+    gl_FragColor = vec4(GetFog(finalColor, vVertexLighting.a), diffColor.a);
 }

+ 5 - 5
SourceAssets/GLSLShaders/Ambient.vert

@@ -2,24 +2,24 @@
 #include "Transform.vert"
 #include "Lighting.vert"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vVertexLighting;
+varying vec4 vVertexLighting;
 
 void main()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
-    vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
+    vTexCoord = GetTexCoord(iTexCoord);
 
-    vVertexLighting = GetAmbient(GetZonePos(worldPos));
+    vVertexLighting = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
     #ifdef NUMVERTEXLIGHTS
     vec3 normal = GetWorldNormal(modelMatrix);
     for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-        vVertexLighting += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
+        vVertexLighting.rgb += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
     #endif
 
     #ifdef VERTEXCOLOR

+ 12 - 12
SourceAssets/GLSLShaders/ForwardLit.frag

@@ -3,11 +3,11 @@
 #include "Lighting.frag"
 #include "Fog.frag"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vLightVec;
+varying vec4 vLightVec;
 #ifdef SPECULAR
     varying vec3 vEyeVec;
 #endif
@@ -33,7 +33,7 @@ varying vec3 vLightVec;
 void main()
 {
     #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord.xy);
+        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
     #else
         vec4 diffColor = cMatDiffColor;
     #endif
@@ -48,26 +48,26 @@ void main()
     float diff;
 
     #ifdef NORMALMAP
-        vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord.xy));
+        vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord));
     #else
         vec3 normal = normalize(vNormal);
     #endif
 
     #ifdef DIRLIGHT
         #ifdef NORMALMAP
-            lightDir = normalize(vLightVec);
+            lightDir = normalize(vLightVec.xyz);
         #else
-            lightDir = vLightVec;
+            lightDir = vLightVec.xyz;
         #endif
         diff = GetDiffuseDir(normal, lightDir);
     #else
-        diff = GetDiffusePointOrSpot(normal, vLightVec, lightDir);
+        diff = GetDiffusePointOrSpot(normal, vLightVec.xyz, lightDir);
     #endif
 
     #ifdef SHADOW
         #if defined(DIRLIGHT)
-            vec4 shadowPos = GetDirShadowPos(vShadowPos, vTexCoord.z);
-            diff *= min(GetShadow(shadowPos) + GetShadowFade(vTexCoord.z), 1.0);
+            vec4 shadowPos = GetDirShadowPos(vShadowPos, vLightVec.w);
+            diff *= min(GetShadow(shadowPos) + GetShadowFade(vLightVec.w), 1.0);
         #elif defined(SPOTLIGHT)
             diff *= GetShadow(vShadowPos);
         #else
@@ -85,7 +85,7 @@ void main()
 
     #ifdef SPECULAR
         #ifdef SPECMAP
-            vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord.xy).g;
+            vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord).g;
         #else
             vec3 specColor = cMatSpecColor.rgb;
         #endif
@@ -97,8 +97,8 @@ void main()
 
     #ifdef AMBIENT
         finalColor += cAmbientColor * diffColor.rgb;
-        gl_FragColor = vec4(GetFog(finalColor, vTexCoord.z), diffColor.a);
+        gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
     #else
-        gl_FragColor = vec4(GetLitFog(finalColor, vTexCoord.z), diffColor.a);
+        gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
     #endif
 }

+ 7 - 7
SourceAssets/GLSLShaders/ForwardLit.vert

@@ -1,11 +1,11 @@
 #include "Uniforms.vert"
 #include "Transform.vert"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vLightVec;
+varying vec4 vLightVec;
 #ifdef SPECULAR
     varying vec3 vEyeVec;
 #endif
@@ -33,7 +33,7 @@ void main()
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
-    vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
+    vTexCoord = GetTexCoord(iTexCoord);
 
     #ifdef VERTEXCOLOR
         vColor = iColor;
@@ -49,9 +49,9 @@ void main()
     vec4 projWorldPos = vec4(worldPos, 1.0);
 
     #ifdef DIRLIGHT
-        vLightVec = cLightDir;
+        vLightVec = vec4(cLightDir, GetDepth(gl_Position));
     #else
-        vLightVec = (cLightPos.xyz - worldPos) * cLightPos.w;
+        vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
     #endif
 
     #ifdef SHADOW
@@ -74,14 +74,14 @@ void main()
     #endif
 
     #ifdef POINTLIGHT
-        vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec;
+        vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
     #endif
 
     #ifdef NORMALMAP
         vTangent = GetWorldTangent(modelMatrix);
         vBitangent = cross(vTangent, vNormal) * iTangent.w;
         mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-        vLightVec = vLightVec * tbn;
+        vLightVec.xyz = vLightVec.xyz * tbn;
         #ifdef SPECULAR
             vEyeVec = (cCameraPos - worldPos) * tbn;
         #endif

+ 4 - 5
SourceAssets/GLSLShaders/LitParticle.frag

@@ -7,8 +7,7 @@ varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vLightVec;
-varying vec2 vZonePosDepth;
+varying vec4 vLightVec;
 #ifdef SPOTLIGHT
     varying vec4 vSpotPos;
 #endif
@@ -36,7 +35,7 @@ void main()
     #ifdef DIRLIGHT
         diff = GetDiffuseDirVolumetric();
     #else
-        diff = GetDiffusePointOrSpotVolumetric(vLightVec);
+        diff = GetDiffusePointOrSpotVolumetric(vLightVec.xyz);
     #endif
 
     #if defined(SPOTLIGHT)
@@ -51,8 +50,8 @@ void main()
     
     #ifdef AMBIENT
         finalColor += cAmbientColor * diffColor.rgb;
-        gl_FragColor = vec4(GetFog(finalColor, vZonePosDepth.y), diffColor.a);
+        gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
     #else
-        gl_FragColor = vec4(GetLitFog(finalColor, vZonePosDepth.y), diffColor.a);
+        gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
     #endif
 }

+ 4 - 7
SourceAssets/GLSLShaders/LitParticle.vert

@@ -5,8 +5,7 @@ varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vLightVec;
-varying vec2 vZonePosDepth;
+varying vec4 vLightVec;
 #ifdef SPOTLIGHT
     varying vec4 vSpotPos;
 #endif
@@ -28,12 +27,10 @@ void main()
     vec4 projWorldPos = vec4(worldPos, 1.0);
 
     #ifdef DIRLIGHT
-        vLightVec = cLightDir;
+        vLightVec = vec4(cLightDir, GetDepth(gl_Position));
     #else
-        vLightVec = (cLightPos.xyz - worldPos) * cLightPos.w;
+        vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
     #endif
-    
-    vZonePosDepth = vec2(GetZonePos(worldPos), GetDepth(gl_Position));
 
     #ifdef SPOTLIGHT
         // Spotlight projection: transform from world space to projector texture coordinates
@@ -41,6 +38,6 @@ void main()
     #endif
 
     #ifdef POINTLIGHT
-        vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec;
+        vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
     #endif
 }

+ 6 - 6
SourceAssets/GLSLShaders/Material.frag

@@ -3,17 +3,17 @@
 #include "Lighting.frag"
 #include "Fog.frag"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vVertexLighting;
+varying vec4 vVertexLighting;
 varying vec4 vScreenPos;
 
 void main()
 {
     #ifdef DIFFMAP
-        vec4 diffInput = texture2D(sDiffMap, vTexCoord.xy);
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
         #ifdef ALPHAMASK
             if (diffInput.a < 0.5)
                 discard;
@@ -24,7 +24,7 @@ void main()
     #endif
 
     #ifdef SPECMAP
-        vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord.xy).g;
+        vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord).g;
     #else
         vec3 specColor = cMatSpecColor.rgb;
     #endif
@@ -33,6 +33,6 @@ void main()
     vec4 lightInput = 2.0 * texture2DProj(sLightBuffer, vScreenPos);
     vec3 lightSpecColor = lightInput.a * lightInput.rgb / max(GetIntensity(lightInput.rgb), 0.001);
 
-    vec3 finalColor = (vVertexLighting + lightInput.rgb) * diffColor + lightSpecColor * specColor;
-    gl_FragColor = vec4(GetFog(finalColor, vTexCoord.z), 1.0);
+    vec3 finalColor = (vVertexLighting.rgb + lightInput.rgb) * diffColor + lightSpecColor * specColor;
+    gl_FragColor = vec4(GetFog(finalColor, vVertexLighting.a), 1.0);
 }

+ 5 - 5
SourceAssets/GLSLShaders/Material.vert

@@ -3,11 +3,11 @@
 #include "ScreenPos.vert"
 #include "Lighting.vert"
 
-varying vec3 vTexCoord;
+varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
 #endif
-varying vec3 vVertexLighting;
+varying vec4 vVertexLighting;
 varying vec4 vScreenPos;
 
 void main()
@@ -15,14 +15,14 @@ void main()
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
-    vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
+    vTexCoord = GetTexCoord(iTexCoord);
     vScreenPos = GetScreenPos(gl_Position);
 
-    vVertexLighting = GetAmbient(GetZonePos(worldPos));
+    vVertexLighting = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
     #ifdef NUMVERTEXLIGHTS
     vec3 normal = GetWorldNormal(modelMatrix);
     for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-        vVertexLighting += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
+        vVertexLighting.rgb += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
     #endif
 
     #ifdef VERTEXCOLOR

+ 10 - 10
SourceAssets/HLSLShaders/Ambient.hlsl

@@ -24,8 +24,8 @@ void VS(float4 iPos : POSITION,
     #ifdef BILLBOARD
         float2 iSize : TEXCOORD1,
     #endif
-    out float3 oTexCoord : TEXCOORD0,
-    out float3 oVertexLighting : TEXCOORD1,
+    out float2 oTexCoord : TEXCOORD0,
+    out float4 oVertexLighting : TEXCOORD1,
     #ifdef VERTEXCOLOR
         out float4 oColor : COLOR0,
     #endif
@@ -34,13 +34,13 @@ void VS(float4 iPos : POSITION,
     float4x3 modelMatrix = iModelMatrix;
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
-    oTexCoord = float3(GetTexCoord(iTexCoord), GetDepth(oPos));
+    oTexCoord = GetTexCoord(iTexCoord);
 
-    oVertexLighting = GetAmbient(GetZonePos(worldPos));
+    oVertexLighting = float4(GetAmbient(GetZonePos(worldPos)), GetDepth(oPos));
     #ifdef NUMVERTEXLIGHTS
     float3 normal = GetWorldNormal(modelMatrix);
     for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-        oVertexLighting += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
+        oVertexLighting.rgb += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
     #endif
 
     #ifdef VERTEXCOLOR
@@ -48,15 +48,15 @@ void VS(float4 iPos : POSITION,
     #endif
 }
 
-void PS(float3 iTexCoord : TEXCOORD0,
-    float3 iVertexLighting : TEXCOORD1,
+void PS(float2 iTexCoord : TEXCOORD0,
+    float4 iVertexLighting : TEXCOORD1,
     #ifdef VERTEXCOLOR
         float4 iColor : COLOR0,
     #endif
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord.xy);
+        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
     #else
         float4 diffColor = cMatDiffColor;
     #endif
@@ -65,7 +65,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
         diffColor *= iColor;
     #endif
 
-    float3 finalColor = iVertexLighting * diffColor.rgb;
+    float3 finalColor = iVertexLighting.rgb * diffColor.rgb;
 
-    oColor = float4(GetFog(finalColor, iTexCoord.z), diffColor.a);
+    oColor = float4(GetFog(finalColor, iVertexLighting.a), diffColor.a);
 }

+ 19 - 19
SourceAssets/HLSLShaders/ForwardLit.hlsl

@@ -23,8 +23,8 @@ void VS(float4 iPos : POSITION,
     #ifdef BILLBOARD
         float2 iSize : TEXCOORD1,
     #endif
-    out float3 oTexCoord : TEXCOORD0,
-    out float3 oLightVec : TEXCOORD1,
+    out float2 oTexCoord : TEXCOORD0,
+    out float4 oLightVec : TEXCOORD1,
     #ifndef NORMALMAP
         out float3 oNormal : TEXCOORD2,
     #endif
@@ -54,7 +54,7 @@ void VS(float4 iPos : POSITION,
     float4x3 modelMatrix = iModelMatrix;
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
-    oTexCoord = float3(GetTexCoord(iTexCoord), GetDepth(oPos));
+    oTexCoord = GetTexCoord(iTexCoord);
 
     #ifdef VERTEXCOLOR
         oColor = iColor;
@@ -70,9 +70,9 @@ void VS(float4 iPos : POSITION,
     float4 projWorldPos = float4(worldPos, 1.0);
 
     #ifdef DIRLIGHT
-        oLightVec = cLightDir;
+        oLightVec = float4(cLightDir, GetDepth(oPos));
     #else
-        oLightVec = (cLightPos.xyz - worldPos) * cLightPos.w;
+        oLightVec = float4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(oPos));
     #endif
 
     #ifdef SHADOW
@@ -95,14 +95,14 @@ void VS(float4 iPos : POSITION,
     #endif
 
     #ifdef POINTLIGHT
-        oCubeMaskVec = mul(oLightVec, (float3x3)cLightMatrices[0]);
+        oCubeMaskVec = mul(oLightVec.xyz, (float3x3)cLightMatrices[0]);
     #endif
 
     #ifdef NORMALMAP
         oTangent = GetWorldTangent(modelMatrix);
         oBitangent = cross(oTangent, oNormal) * iTangent.w;
         float3x3 tbn = float3x3(oTangent, oBitangent, oNormal);
-        oLightVec = mul(tbn, oLightVec);
+        oLightVec.xyz = mul(tbn, oLightVec.xyz);
         #ifdef SPECULAR
             oEyeVec = mul(tbn, cCameraPos - worldPos);
         #endif
@@ -111,8 +111,8 @@ void VS(float4 iPos : POSITION,
     #endif
 }
 
-void PS(float3 iTexCoord : TEXCOORD0,
-    float3 iLightVec : TEXCOORD1,
+void PS(float2 iTexCoord : TEXCOORD0,
+    float4 iLightVec : TEXCOORD1,
     #ifndef NORMALMAP
         float3 iNormal : TEXCOORD2,
     #endif
@@ -140,7 +140,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord.xy);
+        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
     #else
         float4 diffColor = cMatDiffColor;
     #endif
@@ -150,7 +150,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     #endif
 
     #ifdef NORMALMAP
-        float3 normal = DecodeNormal(tex2D(sNormalMap, iTexCoord.xy));
+        float3 normal = DecodeNormal(tex2D(sNormalMap, iTexCoord));
     #else
         float3 normal = normalize(iNormal);
     #endif
@@ -162,19 +162,19 @@ void PS(float3 iTexCoord : TEXCOORD0,
 
     #ifdef DIRLIGHT
         #ifdef NORMALMAP
-            lightDir = normalize(iLightVec);
+            lightDir = normalize(iLightVec.xyz);
         #else
-            lightDir = iLightVec;
+            lightDir = iLightVec.xyz;
         #endif
         diff = GetDiffuseDir(normal, lightDir);
     #else
-        diff = GetDiffusePointOrSpot(normal, iLightVec, lightDir);
+        diff = GetDiffusePointOrSpot(normal, iLightVec.xyz, lightDir);
     #endif
 
     #ifdef SHADOW
         #if defined(DIRLIGHT)
-            float4 shadowPos = GetDirShadowPos(iShadowPos, iTexCoord.z);
-            diff *= saturate(GetShadow(shadowPos) + GetShadowFade(iTexCoord.z));
+            float4 shadowPos = GetDirShadowPos(iShadowPos, iLightVec.w);
+            diff *= saturate(GetShadow(shadowPos) + GetShadowFade(iLightVec.w));
         #elif defined(SPOTLIGHT)
             diff *= GetShadow(iShadowPos);
         #else
@@ -192,7 +192,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
 
     #ifdef SPECULAR
         #ifdef SPECMAP
-            float3 specColor = cMatSpecColor.rgb * tex2D(sSpecMap, iTexCoord.xy).g;
+            float3 specColor = cMatSpecColor.rgb * tex2D(sSpecMap, iTexCoord).g;
         #else
             float3 specColor = cMatSpecColor.rgb;
         #endif
@@ -204,8 +204,8 @@ void PS(float3 iTexCoord : TEXCOORD0,
 
     #ifdef AMBIENT
         finalColor += cAmbientColor * diffColor.rgb;
-        oColor = float4(GetFog(finalColor, iTexCoord.z), diffColor.a);
+        oColor = float4(GetFog(finalColor, iLightVec.w), diffColor.a);
     #else
-        oColor = float4(GetLitFog(finalColor, iTexCoord.z), diffColor.a);
+        oColor = float4(GetLitFog(finalColor, iLightVec.w), diffColor.a);
     #endif
 }

+ 12 - 12
SourceAssets/HLSLShaders/LitParticle.hlsl

@@ -20,8 +20,8 @@ void VS(float4 iPos : POSITION,
     #ifdef BILLBOARD
         float2 iSize : TEXCOORD1,
     #endif
-    out float3 oTexCoord : TEXCOORD0,
-    out float3 oLightVec : TEXCOORD1,
+    out float2 oTexCoord : TEXCOORD0,
+    out float4 oLightVec : TEXCOORD1,
     #ifdef SPOTLIGHT
         out float4 oSpotPos : TEXCOORD2,
     #endif
@@ -36,7 +36,7 @@ void VS(float4 iPos : POSITION,
     float4x3 modelMatrix = iModelMatrix;
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
-    oTexCoord = float3(GetTexCoord(iTexCoord), GetDepth(oPos));
+    oTexCoord = GetTexCoord(iTexCoord);
 
     #ifdef VERTEXCOLOR
         oColor = iColor;
@@ -45,9 +45,9 @@ void VS(float4 iPos : POSITION,
     float4 projWorldPos = float4(worldPos, 1.0);
 
     #ifdef DIRLIGHT
-        oLightVec = cLightDir;
+        oLightVec = float4(cLightDir, GetDepth(oPos));
     #else
-        oLightVec = (cLightPos.xyz - worldPos) * cLightPos.w;
+        oLightVec = float4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(oPos));
     #endif
 
     #ifdef SPOTLIGHT
@@ -56,12 +56,12 @@ void VS(float4 iPos : POSITION,
     #endif
 
     #ifdef POINTLIGHT
-        oCubeMaskVec = mul(oLightVec, (float3x3)cLightMatrices[0]);
+        oCubeMaskVec = mul(oLightVec.xyz, (float3x3)cLightMatrices[0]);
     #endif
 }
 
-void PS(float3 iTexCoord : TEXCOORD0,
-    float3 iLightVec : TEXCOORD1,
+void PS(float2 iTexCoord : TEXCOORD0,
+    float4 iLightVec : TEXCOORD1,
     #ifdef SPOTLIGHT
         float4 iSpotPos : TEXCOORD2,
     #endif
@@ -74,7 +74,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord.xy);
+        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
     #else
         float4 diffColor = cMatDiffColor;
     #endif
@@ -90,7 +90,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     #ifdef DIRLIGHT
         diff = GetDiffuseDirVolumetric();
     #else
-        diff = GetDiffusePointOrSpotVolumetric(iLightVec);
+        diff = GetDiffusePointOrSpotVolumetric(iLightVec.xyz);
     #endif
 
     #if defined(SPOTLIGHT)
@@ -105,8 +105,8 @@ void PS(float3 iTexCoord : TEXCOORD0,
     
     #ifdef AMBIENT
         finalColor += cAmbientColor * diffColor.rgb;
-        oColor = float4(GetFog(finalColor, iTexCoord.z), diffColor.a);
+        oColor = float4(GetFog(finalColor, iLightVec.w), diffColor.a);
     #else
-        oColor = float4(GetLitFog(finalColor, iTexCoord.z), diffColor.a);
+        oColor = float4(GetLitFog(finalColor, iLightVec.w), diffColor.a);
     #endif
 }

+ 11 - 11
SourceAssets/HLSLShaders/Material.hlsl

@@ -19,8 +19,8 @@ void VS(float4 iPos : POSITION,
         float4x3 iModelInstance : TEXCOORD2,
     #endif
     float2 iTexCoord : TEXCOORD0,
-    out float3 oTexCoord : TEXCOORD0,
-    out float3 oVertexLighting : TEXCOORD1,
+    out float2 oTexCoord : TEXCOORD0,
+    out float4 oVertexLighting : TEXCOORD1,
     out float4 oScreenPos : TEXCOORD2,
     #ifdef VERTEXCOLOR
         out float4 oColor : COLOR0,
@@ -30,14 +30,14 @@ void VS(float4 iPos : POSITION,
     float4x3 modelMatrix = iModelMatrix;
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
-    oTexCoord = float3(GetTexCoord(iTexCoord), GetDepth(oPos));
+    oTexCoord = GetTexCoord(iTexCoord);
     oScreenPos = GetScreenPos(oPos);
 
-    oVertexLighting = GetAmbient(GetZonePos(worldPos));
+    oVertexLighting = float4(GetAmbient(GetZonePos(worldPos)), GetDepth(oPos));
     #ifdef NUMVERTEXLIGHTS
     float3 normal = GetWorldNormal(modelMatrix);
     for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-        oVertexLighting += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
+        oVertexLighting.rgb += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
     #endif
 
     #ifdef VERTEXCOLOR
@@ -45,8 +45,8 @@ void VS(float4 iPos : POSITION,
     #endif
 }
 
-void PS(float3 iTexCoord : TEXCOORD0,
-    float3 iVertexLighting : TEXCOORD1,
+void PS(float2 iTexCoord : TEXCOORD0,
+    float4 iVertexLighting : TEXCOORD1,
     float4 iScreenPos : TEXCOORD2,
     #ifdef VERTEXCOLOR
         float4 iColor : COLOR0,
@@ -54,7 +54,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffInput = tex2D(sDiffMap, iTexCoord.xy);
+        float4 diffInput = tex2D(sDiffMap, iTexCoord);
         #ifdef ALPHAMASK
             if (diffInput.a < 0.5)
                 discard;
@@ -65,7 +65,7 @@ void PS(float3 iTexCoord : TEXCOORD0,
     #endif
 
     #ifdef SPECMAP
-        float3 specColor = cMatSpecColor.rgb * tex2D(sSpecMap, iTexCoord.xy).g;
+        float3 specColor = cMatSpecColor.rgb * tex2D(sSpecMap, iTexCoord).g;
     #else
         float3 specColor = cMatSpecColor.rgb;
     #endif
@@ -74,6 +74,6 @@ void PS(float3 iTexCoord : TEXCOORD0,
     float4 lightInput = 2.0 * tex2Dproj(sLightBuffer, iScreenPos);
     float3 lightSpecColor = lightInput.a * (lightInput.rgb / GetIntensity(lightInput.rgb));
 
-    float3 finalColor = (iVertexLighting + lightInput.rgb) * diffColor + lightSpecColor * specColor;
-    oColor = float4(GetFog(finalColor, iTexCoord.z), 1.0);
+    float3 finalColor = (iVertexLighting.rgb + lightInput.rgb) * diffColor + lightSpecColor * specColor;
+    oColor = float4(GetFog(finalColor, iVertexLighting.a), 1.0);
 }