mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 10:29:19 +02:00
add depth prepass in preparation for moving from deferred back to forward renderer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user