Skip to content

Commit

Permalink
[light] depth pass now uses the same vertex struct as the depth pre p…
Browse files Browse the repository at this point in the history
…ass and the gbuffer
  • Loading branch information
PanosK92 committed Oct 25, 2024
1 parent 455d790 commit 5b70f8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion data/shaders/common_vertex_processing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ gbuffer_vertex transform_to_world_space(Vertex_PosUvNorTan input, uint instance_

// compute uv
Material material = GetMaterial();
vertex.uv = float2(input.uv.x * material.tiling.x + material.offset.x, input.uv.y * material.tiling.y + material.offset.y);
vertex.uv = float2(input.uv.x * material.tiling.x + material.offset.x, input.uv.y * material.tiling.y + material.offset.y);

// compute the final world transform
bool is_instanced = instance_id != 0; // not ideal as you can have instancing with instance_id = 0, however it's very performant branching due to predictability
Expand Down
22 changes: 6 additions & 16 deletions data/shaders/depth_light.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,27 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common.hlsl"
//====================

struct vertex
gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID)
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD;
};

vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID)
{
vertex output;
output.uv = input.uv;

float3 f3_value_2 = pass_get_f3_value2();
uint index_array = (uint)f3_value_2.y;

Light light;
light.Build();

gbuffer_vertex vertex = transform_to_world_space(input, instance_id, buffer_pass.transform);
output.position = mul(float4(vertex.position, 1.0f), light.transform[index_array]);
vertex.position_clip = mul(float4(vertex.position, 1.0f), light.transform[index_array]);

// for point lights, output.position is in view space this because we do the paraboloid projection here
if (light.is_point())
{
float3 ndc = project_onto_paraboloid(output.position.xyz, light.near, light.far);
output.position = float4(ndc, 1.0);
float3 ndc = project_onto_paraboloid(vertex.position.xyz, light.near, light.far);
vertex.position_clip = float4(ndc, 1.0f);
}

return output;
return vertex;
}

float4 main_ps(vertex input) : SV_Target0
float4 main_ps(gbuffer_vertex input) : SV_Target0
{
// alpha test
const float3 f3_value = pass_get_f3_value();
Expand Down
8 changes: 4 additions & 4 deletions runtime/RHI/RHI_DepthStencilState.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ namespace Spartan
const RHI_Comparison_Function depth_comparison_function = RHI_Comparison_Function::LessEqual,
const bool stencil_test = false,
const bool stencil_write = false,
const RHI_Comparison_Function stencil_comparison_function = RHI_Comparison_Function::Always,
const RHI_Stencil_Operation stencil_fail_op = RHI_Stencil_Operation::Keep,
const RHI_Stencil_Operation stencil_depth_fail_op = RHI_Stencil_Operation::Keep,
const RHI_Stencil_Operation stencil_pass_op = RHI_Stencil_Operation::Replace
const RHI_Comparison_Function stencil_comparison_function = RHI_Comparison_Function::Never,
const RHI_Stencil_Operation stencil_fail_op = RHI_Stencil_Operation::Zero,
const RHI_Stencil_Operation stencil_depth_fail_op = RHI_Stencil_Operation::Zero,
const RHI_Stencil_Operation stencil_pass_op = RHI_Stencil_Operation::Zero
);
~RHI_DepthStencilState();

Expand Down

0 comments on commit 5b70f8b

Please sign in to comment.