Skip to content

Commit

Permalink
[renderer] minor performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Dec 11, 2024
1 parent dfca8ae commit 18502be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions data/shaders/depth_prepass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceI
{
gbuffer_vertex vertex = transform_to_world_space(input, instance_id, buffer_pass.transform);

Surface surface;
surface.flags = GetMaterial().flags;
if (!surface.is_tessellated())
const bool is_tesselated = pass_get_f3_value().x == 1.0f;
if (!is_tesselated)
{
vertex = transform_to_clip_space(vertex);
}
Expand All @@ -39,7 +38,7 @@ gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceI

void main_ps(gbuffer_vertex vertex)
{
const bool has_albedo = pass_get_f3_value().x == 1.0f;
const bool has_albedo = pass_get_f3_value().y == 1.0f;
const float alpha_threshold = get_alpha_threshold(vertex.position); // distance based alpha threshold

if (has_albedo && GET_TEXTURE(material_texture_index_albedo).Sample(samplers[sampler_anisotropic_wrap], vertex.uv).a <= alpha_threshold)
Expand Down
6 changes: 4 additions & 2 deletions runtime/Rendering/Renderer_Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ namespace Spartan
{
pso.shaders[RHI_Shader_Type::Hull] = is_tessellated ? shader_h : nullptr;
pso.shaders[RHI_Shader_Type::Domain] = is_tessellated ? shader_d : nullptr;
set_pipeline = true;
set_pipeline = true;
}
}

Expand All @@ -702,7 +702,9 @@ namespace Spartan
{
if (Material* material = renderable->GetMaterial())
{
m_pcb_pass_cpu.set_f3_value(material->HasTextureOfType(MaterialTextureType::Color) ? 1.0f : 0.0f); // alpha testing
bool is_tesselated = material->IsTessellated();
bool has_color_texture = material->HasTextureOfType(MaterialTextureType::Color);
m_pcb_pass_cpu.set_f3_value(is_tesselated ? 1.0f : 0.0f, has_color_texture ? 1.0f : 0.0f);
m_pcb_pass_cpu.set_is_transparent_and_material_index(is_transparent_pass, material->GetIndex());
}

Expand Down

0 comments on commit 18502be

Please sign in to comment.