Lasse Öörni 14 лет назад
Родитель
Сommit
8de93e90ad

+ 7 - 10
Engine/Graphics/View.cpp

@@ -1015,22 +1015,19 @@ void View::RenderBatchesLightPrepass()
     if (graphics_->GetHardwareDepthSupport())
     {
         depthStencil = depthBuffer->GetRenderSurface();
-        
         graphics_->SetRenderTarget(0, normalBuffer);
-        graphics_->SetDepthStencil(depthStencil);
-        graphics_->SetViewport(screenRect_);
-        graphics_->Clear(CLEAR_DEPTH | CLEAR_STENCIL);
     }
-    // No hardware depth support: render to R32F depth and RGBA normal buffers
+    // No hardware depth support: render to RGBA normal buffer and R32F depth
     else
     {
-        graphics_->SetRenderTarget(0, depthBuffer);
-        graphics_->SetRenderTarget(1, normalBuffer);
-        graphics_->SetDepthStencil(depthStencil);
-        graphics_->SetViewport(screenRect_);
-        graphics_->Clear(CLEAR_DEPTH | CLEAR_STENCIL);
+        graphics_->SetRenderTarget(0, normalBuffer);
+        graphics_->SetRenderTarget(1, depthBuffer);
     }
     
+    graphics_->SetDepthStencil(depthStencil);
+    graphics_->SetViewport(screenRect_);
+    graphics_->Clear(CLEAR_DEPTH | CLEAR_STENCIL);
+    
     if (!gbufferQueue_.IsEmpty())
     {
         // Render G-buffer batches

+ 11 - 18
SourceAssets/HLSLShaders/GBuffer.hlsl

@@ -55,12 +55,10 @@ void PS(
     #else
         float3 iNormal : TEXCOORD2,
     #endif
-    #if !defined(HWDEPTH) && !defined(FALLBACK)
-        out float4 oDepth : COLOR0,
-        out float4 oNormal : COLOR1)
-    #else
-        out float4 oNormal : COLOR0)
+    #ifndef HWDEPTH
+        out float4 oDepth : COLOR1,
     #endif
+    out float4 oNormal : COLOR0)
 {
     #ifdef ALPHAMASK
         float4 diffInput = tex2D(sDiffMap, iTexCoord);
@@ -75,20 +73,15 @@ void PS(
         float3 normal = normalize(iNormal);
     #endif
 
-    #ifdef FALLBACK
-        // Fallback mode uses 15-bit linear depth
-        oNormal = PackNormalDepth(normal, iDepth.x);
+    #ifdef SPECMAP
+        float specStrength = tex2D(sSpecMap, iTexCoord).r * cMatSpecProperties.x;
     #else
-        #ifdef SPECMAP
-            float specStrength = tex2D(sSpecMap, iTexCoord).r * cMatSpecProperties.x;
-        #else
-            float specStrength = cMatSpecProperties.x;
-        #endif
-        float specPower = cMatSpecProperties.y / 255.0;
+        float specStrength = cMatSpecProperties.x;
+    #endif
+    float specPower = cMatSpecProperties.y / 255.0;
 
-        oNormal = float4(normal * 0.5 + 0.5, specPower);
-        #ifndef HWDEPTH
-            oDepth = iDepth;
-        #endif
+    oNormal = float4(normal * 0.5 + 0.5, specPower);
+    #ifndef HWDEPTH
+        oDepth = iDepth;
     #endif
 }

+ 1 - 2
SourceAssets/HLSLShaders/GBuffer.xml

@@ -10,7 +10,6 @@
         <option name="Normal" define="NORMALMAP" />
         <option name="Spec" define="SPECMAP" />
         <option name="Mask" define="ALPHAMASK" />
-        <option name="HW" define="HWDEPTH" exclude="FB" />
-        <option name="FB" define="FALLBACK" exclude="HW" />
+        <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 24 - 44
SourceAssets/HLSLShaders/LightVolume.hlsl

@@ -47,60 +47,40 @@ void PS(
     out float4 oColor : COLOR0)
 {
     // If rendering a directional light quad, optimize out the w divide
-    #ifndef FALLBACK
-        #ifdef DIRLIGHT
-            #ifdef ORTHO
+    #ifdef DIRLIGHT
+        #ifdef ORTHO
+            float depth = Sample(sDepthBuffer, iScreenPos).r;
+            float3 worldPos = lerp(iNearRay, iFarRay, depth);
+        #else
+            #ifdef LINEAR
                 float depth = Sample(sDepthBuffer, iScreenPos).r;
-                float3 worldPos = lerp(iNearRay, iFarRay, depth);
             #else
-                #ifdef LINEAR
-                    float depth = Sample(sDepthBuffer, iScreenPos).r;
-                #else
-                    float depth = ReconstructDepth(Sample(sDepthBuffer, iScreenPos).r);
-                #endif
-                float3 worldPos = iFarRay * depth;
+                float depth = ReconstructDepth(Sample(sDepthBuffer, iScreenPos).r);
             #endif
-            float4 normalInput = Sample(sNormalBuffer, iScreenPos);
+            float3 worldPos = iFarRay * depth;
+        #endif
+        float4 normalInput = Sample(sNormalBuffer, iScreenPos);
+    #else
+        #ifdef ORTHO
+            float depth = tex2Dproj(sDepthBuffer, iScreenPos).r;
+            float3 worldPos = lerp(iNearRay, iFarRay, depth) / iScreenPos.w;
         #else
-            #ifdef ORTHO
+            #ifdef LINEAR
                 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
-                float3 worldPos = iFarRay * depth / iScreenPos.w;
+                float depth = ReconstructDepth(tex2Dproj(sDepthBuffer, iScreenPos).r);
             #endif
-            float4 normalInput = tex2Dproj(sNormalBuffer, iScreenPos);
+            float3 worldPos = iFarRay * depth / iScreenPos.w;
         #endif
+        float4 normalInput = tex2Dproj(sNormalBuffer, iScreenPos);
+    #endif
 
-        // With specular, normalization greatly improves stability of reflections,
-        // considering input is only 8 bits per axis
-        #ifdef SPECULAR
-            float3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
-        #else
-            float3 normal = normalInput.rgb * 2.0 - 1.0;
-        #endif
+    // With specular, normalization greatly improves stability of reflections,
+    // considering input is only 8 bits per axis
+    #ifdef SPECULAR
+        float3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
     #else
-        float3 normal;
-        float depth;
-        #ifdef DIRLIGHT
-            UnpackNormalDepth(Sample(sNormalBuffer, iScreenPos), normal, depth);
-            #ifdef ORTHO
-                float3 worldPos = lerp(iNearRay, iFarRay, depth);
-            #else
-                float3 worldPos = iFarRay * depth;
-            #endif
-        #else
-            UnpackNormalDepth(tex2Dproj(sNormalBuffer, iScreenPos), normal, depth);
-            #ifdef ORTHO
-                float3 worldPos = lerp(iNearRay, iFarRay, depth) / iScreenPos.w;
-            #else
-                float3 worldPos = iFarRay * depth / iScreenPos.w;
-            #endif
-        #endif
+        float3 normal = normalInput.rgb * 2.0 - 1.0;
     #endif
 
     float4 projWorldPos = float4(worldPos, 1.0);

+ 0 - 24
SourceAssets/HLSLShaders/Samplers.hlsl

@@ -51,30 +51,6 @@ float3 DecodeNormal(float4 normalInput)
     return normal;
 }
 
-float4 PackNormalDepth(float3 normal, float depth)
-{
-    float4 ret;
-    ret.xy = normal.xz * 0.5 + 0.5;
-    ret.z = (floor(depth * 127.0) + (normal.y < 0.0) * 128.0) * (1.0 / 255.0);
-    ret.w = frac(depth * 127.0);
-    return ret;
-}
-
-void UnpackNormalDepth(float4 input, out float3 normal, out float depth)
-{
-    normal.xz = input.xy * 2.0 - 1.0;
-    normal.y = sqrt(1.0 - dot(normal.xz, normal.xz));
-
-    float hiDepth = input.z * 255.0;
-    if (hiDepth > 127.0)
-    {
-        hiDepth -= 128.0;
-        normal.y = -normal.y;
-    }
-
-    depth = (hiDepth + input.w) * (1.0 / 127.0);
-}
-
 float ReconstructDepth(float hwDepth)
 {
     return cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x);