2#include <engine/engine_export.h>
18struct shadow_cutout_state;
81 virtual auto
get_render_states(
bool apply_cull = true,
bool depth_write = true,
bool depth_test = true) const
116 auto clone()
const -> std::shared_ptr<material>
override;
142 return subsurface_color_;
151 subsurface_color_ = val;
160 return emissive_color_;
169 emissive_color_ = val;
174 return emissive_intensity_;
179 emissive_intensity_ = val;
188 return surface_data_.x;
197 surface_data_.x = roughness;
206 return surface_data_.y;
215 surface_data_.y = metalness;
224 return surface_data_.z;
233 surface_data_.z = bumpiness;
254 return alpha_cutoff_;
260 void set_alpha_cutoff(
float cutoff);
263 [[nodiscard]]
auto uses_alpha_cutout() const ->
bool;
266 [[nodiscard]] auto casts_shadow() const ->
bool;
272 void infer_alpha_mode_from_legacy_cutoff();
278 auto get_surface_data() const -> const
math::vec4&
280 return surface_data_;
289 math::vec4 surface_data2{};
291 surface_data2[0] = metalness_roughness_combined() ? 1.0f : 0.0f;
293 const auto normal_texture = normal_map.get();
297 return surface_data2;
302 return metalness_map_ == roughness_map_;
329 return dither_threshold_;
338 dither_threshold_ = threshold;
383 return roughness_map_;
392 roughness_map_ = val;
401 return metalness_map_;
410 metalness_map_ = val;
437 return emissive_map_;
450 void sync_surface_alpha_channel();
474 float emissive_intensity_{1.0f};
476 float alpha_cutoff_{0.5f};
478 math::vec4 surface_data_{
490 math::vec2 dither_threshold_{
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::weak_ptr< material > wptr
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.
std::unique_ptr< material > uptr
auto get_cull_type() const -> cull_type
Gets the culling type of the material.
virtual auto clone() const -> material::sptr
Clones a materiial.
Class for physically-based rendering (PBR) materials.
auto get_surface_data2() const -> math::vec4
Gets additional surface data for the material.
auto get_alpha_mode() const -> alpha_mode
Gets the alpha mode (opaque / mask / blend).
auto get_dither_threshold() const -> const math::vec2 &
Gets the dither threshold of the material.
auto get_emissive_map() const -> const asset_handle< gfx::texture > &
Gets the emissive map of the material.
void set_subsurface_color(const math::color &val)
Sets the subsurface color of the material.
void set_roughness_map(const asset_handle< gfx::texture > &val)
Sets the roughness map of the material.
void set_base_color(const math::color &val)
Sets the base color of the material.
auto metalness_roughness_combined() const -> bool
auto get_emissive_intensity() const -> float
auto get_subsurface_color() const -> const math::color &
Gets the subsurface color of the material.
void set_color_map(const asset_handle< gfx::texture > &val)
Sets the color map of the material.
void set_ao_map(const asset_handle< gfx::texture > &val)
Sets the ambient occlusion map of the material.
auto get_color_map() const -> const asset_handle< gfx::texture > &
Gets the color map of the material.
auto get_bumpiness() const -> float
Gets the bumpiness of the material.
void set_emissive_intensity(float val)
auto get_roughness() const -> float
Gets the roughness of the material.
auto get_metalness() const -> float
Gets the metalness of the material.
void set_dither_threshold(const math::vec2 &threshold)
Sets the dither threshold of the material.
auto get_alpha_cutoff() const -> float
Gets the alpha cutoff used when alpha_mode is alpha_mode::mask.
void set_bumpiness(float bumpiness)
Sets the bumpiness of the material.
void set_emissive_map(const asset_handle< gfx::texture > &val)
Sets the emissive map of the material.
void set_normal_map(const asset_handle< gfx::texture > &val)
Sets the normal map of the material.
auto get_roughness_map() const -> const asset_handle< gfx::texture > &
Gets the roughness map of the material.
void set_emissive_color(const math::color &val)
Sets the emissive color of the material.
auto get_metalness_map() const -> const asset_handle< gfx::texture > &
Gets the metalness map of the material.
auto get_tiling() const -> const math::vec2 &
Gets the tiling factor of the material.
auto get_normal_map() const -> const asset_handle< gfx::texture > &
Gets the normal map of the material.
void set_metalness_map(const asset_handle< gfx::texture > &val)
Sets the metalness map of the material.
void set_tiling(const math::vec2 &tiling)
Sets the tiling factor of the material.
void set_roughness(float roughness)
Sets the roughness of the material.
void set_metalness(float metalness)
Sets the metalness of the material.
auto get_base_color() const -> const math::color &
Gets the base color of the material.
auto get_emissive_color() const -> const math::color &
Gets the emissive color of the material.
auto get_ao_map() const -> const asset_handle< gfx::texture > &
Gets the ambient occlusion map of the material.
auto normal_map_needs_z_reconstruction(texture_format fmt) -> bool
Hash specialization for batch_key to enable use in std::unordered_map.
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.
std::vector< math::color > color
Thread-safe handle to an asset.
Per-draw state for alpha-cutout shadow batches (texture + clip threshold).