Browse Source

Fixed forward lit spotlight shadows on OpenGL.
Removed the NVIDIA-specific INTZ depth path so that shaders don't need special cases for reading depth.

Lasse Öörni 13 years ago
parent
commit
7c61b098bf
35 changed files with 75 additions and 295 deletions
  1. 2 14
      Bin/CoreData/Shaders/GLSL/DeferredLight.frag
  2. 0 1
      Bin/CoreData/Shaders/GLSL/DeferredLight.xml
  3. 11 0
      Bin/CoreData/Shaders/GLSL/Lighting.vert
  4. 5 12
      Bin/CoreData/Shaders/GLSL/LitSolid.frag
  5. 4 8
      Bin/CoreData/Shaders/GLSL/LitSolid.vert
  6. 0 2
      Bin/CoreData/Shaders/GLSL/LitSolid.xml
  7. 2 14
      Bin/CoreData/Shaders/GLSL/PrepassLight.frag
  8. 0 1
      Bin/CoreData/Shaders/GLSL/PrepassLight.xml
  9. 0 6
      Bin/CoreData/Shaders/GLSL/Samplers.frag
  10. 3 9
      Bin/CoreData/Shaders/GLSL/TerrainBlend.frag
  11. 2 6
      Bin/CoreData/Shaders/GLSL/TerrainBlend.vert
  12. 0 2
      Bin/CoreData/Shaders/GLSL/TerrainBlend.xml
  13. 1 2
      Bin/CoreData/Shaders/GLSL/Uniforms.frag
  14. 2 10
      Bin/CoreData/Shaders/HLSL/DeferredLight.hlsl
  15. 1 2
      Bin/CoreData/Shaders/HLSL/DeferredLight.xml
  16. 4 11
      Bin/CoreData/Shaders/HLSL/LitSolid.hlsl
  17. 0 2
      Bin/CoreData/Shaders/HLSL/LitSolid.xml
  18. 2 10
      Bin/CoreData/Shaders/HLSL/PrepassLight.hlsl
  19. 1 2
      Bin/CoreData/Shaders/HLSL/PrepassLight.xml
  20. 0 5
      Bin/CoreData/Shaders/HLSL/Samplers.hlsl
  21. 4 10
      Bin/CoreData/Shaders/HLSL/TerrainBlend.hlsl
  22. 0 2
      Bin/CoreData/Shaders/HLSL/TerrainBlend.xml
  23. 0 1
      Bin/CoreData/Shaders/HLSL/Uniforms.hlsl
  24. 5 5
      Docs/Reference.dox
  25. 0 1
      Engine/Engine/GraphicsAPI.cpp
  26. 0 5
      Engine/Graphics/Batch.cpp
  27. 10 60
      Engine/Graphics/Direct3D9/D3D9Graphics.cpp
  28. 0 10
      Engine/Graphics/Direct3D9/D3D9Graphics.h
  29. 0 1
      Engine/Graphics/GraphicsDefs.cpp
  30. 0 1
      Engine/Graphics/GraphicsDefs.h
  31. 5 35
      Engine/Graphics/OpenGL/OGLGraphics.cpp
  32. 0 4
      Engine/Graphics/OpenGL/OGLGraphics.h
  33. 4 3
      Engine/Graphics/OpenGL/OGLTexture2D.cpp
  34. 3 30
      Engine/Graphics/Renderer.cpp
  35. 4 8
      Engine/Graphics/View.cpp

+ 2 - 14
Bin/CoreData/Shaders/GLSL/DeferredLight.frag

@@ -16,13 +16,7 @@ void main()
 {
     // If rendering a directional light quad, optimize out the w divide
     #ifdef DIRLIGHT
-        #if defined(HWDEPTH) && defined(ORTHO)
-            float depth = texture2D(sDepthBuffer, vScreenPos).r;
-        #elif defined(HWDEPTH) && !defined(ORTHO)
-            float depth = ReconstructDepth(texture2D(sDepthBuffer, vScreenPos).r);
-        #else
-            float depth = DecodeDepth(texture2D(sDepthBuffer, vScreenPos).rgb);
-        #endif
+        float depth = DecodeDepth(texture2D(sDepthBuffer, vScreenPos).rgb);
         #ifdef ORTHO
             vec3 worldPos = mix(vNearRay, vFarRay, depth);
         #else
@@ -31,13 +25,7 @@ void main()
         vec4 albedoInput = texture2D(sAlbedoBuffer, vScreenPos);
         vec4 normalInput = texture2D(sNormalBuffer, vScreenPos);
     #else
-        #if defined(HWDEPTH) && defined(ORTHO)
-            float depth = texture2DProj(sDepthBuffer, vScreenPos).r;
-        #elif defined(HWDEPTH) && !defined(ORTHO)
-            float depth = ReconstructDepth(texture2DProj(sDepthBuffer, vScreenPos).r);
-        #else
-            float depth = DecodeDepth(texture2DProj(sDepthBuffer, vScreenPos).rgb);
-        #endif
+        float depth = DecodeDepth(texture2DProj(sDepthBuffer, vScreenPos).rgb);
         #ifdef ORTHO
             vec3 worldPos = mix(vNearRay, vFarRay, depth) / vScreenPos.w;
         #else

+ 0 - 1
Bin/CoreData/Shaders/GLSL/DeferredLight.xml

@@ -12,6 +12,5 @@
         <option name="Spec" define="SPECULAR" />
         <option name="Shadow" define="SHADOW" />
         <option name="LQ" define="LQSHADOW" />
-        <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 11 - 0
Bin/CoreData/Shaders/GLSL/Lighting.vert

@@ -69,4 +69,15 @@ float GetVertexLightVolumetric(int index, vec3 worldPos)
     #define NUMCASCADES 1
 #endif
 
+vec4 GetShadowPos(int index, vec4 projWorldPos)
+{
+    #if defined(DIRLIGHT)
+        return cLightMatrices[index] * projWorldPos;
+    #elif defined(SPOTLIGHT)
+        return cLightMatrices[1] * projWorldPos;
+    #else
+        return vec4(projWorldPos.xyz - cLightPos.xyz, 1.0);
+    #endif
+}
+
 #endif

+ 5 - 12
Bin/CoreData/Shaders/GLSL/LitSolid.frag

@@ -105,13 +105,9 @@ void main()
         #endif
     
         float specPower = cMatSpecColor.a / 255.0;
-    
-        #ifdef HWDEPTH
-            gl_FragColor = vec4(normal * 0.5 + 0.5, specPower);
-        #else
-            gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
-            gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-        #endif
+        
+        gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
+        gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
     #elif defined(DEFERRED)
         // Fill deferred G-buffer
         #ifdef NORMALMAP
@@ -127,15 +123,12 @@ void main()
         gl_FragData[0] = vec4(GetFog(vVertexLight.rgb * diffColor.rgb, vVertexLight.a), 1.0);
         gl_FragData[1] = GetFogFactor(vVertexLight.a) * vec4(diffColor.rgb, specIntensity);
         gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
-        
+        gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
+
         #ifdef ENVCUBEMAP
             normal = normalize(normal);
             gl_FragData[0].rgb += cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal));
         #endif
-
-        #ifndef HWDEPTH
-            gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-        #endif
     #else
         // Ambient & per-vertex lighting
         vec3 finalColor = vVertexLight.rgb * diffColor.rgb;

+ 4 - 8
Bin/CoreData/Shaders/GLSL/LitSolid.vert

@@ -56,17 +56,13 @@ void main()
     #ifdef PERPIXEL
         // Per-pixel forward lighting
         vec4 projWorldPos = vec4(worldPos, 1.0);
-    
+
         #ifdef SHADOW
             // Shadow projection: transform from world space to shadow space
-            #ifndef POINTLIGHT
-                for (int i = 0; i < NUMCASCADES; i++)
-                    vShadowPos[i] = cLightMatrices[i] * projWorldPos;
-            #else
-                vShadowPos[0] = vec4(projWorldPos.xyz - cLightPos.xyz, 1.0);
-            #endif
+            for (int i = 0; i < NUMCASCADES; i++)
+                vShadowPos[i] = GetShadowPos(i, projWorldPos);
         #endif
-    
+
         #ifdef SPOTLIGHT
             // Spotlight projection: transform from world space to projector texture coordinates
             vSpotPos = cLightMatrices[0] * projWorldPos;

+ 0 - 2
Bin/CoreData/Shaders/GLSL/LitSolid.xml

@@ -48,8 +48,6 @@
         <variation name="Prepass" define="PREPASS" exclude="EnvCube" />
         <variation name="Material" define="MATERIAL" />
         <variation name="Deferred" define="DEFERRED" />
-        <option name="HW" define="HWDEPTH" require="PREPASS" />
-        <option name="HW" define="HWDEPTH" require="DEFERRED" />
         <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
         <option name="Spec" define="SPECULAR" require="PERPIXEL" />
         <option name="Shadow" define="SHADOW" require="PERPIXEL" />

+ 2 - 14
Bin/CoreData/Shaders/GLSL/PrepassLight.frag

@@ -16,13 +16,7 @@ void main()
 {
     // If rendering a directional light quad, optimize out the w divide
     #ifdef DIRLIGHT
-        #if defined(HWDEPTH) && defined(ORTHO)
-            float depth = texture2D(sDepthBuffer, vScreenPos).r;
-        #elif defined(HWDEPTH) && !defined(ORTHO)
-            float depth = ReconstructDepth(texture2D(sDepthBuffer, vScreenPos).r);
-        #else
-            float depth = DecodeDepth(texture2D(sDepthBuffer, vScreenPos).rgb);
-        #endif
+        float depth = DecodeDepth(texture2D(sDepthBuffer, vScreenPos).rgb);
         #ifdef ORTHO
             vec3 worldPos = mix(vNearRay, vFarRay, depth);
         #else
@@ -30,13 +24,7 @@ void main()
         #endif
         vec4 normalInput = texture2D(sNormalBuffer, vScreenPos);
     #else
-        #if defined(HWDEPTH) && defined(ORTHO)
-            float depth = texture2DProj(sDepthBuffer, vScreenPos).r;
-        #elif defined(HWDEPTH) && !defined(ORTHO)
-            float depth = ReconstructDepth(texture2DProj(sDepthBuffer, vScreenPos).r);
-        #else
-            float depth = DecodeDepth(texture2DProj(sDepthBuffer, vScreenPos).rgb);
-        #endif
+        float depth = DecodeDepth(texture2DProj(sDepthBuffer, vScreenPos).rgb);
         #ifdef ORTHO
             vec3 worldPos = mix(vNearRay, vFarRay, depth) / vScreenPos.w;
         #else

+ 0 - 1
Bin/CoreData/Shaders/GLSL/PrepassLight.xml

@@ -12,6 +12,5 @@
         <option name="Spec" define="SPECULAR" />
         <option name="Shadow" define="SHADOW" />
         <option name="LQ" define="LQSHADOW" />
-        <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 0 - 6
Bin/CoreData/Shaders/GLSL/Samplers.frag

@@ -45,9 +45,3 @@ float DecodeDepth(vec3 depth)
     const vec3 dotValues = vec3(1.0, 1.0 / 255.0, 1.0 / (255.0 * 255.0));
     return dot(depth, dotValues);
 }
-
-float ReconstructDepth(float hwDepth)
-{
-    return cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x);
-}
-

+ 3 - 9
Bin/CoreData/Shaders/GLSL/TerrainBlend.frag

@@ -87,12 +87,8 @@ void main()
 
         float specPower = cMatSpecColor.a / 255.0;
 
-        #ifdef HWDEPTH
-            gl_FragColor = vec4(normal * 0.5 + 0.5, specPower);
-        #else
-            gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
-            gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-        #endif
+        gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
+        gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
     #elif defined(DEFERRED)
         // Fill deferred G-buffer
         vec3 normal = vNormal;
@@ -103,9 +99,7 @@ void main()
         gl_FragData[0] = vec4(GetFog(vVertexLight.rgb * diffColor.rgb, vVertexLight.a), 1.0);
         gl_FragData[1] = GetFogFactor(vVertexLight.a) * vec4(diffColor.rgb, specIntensity);
         gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
-        #ifndef HWDEPTH
-            gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-        #endif
+        gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
     #else
         // Ambient & per-vertex lighting
         vec3 finalColor = vVertexLight.rgb * diffColor.rgb;

+ 2 - 6
Bin/CoreData/Shaders/GLSL/TerrainBlend.vert

@@ -39,12 +39,8 @@ void main()
 
         #ifdef SHADOW
             // Shadow projection: transform from world space to shadow space
-            #ifndef POINTLIGHT
-                for (int i = 0; i < NUMCASCADES; i++)
-                    vShadowPos[i] = cLightMatrices[i] * projWorldPos;
-            #else
-                vShadowPos[0] = vec4(projWorldPos.xyz - cLightPos.xyz, 1.0);
-            #endif
+            for (int i = 0; i < NUMCASCADES; i++)
+                vShadowPos[i] = GetShadowPos(i, projWorldPos);
         #endif
 
         #ifdef SPOTLIGHT

+ 0 - 2
Bin/CoreData/Shaders/GLSL/TerrainBlend.xml

@@ -41,8 +41,6 @@
         <variation name="Prepass" define="PREPASS" />
         <variation name="Material" define="MATERIAL" exclude="Normal" />
         <variation name="Deferred" define="DEFERRED" />
-        <option name="HW" define="HWDEPTH" require="PREPASS" />
-        <option name="HW" define="HWDEPTH" require="DEFERRED" />
         <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
         <option name="Spec" define="SPECULAR" require="PERPIXEL" />
         <option name="Shadow" define="SHADOW" require="PERPIXEL" />

+ 1 - 2
Bin/CoreData/Shaders/GLSL/Uniforms.frag

@@ -1,9 +1,8 @@
 #ifdef GL_ES
-    precision mediump float;
+    precision mediump float;
 #endif
 
 uniform vec3 cAmbientColor;
-uniform vec2 cDepthReconstruct;
 uniform vec2 cFogParams;
 uniform vec3 cFogColor;
 uniform vec2 cGBufferInvSize;

+ 2 - 10
Bin/CoreData/Shaders/HLSL/DeferredLight.hlsl

@@ -52,11 +52,7 @@ void PS(
             float depth = tex2D(sDepthBuffer, iScreenPos).r;
             float3 worldPos = lerp(iNearRay, iFarRay, depth);
         #else
-            #ifdef LINEAR
-                float depth = tex2D(sDepthBuffer, iScreenPos).r;
-            #else
-                float depth = ReconstructDepth(tex2D(sDepthBuffer, iScreenPos).r);
-            #endif
+            float depth = tex2D(sDepthBuffer, iScreenPos).r;
             float3 worldPos = iFarRay * depth;
         #endif
         float4 albedoInput = tex2D(sAlbedoBuffer, iScreenPos);
@@ -66,11 +62,7 @@ void PS(
             float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
             float3 worldPos = lerp(iNearRay, iFarRay, depth) / iScreenPos.w;
         #else
-            #ifdef LINEAR
-                float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
-            #else
-                float depth = ReconstructDepth(tex2Dproj(sDepthBuffer, iScreenPos).r);
-            #endif
+            float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
             float3 worldPos = iFarRay * depth / iScreenPos.w;
         #endif
         float4 albedoInput = tex2Dproj(sAlbedoBuffer, iScreenPos);

+ 1 - 2
Bin/CoreData/Shaders/HLSL/DeferredLight.xml

@@ -4,8 +4,7 @@
         <option name="Dir" define="DIRLIGHT" />
     </shader>
     <shader type="ps">
-        <option name="Linear" define="LINEAR" exclude="Ortho" />
-        <option name="Ortho" define="ORTHO" exclude="Linear" />
+        <option name="Ortho" define="ORTHO" />
         <variation name="Dir" define="DIRLIGHT" />
         <variation name="Spot" define="SPOTLIGHT" />
         <variation name="Point" define="POINTLIGHT" />

+ 4 - 11
Bin/CoreData/Shaders/HLSL/LitSolid.hlsl

@@ -155,15 +155,13 @@ void PS(float2 iTexCoord : TEXCOORD0,
             float3 iReflectionVec : TEXCOORD6,
         #endif
     #endif
-    #if defined(PREPASS) && !defined(HWDEPTH)
+    #ifdef PREPASS
         out float4 oDepth : COLOR1,
     #endif
     #ifdef DEFERRED
         out float4 oAlbedo : COLOR1,
         out float4 oNormal : COLOR2,
-        #ifndef HWDEPTH
-            out float4 oDepth : COLOR3,
-        #endif
+        out float4 oDepth : COLOR3,
     #endif
     out float4 oColor : COLOR0)
 {
@@ -238,9 +236,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
         float specPower = cMatSpecColor.a / 255.0;
 
         oColor = float4(normal * 0.5 + 0.5, specPower);
-        #ifndef HWDEPTH
-            oDepth = iVertexLight.a;
-        #endif
+        oDepth = iVertexLight.a;
     #elif defined(DEFERRED)
         // Fill deferred G-buffer
         #ifdef NORMALMAP
@@ -261,14 +257,11 @@ void PS(float2 iTexCoord : TEXCOORD0,
         oColor = float4(GetFog(iVertexLight.rgb * diffColor.rgb, iVertexLight.a), 1.0);
         oAlbedo = GetFogFactor(iVertexLight.a) * float4(diffColor.rgb, specIntensity);
         oNormal = float4(normal * 0.5 + 0.5, specPower);
+        oDepth = iVertexLight.a;
 
         #ifdef ENVCUBEMAP
             oColor.rgb += cMatEnvMapColor * texCUBE(sEnvCubeMap, reflect(iReflectionVec, normal));
         #endif
-
-        #ifndef HWDEPTH
-            oDepth = iVertexLight.a;
-        #endif
     #else
         // Ambient & per-vertex lighting
         float3 finalColor = iVertexLight.rgb * diffColor.rgb;

+ 0 - 2
Bin/CoreData/Shaders/HLSL/LitSolid.xml

@@ -49,8 +49,6 @@
         <variation name="Prepass" define="PREPASS" exclude="EnvCube" />
         <variation name="Material" define="MATERIAL" />
         <variation name="Deferred" define="DEFERRED" />
-        <option name="HW" define="HWDEPTH" require="PREPASS" />
-        <option name="HW" define="HWDEPTH" require="DEFERRED" />
         <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
         <option name="Spec" define="SPECULAR" require="PERPIXEL" />
         <option name="Shadow" define="SHADOW" require="PERPIXEL" />

+ 2 - 10
Bin/CoreData/Shaders/HLSL/PrepassLight.hlsl

@@ -52,11 +52,7 @@ void PS(
             float depth = tex2D(sDepthBuffer, iScreenPos).r;
             float3 worldPos = lerp(iNearRay, iFarRay, depth);
         #else
-            #ifdef LINEAR
-                float depth = tex2D(sDepthBuffer, iScreenPos).r;
-            #else
-                float depth = ReconstructDepth(tex2D(sDepthBuffer, iScreenPos).r);
-            #endif
+            float depth = tex2D(sDepthBuffer, iScreenPos).r;
             float3 worldPos = iFarRay * depth;
         #endif
         float4 normalInput = tex2D(sNormalBuffer, iScreenPos);
@@ -65,11 +61,7 @@ void PS(
             float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
             float3 worldPos = lerp(iNearRay, iFarRay, depth) / iScreenPos.w;
         #else
-            #ifdef LINEAR
-                float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
-            #else
-                float depth = ReconstructDepth(tex2Dproj(sDepthBuffer, iScreenPos).r);
-            #endif
+            float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
             float3 worldPos = iFarRay * depth / iScreenPos.w;
         #endif
         float4 normalInput = tex2Dproj(sNormalBuffer, iScreenPos);

+ 1 - 2
Bin/CoreData/Shaders/HLSL/PrepassLight.xml

@@ -4,8 +4,7 @@
         <option name="Dir" define="DIRLIGHT" />
     </shader>
     <shader type="ps">
-        <option name="Linear" define="LINEAR" exclude="Ortho" />
-        <option name="Ortho" define="ORTHO" exclude="Linear" />
+        <option name="Ortho" define="ORTHO" />
         <variation name="Dir" define="DIRLIGHT" />
         <variation name="Spot" define="SPOTLIGHT" />
         <variation name="Point" define="POINTLIGHT" />

+ 0 - 5
Bin/CoreData/Shaders/HLSL/Samplers.hlsl

@@ -33,8 +33,3 @@ float3 DecodeNormal(float4 normalInput)
     normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
     return normal;
 }
-
-float ReconstructDepth(float hwDepth)
-{
-    return cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x);
-}

+ 4 - 10
Bin/CoreData/Shaders/HLSL/TerrainBlend.hlsl

@@ -117,15 +117,13 @@ void PS(float2 iTexCoord : TEXCOORD0,
         float3 iNormal : TEXCOORD2,
         float4 iScreenPos : TEXCOORD3,
     #endif
-    #if defined(PREPASS) && !defined(HWDEPTH)
+    #ifdef PREPASS
         out float4 oDepth : COLOR1,
     #endif
     #ifdef DEFERRED
         out float4 oAlbedo : COLOR1,
         out float4 oNormal : COLOR2,
-        #ifndef HWDEPTH
-            out float4 oDepth : COLOR3,
-        #endif
+        out float4 oDepth : COLOR3,
     #endif
     out float4 oColor : COLOR0)
 {
@@ -183,9 +181,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
         float specPower = cMatSpecColor.a / 255.0;
 
         oColor = float4(normal * 0.5 + 0.5, specPower);
-        #ifndef HWDEPTH
-            oDepth = iVertexLight.a;
-        #endif
+        oDepth = iVertexLight.a;
     #elif defined(DEFERRED)
         // Fill deferred G-buffer
         float3 normal = iNormal;
@@ -201,9 +197,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
         oColor = float4(GetFog(iVertexLight.rgb * diffColor.rgb, iVertexLight.a), 1.0);
         oAlbedo = GetFogFactor(iVertexLight.a) * float4(diffColor.rgb, specIntensity);
         oNormal = float4(normal * 0.5 + 0.5, specPower);
-        #ifndef HWDEPTH
-            oDepth = iVertexLight.a;
-        #endif
+        oDepth = iVertexLight.a;
     #else
         // Ambient & per-vertex lighting
         float3 finalColor = iVertexLight.rgb * diffColor.rgb;

+ 0 - 2
Bin/CoreData/Shaders/HLSL/TerrainBlend.xml

@@ -42,8 +42,6 @@
         <variation name="Prepass" define="PREPASS" />
         <variation name="Material" define="MATERIAL" />
         <variation name="Deferred" define="DEFERRED" />
-        <option name="HW" define="HWDEPTH" require="PREPASS" />
-        <option name="HW" define="HWDEPTH" require="DEFERRED" />
         <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
         <option name="Spec" define="SPECULAR" require="PERPIXEL" />
         <option name="Shadow" define="SHADOW" require="PERPIXEL" />

+ 0 - 1
Bin/CoreData/Shaders/HLSL/Uniforms.hlsl

@@ -21,7 +21,6 @@ uniform float4 cVertexLights[4*3];
 
 // Pixel shader uniforms
 uniform float3 cAmbientColor;
-uniform float2 cDepthReconstruct;
 uniform float2 cFogParams;
 uniform float3 cFogColor;
 uniform float2 cGBufferInvSize;

+ 5 - 5
Docs/Reference.dox

@@ -432,7 +432,7 @@ When setting the initial screen mode, Graphics does a few checks:
 - For Direct3D9, the supported shader model is checked. 2 is minimum, but 3 will be used if available. SM2 can be forced by calling \ref Graphics::SetForceSM2 "SetForceSM2()" before setting the initial screen mode.
 - For OpenGL, version 2.0 with EXT_framebuffer_object, EXT_packed_depth_stencil and EXT_texture_filter_anisotropic extensions is checked for.
 - Are hardware shadow maps supported? Both ATI & NVIDIA style shadow maps can be used. If neither are available, no shadows will be rendered.
-- Are light pre-pass and deferred rendering modes supported? These require sufficient multiple rendertarget support, and either R32F texture format or readable hardware depth.
+- Are light pre-pass and deferred rendering modes supported? These require sufficient multiple rendertarget support, and R32F texture format support.
 
 \section Rendering_Renderer Renderer
 
@@ -522,11 +522,11 @@ Materials can also define an optimization pass for forward rendering where the a
 
 \section RenderingModes_Prepass Light pre-pass rendering
 
-%Light pre-pass requires a minimum of two passes per object. First the normal, specular power, depth and lightmask (8 low bits only) of opaque objects are rendered to the following G-buffer. If the INTZ readable hardware depth-stencil texture format is available, the second color rendertarget will be omitted:
+%Light pre-pass requires a minimum of two passes per object. First the normal, specular power, depth and lightmask (8 low bits only) of opaque objects are rendered to the following G-buffer:
 
 - RT0: World-space normal and specular power (D3DFMT_A8R8G8B8)
 - RT1: Linear depth (D3DFMT_R32F)
-- DS: Hardware depth and lightmask (D3DFMT_D24S8 or INTZ)
+- DS: Hardware depth and lightmask (D3DFMT_D24S8)
 
 After the G-buffer is complete, light volumes (spot and point lights) or fullscreen quads (directional lights) will be rendered to a light accumulation buffer to calculate the diffuse and specular light at each opaque pixel. Specular light is stored as intensity only. Stencil compare (AND operation) with the 8 low bits of the light's lightmask will be used for light culling. Similarly to forward rendering, shadow maps will be updated before each light as necessary.
 
@@ -534,13 +534,13 @@ Finally the opaque objects are re-rendered during the material pass, which combi
 
 \section RenderingModes_Deferred Deferred rendering
 
-Deferred rendering needs to render each opaque object only once to the G-buffer, but this rendering pass is much heavier than in light pre-pass rendering, as also ambient, emissive and diffuse albedo information is output at the same time. The G-buffer is the following, with the last color rendertarget omitted if hardware depth can be read:
+Deferred rendering needs to render each opaque object only once to the G-buffer, but this rendering pass is much heavier than in light pre-pass rendering, as also ambient, emissive and diffuse albedo information is output at the same time. The G-buffer is the following:
 
 - RT0: Final rendertarget with ambient, per-vertex and emissive color (D3DFMT_X8R8G8B8)
 - RT1: Diffuse albedo and specular intensity (D3DFMT_A8R8G8B8)
 - RT2: World-space normal and specular power (D3DFMT_A8R8G8B8)
 - RT3: Linear depth (D3DFMT_R32F)
-- DS: Hardware depth and lightmask (D3DFMT_D24S8 or INTZ)
+- DS: Hardware depth and lightmask (D3DFMT_D24S8)
 
 After the G-buffer has been rendered, light volumes will be rendered into the final rendertarget to accumulate per-pixel lighting. As the material albedo is available, all lighting calculations are final and output both the diffuse and specular color at the same time. After light accumulation rendering proceeds to pre-alpha, transparent, and post-alpha passes, as in other rendering modes.
 

+ 0 - 1
Engine/Engine/GraphicsAPI.cpp

@@ -904,7 +904,6 @@ static void RegisterGraphics(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Graphics", "bool get_sm3Support() const", asMETHOD(Graphics, GetSM3Support), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_lightPrepassSupport() const", asMETHOD(Graphics, GetLightPrepassSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_deferredSupport() const", asMETHOD(Graphics, GetDeferredSupport), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Graphics", "bool get_hardwareDepthSupport() const", asMETHOD(Graphics, GetHardwareDepthSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareShadowSupport() const", asMETHOD(Graphics, GetHardwareShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void set_forceSM2(bool)", asMETHOD(Graphics, SetForceSM2), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_forceSM2() const", asMETHOD(Graphics, GetForceSM2), asCALL_THISCALL);

+ 0 - 5
Engine/Graphics/Batch.cpp

@@ -248,11 +248,6 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
         
         graphics->SetShaderParameter(VSP_VIEWRIGHTVECTOR, cameraWorldRotation * Vector3::RIGHT);
         graphics->SetShaderParameter(VSP_VIEWUPVECTOR, cameraWorldRotation * Vector3::UP);
-        
-        float farClip = camera_->GetFarClip();
-        float nearClip = camera_->GetNearClip();
-        Vector4 depthReconstruct(farClip / (farClip - nearClip), -nearClip / (farClip - nearClip), 0.0f, 0.0f);
-        graphics->SetShaderParameter(PSP_DEPTHRECONSTRUCT, depthReconstruct);
     }
     
     // Set viewport shader parameters

+ 10 - 60
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -183,10 +183,8 @@ Graphics::Graphics(Context* context) :
     vsync_(false),
     tripleBuffer_(false),
     deviceLost_(false),
-    systemDepthStencil_(false),
     lightPrepassSupport_(false),
     deferredSupport_(false),
-    hardwareDepthSupport_(false),
     hardwareShadowSupport_(false),
     streamOffsetSupport_(false),
     hasSM3_(false),
@@ -225,8 +223,7 @@ Graphics::~Graphics()
     }
     if (impl_->defaultDepthStencilSurface_)
     {
-        if (systemDepthStencil_)
-            impl_->defaultDepthStencilSurface_->Release();
+        impl_->defaultDepthStencilSurface_->Release();
         impl_->defaultDepthStencilSurface_ = 0;
     }
     if (impl_->device_)
@@ -361,9 +358,6 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool vsync, bool
         impl_->presentParams_.Windowed         = true;
     }
     
-    // Use AutoDepthStencil normally. However, if INTZ depth is available, create a depth texture instead
-    bool autoDepthStencil = multiSample > 1 || !hardwareDepthSupport_;
-    
     impl_->presentParams_.BackBufferWidth            = width;
     impl_->presentParams_.BackBufferHeight           = height;
     impl_->presentParams_.BackBufferCount            = tripleBuffer ? 2 : 1;
@@ -371,7 +365,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool vsync, bool
     impl_->presentParams_.MultiSampleQuality         = 0;
     impl_->presentParams_.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
     impl_->presentParams_.hDeviceWindow              = WIN_GetWindowHandle(impl_->window_);
-    impl_->presentParams_.EnableAutoDepthStencil     = autoDepthStencil ? TRUE : FALSE;
+    impl_->presentParams_.EnableAutoDepthStencil     = TRUE;
     impl_->presentParams_.AutoDepthStencilFormat     = D3DFMT_D24S8;
     impl_->presentParams_.Flags                      = 0;
     impl_->presentParams_.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
@@ -451,8 +445,6 @@ void Graphics::Close()
     {
         MutexLock lock(GetStaticMutex());
         
-        depthTexture_.Reset();
-        
         SDL_ShowCursor(SDL_TRUE);
         SDL_DestroyWindow(impl_->window_);
         impl_->window_ = 0;
@@ -1796,11 +1788,6 @@ RenderSurface* Graphics::GetRenderTarget(unsigned index) const
     return index < MAX_RENDERTARGETS ? renderTargets_[index] : 0;
 }
 
-Texture2D* Graphics::GetDepthTexture() const
-{
-    return depthTexture_;
-}
-
 unsigned Graphics::GetStreamFrequency(unsigned index) const
 {
     return index < MAX_VERTEX_STREAMS ? streamFrequencies_[index] : 0;
@@ -2184,32 +2171,13 @@ void Graphics::CheckFeatureSupport()
             hasSM3_ = true;
     }
     
-    // Check for readable hardware depth-stencil format (INTZ), light pre-pass and deferred rendering support
-    if (impl_->CheckFormatSupport((D3DFORMAT)MAKEFOURCC('I', 'N', 'T', 'Z'), D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE))
-    {
-        // Sampling INTZ buffer directly while also using it for depth test results in performance loss on ATI GPUs,
-        // so use INTZ buffer only with other vendors
-        if (impl_->adapterIdentifier_.VendorId != 0x1002)
-        {
-            hardwareDepthSupport_ = false;
-            lightPrepassSupport_ = true;
-            depthStencilFormat = MAKEFOURCC('I', 'N', 'T', 'Z');
-            if (impl_->deviceCaps_.NumSimultaneousRTs >= 3)
-                deferredSupport_ = true;
-        }
-    }
-    
-    if (!hardwareDepthSupport_)
+    // Check for light prepass and deferred rendering support
+    if (impl_->deviceCaps_.NumSimultaneousRTs >= 2 && impl_->CheckFormatSupport(D3DFMT_R32F, D3DUSAGE_RENDERTARGET,
+        D3DRTYPE_TEXTURE))
     {
-        // If hardware depth is not supported, must support 2 rendertargets and R32F format for light pre-pass,
-        // and 4 for deferred rendering
-        if (impl_->deviceCaps_.NumSimultaneousRTs >= 2 && impl_->CheckFormatSupport(D3DFMT_R32F, D3DUSAGE_RENDERTARGET,
-            D3DRTYPE_TEXTURE))
-        {
-            lightPrepassSupport_ = true;
-            if (impl_->deviceCaps_.NumSimultaneousRTs >= 4)
-                deferredSupport_ = true;
-        }
+        lightPrepassSupport_ = true;
+        if (impl_->deviceCaps_.NumSimultaneousRTs >= 4)
+            deferredSupport_ = true;
     }
     
     // Check for stream offset (needed for instancing)
@@ -2241,8 +2209,7 @@ void Graphics::OnDeviceLost()
     }
     if (impl_->defaultDepthStencilSurface_)
     {
-        if (systemDepthStencil_)
-            impl_->defaultDepthStencilSurface_->Release();
+        impl_->defaultDepthStencilSurface_->Release();
         impl_->defaultDepthStencilSurface_ = 0;
     }
     
@@ -2257,24 +2224,7 @@ void Graphics::OnDeviceReset()
     
     // Get default surfaces
     impl_->device_->GetRenderTarget(0, &impl_->defaultColorSurface_);
-    if (impl_->presentParams_.EnableAutoDepthStencil)
-    {
-        impl_->device_->GetDepthStencilSurface(&impl_->defaultDepthStencilSurface_);
-        systemDepthStencil_ = true;
-    }
-    else
-    {
-        if (!depthTexture_)
-            depthTexture_ = new Texture2D(context_);
-        
-        depthTexture_->SetSize(width_, height_, (D3DFORMAT)MAKEFOURCC('I', 'N', 'T', 'Z'), TEXTURE_DEPTHSTENCIL);
-        
-        impl_->defaultDepthStencilSurface_ = (IDirect3DSurface9*)depthTexture_->GetRenderSurface()->GetSurface();
-        systemDepthStencil_ = false;
-        
-        // When AutoDepthStencil is not used, depth buffering must be enabled manually
-        impl_->device_->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
-    }
+    impl_->device_->GetDepthStencilSurface(&impl_->defaultDepthStencilSurface_);
     
     ResetCachedState();
 }

+ 0 - 10
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -237,8 +237,6 @@ public:
     bool GetLightPrepassSupport() const { return lightPrepassSupport_; }
     /// Return whether deferred rendering is supported.
     bool GetDeferredSupport() const { return deferredSupport_; }
-    /// Return whether hardware depth can be read as a texture.
-    bool GetHardwareDepthSupport() const { return hardwareDepthSupport_; }
     /// Return whether shadow map depth compare is done in hardware.
     bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
     /// Return whether stream offset is supported.
@@ -269,8 +267,6 @@ public:
     RenderSurface* GetRenderTarget(unsigned index) const;
     /// Return current depth-stencil surface.
     RenderSurface* GetDepthStencil() const { return depthStencil_; }
-    /// Return backbuffer depth-stencil texture, created if available.
-    Texture2D* GetDepthTexture() const;
     /// Return the viewport coordinates.
     IntRect GetViewport() const { return viewport_; }
     /// Return texture anisotropy.
@@ -408,14 +404,10 @@ private:
     bool tripleBuffer_;
     /// Direct3D device lost flag.
     bool deviceLost_;
-    /// System depth-stencil flag.
-    bool systemDepthStencil_;
     /// Light pre-pass rendering support flag.
     bool lightPrepassSupport_;
     /// Deferred rendering support flag.
     bool deferredSupport_;
-    /// Hardware depth texture support flag.
-    bool hardwareDepthSupport_;
     /// Hardware shadow map depth compare support flag.
     bool hardwareShadowSupport_;
     /// Stream offset support flag.
@@ -466,8 +458,6 @@ private:
     RenderSurface* renderTargets_[MAX_RENDERTARGETS];
     /// Depth-stencil surface in use.
     RenderSurface* depthStencil_;
-    /// Backbuffer depth-stencil texture.
-    SharedPtr<Texture2D> depthTexture_;
     /// View texture.
     Texture* viewTexture_;
     /// Viewport coordinates.

+ 0 - 1
Engine/Graphics/GraphicsDefs.cpp

@@ -50,7 +50,6 @@ StringHash VSP_LIGHTMATRICES("LightMatrices");
 StringHash VSP_SKINMATRICES("SkinMatrices");
 StringHash VSP_VERTEXLIGHTS("VertexLights");
 StringHash PSP_AMBIENTCOLOR("AmbientColor");
-StringHash PSP_DEPTHRECONSTRUCT("DepthReconstruct");
 StringHash PSP_FOGCOLOR("FogColor");
 StringHash PSP_FOGPARAMS("FogParams");
 StringHash PSP_GBUFFERINVSIZE("GBufferInvSize");

+ 0 - 1
Engine/Graphics/GraphicsDefs.h

@@ -232,7 +232,6 @@ extern StringHash VSP_LIGHTMATRICES;
 extern StringHash VSP_SKINMATRICES;
 extern StringHash VSP_VERTEXLIGHTS;
 extern StringHash PSP_AMBIENTCOLOR;
-extern StringHash PSP_DEPTHRECONSTRUCT;
 extern StringHash PSP_FOGCOLOR;
 extern StringHash PSP_FOGPARAMS;
 extern StringHash PSP_GBUFFERINVSIZE;

+ 5 - 35
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -162,7 +162,6 @@ Graphics::Graphics(Context* context_) :
     tripleBuffer_(false),
     lightPrepassSupport_(false),
     deferredSupport_(false),
-    hardwareDepthSupport_(false),
     anisotropySupport_(false),
     dxtTextureSupport_(false),
     etcTextureSupport_(false),
@@ -2145,45 +2144,17 @@ void Graphics::CheckFeatureSupport()
     // Check supported features: light pre-pass, deferred rendering and hardware depth texture
     lightPrepassSupport_ = false;
     deferredSupport_ = false;
-    hardwareDepthSupport_ = false;
     
     int numSupportedRTs = 1;
     
     #ifndef GL_ES_VERSION_2_0
     glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &numSupportedRTs);
     
-    // For now hardware depth texture is only tested for on NVIDIA hardware because of visual artifacts and slowdown on ATI
-    String vendorString = String((const char*)glGetString(GL_VENDOR)).ToUpper();
-    if (vendorString.Find("NVIDIA") != String::NPOS)
-    {
-        SharedPtr<Texture2D> depthTexture(new Texture2D(context_));
-        
-        hardwareDepthSupport_ = true;
-        // Note: Texture2D::SetSize() requires hardwareDepthSupport_ == true to create a texture instead of a renderbuffer
-        depthTexture->SetSize(256, 256, GetDepthStencilFormat(), TEXTURE_DEPTHSTENCIL);
-        SetDepthStencil(depthTexture);
-        
-        // If hardware depth textures work, this means also light pre-pass is automatically supported
-        if (CheckFramebuffer())
-        {
-            lightPrepassSupport_ = true;
-            if (numSupportedRTs >= 3)
-                deferredSupport_ = true;
-        }
-        else
-            hardwareDepthSupport_ = false;
-        
-        ResetDepthStencil();
-    }
-    
-    if (!hardwareDepthSupport_)
-    {
-        // If hardware depth is not supported, must support 2 rendertargets for light pre-pass, and 4 for deferred
-        if (numSupportedRTs >= 2)
-            lightPrepassSupport_ = true;
-        if (numSupportedRTs >= 4)
-            deferredSupport_ = true;
-    }
+    // If hardware depth is not supported, must support 2 rendertargets for light pre-pass, and 4 for deferred
+    if (numSupportedRTs >= 2)
+        lightPrepassSupport_ = true;
+    if (numSupportedRTs >= 4)
+        deferredSupport_ = true;
     #else
     if (!CheckExtension("GL_OES_depth_texture"))
     {
@@ -2194,7 +2165,6 @@ void Graphics::CheckFeatureSupport()
     {
         shadowMapFormat_ = GL_DEPTH_COMPONENT;
         hiresShadowMapFormat_ = 0;
-        hardwareDepthSupport_ = true;
     }
     #endif
 }

+ 0 - 4
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -246,8 +246,6 @@ public:
     bool GetLightPrepassSupport() const { return lightPrepassSupport_; }
     /// Return whether deferred rendering is supported.
     bool GetDeferredSupport() const { return deferredSupport_; }
-    /// Return whether hardware depth texture is supported. On OpenGL ES this means the depth texture extension.
-    bool GetHardwareDepthSupport() const { return hardwareDepthSupport_; }
     /// Return whether anisotropic texture filtering is supported.
     bool GetAnisotropySupport() const { return anisotropySupport_; }
     /// Return whether shadow map depth compare is done in hardware. Always true on OpenGL.
@@ -417,8 +415,6 @@ private:
     bool lightPrepassSupport_;
     /// Deferred rendering support flag.
     bool deferredSupport_;
-    /// Hardware depth support flag.
-    bool hardwareDepthSupport_;
     /// Anisotropic filtering support flag.
     bool anisotropySupport_;
     /// DXT format support flag.

+ 4 - 3
Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -411,11 +411,12 @@ bool Texture2D::Create()
     unsigned externalFormat = GetExternalFormat(format_);
     unsigned dataType = GetDataType(format_);
     
-    // Create a renderbuffer instead of a texture if depth texture is not properly supported
+    // Create a renderbuffer instead of a texture if depth texture is not properly supported, or if this will be a packed
+    // depth stencil texture
     #ifndef GL_ES_VERSION_2_0
-    if (!graphics_->GetHardwareDepthSupport() && format_ == Graphics::GetDepthStencilFormat())
+    if (format_ == Graphics::GetDepthStencilFormat())
     #else
-    if (!graphics_->GetHardwareDepthSupport() && externalFormat == GL_DEPTH_COMPONENT)
+    if (!graphics_->GetShadowMapFormat() && externalFormat == GL_DEPTH_COMPONENT)
     #endif
     {
         if (renderSurface_)

+ 3 - 30
Engine/Graphics/Renderer.cpp

@@ -187,12 +187,6 @@ static const String shadowVariations[] =
     #endif
 };
 
-static const String hwVariations[] =
-{
-    "",
-    "HW"
-};
-
 static const String geometryVSVariations[] =
 {
     "",
@@ -933,14 +927,6 @@ Texture2D* Renderer::GetScreenBuffer(int width, int height, unsigned format, boo
     if (filtered)
         searchKey |= 0x8000000000000000LL;
     
-    // Return the default depth-stencil if applicable (Direct3D9 only)
-    if (width <= graphics_->GetWidth() && height <= graphics_->GetHeight() && depthStencil)
-    {
-        Texture2D* depthTexture = graphics_->GetDepthTexture();
-        if (depthTexture)
-            return depthTexture;
-    }
-    
     // If new size or format, initialize the allocation stats
     if (screenBuffers_.Find(searchKey) == screenBuffers_.End())
         screenBufferAllocations_[searchKey] = 0;
@@ -1502,23 +1488,17 @@ void Renderer::LoadShaders()
         
         for (unsigned i = 0; i < lightPS_.Size(); ++i)
         {
-            String ortho, hwDepth;
-            #ifdef USE_OPENGL
-            hwDepth = hwVariations[graphics_->GetHardwareDepthSupport() ? 1 : 0];
-            #else
-            if (!graphics_->GetHardwareDepthSupport() && i < DLPS_ORTHO)
-                ortho = "Linear";
-            #endif
+            String ortho;
             if (i >= DLPS_ORTHO)
                 ortho = "Ortho";
             
             if (i & DLPS_SHADOW)
             {
                 lightPS_[i] = GetPixelShader(shaderName + ortho + lightPSVariations[i % DLPS_ORTHO] +
-                    shadowVariations[shadows] + hwDepth);
+                    shadowVariations[shadows]);
             }
             else
-                lightPS_[i] = GetPixelShader(shaderName + ortho + lightPSVariations[i % DLPS_ORTHO] + hwDepth);
+                lightPS_[i] = GetPixelShader(shaderName + ortho + lightPSVariations[i % DLPS_ORTHO]);
         }
     }
     
@@ -1563,13 +1543,6 @@ void Renderer::LoadPassShaders(Technique* tech, PassType type)
     if (pixelShaderName.Find('_') == String::NPOS)
         pixelShaderName += "_";
     
-    // If hardware depth is used, choose a G-buffer shader that does not write depth manually
-    if (type == PASS_PREPASS || type == PASS_DEFERRED)
-    {
-        unsigned hwDepth = graphics_->GetHardwareDepthSupport() ? 1 : 0;
-        pixelShaderName += hwVariations[hwDepth];
-    }
-    
     Vector<SharedPtr<ShaderVariation> >& vertexShaders = pass->GetVertexShaders();
     Vector<SharedPtr<ShaderVariation> >& pixelShaders = pass->GetPixelShaders();
     

+ 4 - 8
Engine/Graphics/View.cpp

@@ -1288,29 +1288,25 @@ void View::RenderBatchesDeferred()
         }
     }
     
-    bool hwDepth = graphics_->GetHardwareDepthSupport();
     // In light prepass mode the albedo buffer is used for light accumulation instead
     Texture2D* albedoBuffer = renderer_->GetScreenBuffer(rtSize_.x_, rtSize_.y_, Graphics::GetRGBAFormat());
     Texture2D* normalBuffer = renderer_->GetScreenBuffer(rtSize_.x_, rtSize_.y_, Graphics::GetRGBAFormat());
-    Texture2D* depthBuffer = renderer_->GetScreenBuffer(rtSize_.x_, rtSize_.y_, hwDepth ? Graphics::GetDepthStencilFormat() :
-        Graphics::GetLinearDepthFormat());
+    Texture2D* depthBuffer = renderer_->GetScreenBuffer(rtSize_.x_, rtSize_.y_, Graphics::GetLinearDepthFormat());
     
     RenderSurface* renderTarget = screenBuffers_.Size() ? screenBuffers_[0]->GetRenderSurface() : renderTarget_;
-    RenderSurface* depthStencil = hwDepth ? depthBuffer->GetRenderSurface() : renderer_->GetDepthStencil(rtSize_.x_, rtSize_.y_);
+    RenderSurface* depthStencil = renderer_->GetDepthStencil(rtSize_.x_, rtSize_.y_);
     
     if (renderMode_ == RENDER_PREPASS)
     {
         graphics_->SetRenderTarget(0, normalBuffer);
-        if (!hwDepth)
-            graphics_->SetRenderTarget(1, depthBuffer);
+        graphics_->SetRenderTarget(1, depthBuffer);
     }
     else
     {
         graphics_->SetRenderTarget(0, renderTarget);
         graphics_->SetRenderTarget(1, albedoBuffer);
         graphics_->SetRenderTarget(2, normalBuffer);
-        if (!hwDepth)
-            graphics_->SetRenderTarget(3, depthBuffer);
+        graphics_->SetRenderTarget(3, depthBuffer);
     }
     
     graphics_->SetDepthStencil(depthStencil);