16constexpr float k_deferred_dither_alpha = 0.25f;
17constexpr float k_legacy_opaque_cutoff_sentinel = 0.25f;
22 auto mat = std::make_shared<material>(*
this);
56 uint64_t states = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_MSAA;
60 states |= BGFX_STATE_WRITE_Z;
65 states |= BGFX_STATE_DEPTH_TEST_LESS;
73 states |= BGFX_STATE_CULL_CCW;
77 states |= BGFX_STATE_CULL_CW;
87 auto mat = std::make_shared<pbr_material>(*
this);
94 sync_surface_alpha_channel();
99 alpha_cutoff_ = std::clamp(cutoff, 0.0f, 1.0f);
102 alpha_cutoff_ = 0.5f;
104 sync_surface_alpha_channel();
107void pbr_material::sync_surface_alpha_channel()
109 surface_data_.w = alpha_mode_ ==
alpha_mode::mask ? alpha_cutoff_ : k_deferred_dither_alpha;
126 const auto& albedo = color_map ? color_map : default_color_map();
136 if(std::abs(alpha_cutoff_ - k_legacy_opaque_cutoff_sentinel) > 0.001f
137 || std::abs(surface_data_.w - k_legacy_opaque_cutoff_sentinel) > 0.001f)
139 if(std::abs(alpha_cutoff_ - k_legacy_opaque_cutoff_sentinel) <= 0.001f)
141 alpha_cutoff_ = surface_data_.w;
Class representing a GPU program.
Base class for materials used in rendering.
static auto default_normal_map() -> asset_handle< gfx::texture > &
Gets the default normal map.
static auto default_color_map() -> asset_handle< gfx::texture > &
Gets the default color map.
std::shared_ptr< material > sptr
void set_cull_type(cull_type val)
Sets the culling type of the material.
virtual auto submit(gpu_program *program) const -> bool
Submits the material properties to the GPU program.
virtual auto get_render_states(bool apply_cull=true, bool depth_write=true, bool depth_test=true) const -> uint64_t
Gets the render states for the material.
cull_type cull_type_
< The culling type for this material.
auto get_cull_type() const -> cull_type
Gets the culling type of the material.
virtual auto clone() const -> material::sptr
Clones a materiial.
auto make_shadow_cutout_state() const -> shadow_cutout_state
Snapshot of shader state needed by the shadow cutout pass.
auto get_color_map() const -> const asset_handle< gfx::texture > &
Gets the color map of the material.
void infer_alpha_mode_from_legacy_cutoff()
Infer alpha_mode when loading legacy assets that only stored a cutoff value.
auto casts_shadow() const -> bool
True when this material should contribute to shadow maps.
auto uses_alpha_cutout() const -> bool
True when alpha_mode is alpha_mode::mask (hard alpha clip + cutout shadows).
auto clone() const -> std::shared_ptr< material > override
auto get_tiling() const -> const math::vec2 &
Gets the tiling factor of the material.
void set_alpha_mode(alpha_mode mode)
Sets the alpha mode.
void set_alpha_cutoff(float cutoff)
Sets the alpha cutoff for alpha_mode::mask materials.
auto get_base_color() const -> const math::color &
Gets the base color of the material.
cull_type
Enum representing the type of culling to be used.
@ counter_clockwise
Cull counter-clockwise faces.
@ clockwise
Cull clockwise faces.
alpha_mode
glTF-aligned surface alpha behavior (default: opaque).
@ opaque
No alpha clip; casts solid shadows.
@ blend
Transparent (lit pass); does not cast shadows.
@ mask
Hard alpha cutoff; casts cutout shadows.
Thread-safe handle to an asset.
Per-draw state for alpha-cutout shadow batches (texture + clip threshold).
std::shared_ptr< gfx::texture > color_map