16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00

add depth prepass in preparation for moving from deferred back to forward renderer

This commit is contained in:
Wls50
2025-11-23 09:19:44 +01:00
committed by Hirek
parent 915e4c769e
commit 593a8a288f
10 changed files with 201 additions and 53 deletions

View File

@@ -7,6 +7,12 @@ struct VertexInput {
float4 m_Tangent : Tangent;
};
#ifdef PREPASS
struct VertexOutput {
float2 m_TexCoord : TexCoord;
float4 m_PositionSV : SV_Position;
};
#else
struct VertexOutput {
float3 m_Position : Position;
float3 m_Normal : Normal;
@@ -16,6 +22,7 @@ struct VertexOutput {
float4 m_PositionCS : PositionCS;
float4 m_HistoryPositionCS : HistoryPositionCS;
};
#endif
cbuffer VertexConstants : register(b0) {
float4x4 g_JitteredProjection;
@@ -29,14 +36,17 @@ VertexOutput main(in VertexInput vs_in) {
VertexOutput result;
float4x3 model_view = GetModelView();
float4x3 model_view_history = GetModelViewHistory();
result.m_Position = mul(float4(vs_in.m_Position, 1.), model_view).xyz;
result.m_Normal = mul(float4(vs_in.m_Normal, 0.), model_view).xyz;
float3 view_space_position = mul(float4(vs_in.m_Position, 1.), model_view).xyz;
result.m_TexCoord = vs_in.m_TexCoord;
result.m_PositionSV = mul(g_JitteredProjection, float4(view_space_position, 1.));
#ifndef PREPASS
result.m_Normal = mul(float4(vs_in.m_Normal, 0.), model_view).xyz;
result.m_Position = view_space_position;
result.m_Tangent.xyz = mul(float4(vs_in.m_Tangent.xyz, 0.), model_view).xyz;
result.m_Tangent.w = vs_in.m_Tangent.w;
result.m_PositionSV = mul(g_JitteredProjection, float4(result.m_Position, 1.));
result.m_PositionCS = mul(g_Projection, float4(result.m_Position, 1.));
float3 history_position = mul(float4(vs_in.m_Position, 1.), model_view_history);
result.m_HistoryPositionCS = mul(g_ProjectionHistory, float4(history_position, 1.));
#endif
return result;
}

View File

@@ -8,6 +8,12 @@ struct VertexInput {
float4 m_InstanceTransform[3] : InstanceTransform;
};
#ifdef PREPASS
struct VertexOutput {
float2 m_TexCoord : TexCoord;
float4 m_PositionSV : SV_Position;
};
#else
struct VertexOutput {
float3 m_Position : Position;
float3 m_Normal : Normal;
@@ -17,6 +23,7 @@ struct VertexOutput {
float4 m_PositionCS : PositionCS;
float4 m_HistoryPositionCS : HistoryPositionCS;
};
#endif
cbuffer VertexConstants : register(b0) {
float4x4 g_JitteredProjection;
@@ -32,14 +39,17 @@ VertexOutput main(in VertexInput vs_in) {
float4x3 model_view_history = GetModelViewHistory();
float4x4 instance_transform = transpose(float4x4(vs_in.m_InstanceTransform[0], vs_in.m_InstanceTransform[1], vs_in.m_InstanceTransform[2], float4(0., 0., 0., 1.)));
float3 position = mul(float4(vs_in.m_Position, 1.), instance_transform).xyz;
result.m_Position = mul(float4(position, 1.), model_view).xyz;
result.m_Normal = mul(mul(float4(vs_in.m_Normal, 0.), instance_transform), model_view);
float3 view_space_position = mul(float4(position, 1.), model_view).xyz;
result.m_PositionSV = mul(g_JitteredProjection, float4(view_space_position, 1.));
result.m_TexCoord = vs_in.m_TexCoord;
#ifndef PREPASS
result.m_Position = view_space_position;
result.m_Normal = mul(mul(float4(vs_in.m_Normal, 0.), instance_transform), model_view);
result.m_Tangent.xyz = mul(mul(float4(vs_in.m_Tangent.xyz, 0.), instance_transform), model_view);
result.m_Tangent.w = vs_in.m_Tangent.w;
result.m_PositionSV = mul(g_JitteredProjection, float4(result.m_Position, 1.));
result.m_PositionCS = mul(g_Projection, float4(result.m_Position, 1.));
float3 history_position = mul(float4(position, 1.), model_view_history).xyz;
result.m_HistoryPositionCS = mul(g_ProjectionHistory, float4(history_position, 1.));
#endif
return result;
}

View File

@@ -2,7 +2,9 @@
#define ALPHA_MASK_HLSLI
void AlphaMask(in float alpha) {
#if (PASS & FORWARD_LIGHTING) || defined (SHADOW)
if(g_DrawConstants.m_AlphaThreshold >= 0. ? (alpha < g_DrawConstants.m_AlphaThreshold) : (alpha >= -g_DrawConstants.m_AlphaThreshold)) discard;
#endif
}
#endif

View File

@@ -157,6 +157,12 @@ shaders:
source: ps_shadow_masked
target: pixel
entrypoint: main
prepass_masked:
source: ps_shadow_masked
target: pixel
entrypoint: main
definitions:
PREPASS: 1
# Contact shadows
# TODO Depth conversion is broken since converting to reversed depth buffer
contact_shadows:
@@ -173,6 +179,12 @@ shaders:
source: default_vertex
target: vertex
entrypoint: main
default_prepass_vertex:
source: default_vertex
target: vertex
entrypoint: main
definitions:
PREPASS: 1
shadow_vertex:
source: shadow_vertex
target: vertex
@@ -185,6 +197,12 @@ shaders:
source: instanced_vertex
target: vertex
entrypoint: main
instanced_prepass_vertex:
source: instanced_vertex
target: vertex
entrypoint: main
definitions:
PREPASS: 1
instanced_shadow_vertex:
source: instanced_shadow_vertex
target: vertex

View File

@@ -3,8 +3,13 @@
sampler diffuse_sampler : register(s0);
Texture2D diffuse : register(t0);
#ifdef PREPASS
#include "manul/draw_constants.hlsli"
#else
#include "manul/draw_constants_shadow.hlsli"
#endif
#define SHADOW
#include "manul/alpha_mask.hlsli"
struct VertexOutput {