Skip to content

Commit

Permalink
[Material] Introduced VertexAnimateWind flag, this will allow for sel…
Browse files Browse the repository at this point in the history
…ecting wind animation, say, the leafs of the tree but not its trunk
  • Loading branch information
PanosK92 committed Oct 24, 2023
1 parent 7007afd commit 1a83a1f
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 136 deletions.
5 changes: 3 additions & 2 deletions data/shaders/common_buffers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ bool has_texture_metalness() { return buffer_material.propertie
bool has_texture_alpha_mask() { return buffer_material.properties & uint(1U << 6); }
bool has_texture_emissive() { return buffer_material.properties & uint(1U << 7); }
bool has_texture_occlusion() { return buffer_material.properties & uint(1U << 8); }
bool material_slope_based() { return buffer_material.properties & uint(1U << 9); }
bool material_animate_uv() { return buffer_material.properties & uint(1U << 10); }
bool material_texture_slope_based() { return buffer_material.properties & uint(1U << 9); }
bool material_texture_animate() { return buffer_material.properties & uint(1U << 10); }
bool material_vertex_animate_wind() { return buffer_material.properties & uint(1U << 11); }

// lighting properties
bool light_is_directional() { return buffer_light.options & uint(1U << 0); }
Expand Down
6 changes: 3 additions & 3 deletions data/shaders/g_buffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ float4 sample_albedo(float2 uv, float slope)
{
float4 albedo = tex_material_albedo.Sample(samplers[sampler_anisotropic_wrap], uv);

if (material_slope_based())
if (material_texture_slope_based())
{
float4 tex_flat = albedo;
float4 tex_slope = tex_material_albedo_2.Sample(samplers[sampler_anisotropic_wrap], uv * 0.3f);
Expand All @@ -93,7 +93,7 @@ float3 smaple_normal(float2 uv, float slope)
{
float3 normal = tex_material_normal.Sample(samplers[sampler_anisotropic_wrap], uv).xyz;

if (material_slope_based())
if (material_texture_slope_based())
{
float3 tex_flat = normal;
float3 tex_slope = tex_material_normal2.Sample(samplers[sampler_anisotropic_wrap], uv * 0.3f).rgb;
Expand All @@ -113,7 +113,7 @@ PixelOutputType mainPS(PixelInputType input)
// uv
float2 uv = input.uv;
uv = float2(uv.x * buffer_material.tiling.x + buffer_material.offset.x, uv.y * buffer_material.tiling.y + buffer_material.offset.y);
uv += float(buffer_frame.frame * 0.001f) * material_animate_uv();
uv += float(buffer_frame.time * 0.001f) * material_texture_animate();

// parallax mapping
if (has_texture_height())
Expand Down
35 changes: 15 additions & 20 deletions editor/Widgets/Properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ void Properties::ShowRenderable(shared_ptr<Renderable> renderable) const
string name_mesh = mesh ? mesh->GetObjectName() : "N/A";
string name_material = material ? material->GetObjectName() : "N/A";
bool cast_shadows = renderable->GetCastShadows();
bool affected_by_wind = renderable->GetAffectedByWind();
//=====================================================================

// mesh
Expand Down Expand Up @@ -404,13 +403,9 @@ void Properties::ShowRenderable(shared_ptr<Renderable> renderable) const
ImGui::Text("Cast shadows");
ImGui::SameLine(column_pos_x); ImGui::Checkbox("##renderable_cast_shadows", &cast_shadows);

ImGui::Text("Affected by wind");
ImGui::SameLine(column_pos_x); ImGui::Checkbox("##renderable_affected_by_wind", &affected_by_wind);

//= MAP ==========================================================================================
//= MAP ===================================================================================
if (cast_shadows != renderable->GetCastShadows()) renderable->SetCastShadows(cast_shadows);
if (cast_shadows != renderable->GetCastShadows()) renderable->SetAffectedByWind(affected_by_wind);
//================================================================================================
//=========================================================================================
}
component_end();
}
Expand Down Expand Up @@ -663,13 +658,13 @@ void Properties::ShowMaterial(Material* material) const
{
//= REFLECT ===========================================
Math::Vector2 tiling = Vector2(
material->GetProperty(MaterialProperty::UvTilingX),
material->GetProperty(MaterialProperty::UvTilingY)
material->GetProperty(MaterialProperty::TextureTilingX),
material->GetProperty(MaterialProperty::TextureTilingY)
);

Math::Vector2 offset = Vector2(
material->GetProperty(MaterialProperty::UvOffsetX),
material->GetProperty(MaterialProperty::UvOffsetY)
material->GetProperty(MaterialProperty::TextureOffsetX),
material->GetProperty(MaterialProperty::TextureOffsetY)
);

m_material_color_picker->SetColor(Color(
Expand Down Expand Up @@ -747,7 +742,7 @@ void Properties::ShowMaterial(Material* material) const
ImGui::PushID(static_cast<int>(ImGui::GetCursorPosX() + ImGui::GetCursorPosY()));
float value = material->GetProperty(mat_property);

if (mat_property != MaterialProperty::MetalnessMultiplier)
if (mat_property != MaterialProperty::MultiplierMetalness)
{
ImGuiSp::draw_float_wrap("", &value, 0.004f, 0.0f, 1.0f);
}
Expand All @@ -771,10 +766,10 @@ void Properties::ShowMaterial(Material* material) const
show_property("Sheen", "Amount of soft velvet like reflection near edges", MaterialTexture::Undefined, MaterialProperty::Sheen);
show_property("Sheen tint", "Mix between white and using base color for sheen reflection", MaterialTexture::Undefined, MaterialProperty::SheenTint);
show_property("Color", "Surface color", MaterialTexture::Color, MaterialProperty::ColorTint);
show_property("Roughness", "Specifies microfacet roughness of the surface for diffuse and specular reflection", MaterialTexture::Roughness, MaterialProperty::RoughnessMultiplier);
show_property("Metalness", "Blends between a non-metallic and metallic material model", MaterialTexture::Metalness, MaterialProperty::MetalnessMultiplier);
show_property("Normal", "Controls the normals of the base layers", MaterialTexture::Normal, MaterialProperty::NormalMultiplier);
show_property("Height", "Perceived depth for parallax mapping", MaterialTexture::Height, MaterialProperty::HeightMultiplier);
show_property("Roughness", "Specifies microfacet roughness of the surface for diffuse and specular reflection", MaterialTexture::Roughness, MaterialProperty::MultiplierRoughness);
show_property("Metalness", "Blends between a non-metallic and metallic material model", MaterialTexture::Metalness, MaterialProperty::MultiplierMetalness);
show_property("Normal", "Controls the normals of the base layers", MaterialTexture::Normal, MaterialProperty::MultiplierNormal);
show_property("Height", "Perceived depth for parallax mapping", MaterialTexture::Height, MaterialProperty::MultiplierHeight);
show_property("Occlusion", "Amount of light loss, can be complementary to SSAO", MaterialTexture::Occlusion, MaterialProperty::Undefined);
show_property("Emission", "Light emission from the surface, works nice with bloom", MaterialTexture::Emission, MaterialProperty::Undefined);
show_property("Alpha mask", "Discards pixels", MaterialTexture::AlphaMask, MaterialProperty::Undefined);
Expand Down Expand Up @@ -803,10 +798,10 @@ void Properties::ShowMaterial(Material* material) const
}

//= MAP ===============================================================================
material->SetProperty(MaterialProperty::UvTilingX, tiling.x);
material->SetProperty(MaterialProperty::UvTilingY, tiling.y);
material->SetProperty(MaterialProperty::UvOffsetX, offset.x);
material->SetProperty(MaterialProperty::UvOffsetY, offset.y);
material->SetProperty(MaterialProperty::TextureTilingX, tiling.x);
material->SetProperty(MaterialProperty::TextureTilingY, tiling.y);
material->SetProperty(MaterialProperty::TextureOffsetX, offset.x);
material->SetProperty(MaterialProperty::TextureOffsetY, offset.y);
material->SetProperty(MaterialProperty::ColorR, m_material_color_picker->GetColor().r);
material->SetProperty(MaterialProperty::ColorG, m_material_color_picker->GetColor().g);
material->SetProperty(MaterialProperty::ColorB, m_material_color_picker->GetColor().b);
Expand Down
41 changes: 21 additions & 20 deletions runtime/Rendering/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace Spartan
{
switch (material_property)
{
case MaterialProperty::CanBeEdited: return "can_be_edited";
case MaterialProperty::SingleTextureRoughnessMetalness: return "single_texture_roughness_metalness";
case MaterialProperty::Clearcoat: return "clearcoat_multiplier";
case MaterialProperty::Clearcoat_Roughness: return "clearcoat_roughness_multiplier";
case MaterialProperty::Anisotropic: return "anisotropic_multiplier";
Expand All @@ -56,18 +58,17 @@ namespace Spartan
case MaterialProperty::ColorG: return "color_g";
case MaterialProperty::ColorB: return "color_b";
case MaterialProperty::ColorA: return "color_a";
case MaterialProperty::RoughnessMultiplier: return "roughness_multiplier";
case MaterialProperty::MetalnessMultiplier: return "metalness_multiplier";
case MaterialProperty::NormalMultiplier: return "normal_multiplier";
case MaterialProperty::HeightMultiplier: return "height_multiplier";
case MaterialProperty::UvTilingX: return "uv_tiling_x";
case MaterialProperty::UvTilingY: return "uv_tiling_y";
case MaterialProperty::UvOffsetX: return "uv_offset_x";
case MaterialProperty::UvOffsetY: return "uv_offset_y";
case MaterialProperty::SingleTextureRoughnessMetalness: return "single_texture_roughness_metalness";
case MaterialProperty::CanBeEdited: return "can_be_edited";
case MaterialProperty::SlopeBased: return "is_terrain";
case MaterialProperty::AnimateUVs: return "is_water";
case MaterialProperty::MultiplierRoughness: return "multiplier_roughness";
case MaterialProperty::MultiplierMetalness: return "multiplier_metalness";
case MaterialProperty::MultiplierNormal: return "multiplier_normal";
case MaterialProperty::MultiplierHeight: return "multiplier_height";
case MaterialProperty::TextureTilingX: return "texture_tiling_x";
case MaterialProperty::TextureTilingY: return "texture_tiling_y";
case MaterialProperty::TextureOffsetX: return "texture_offset_x";
case MaterialProperty::TextureOffsetY: return "texture_offset_y";
case MaterialProperty::TextureSlopeBased: return "texture_slope_based";
case MaterialProperty::TextureAnimate: return "texture_animate";
case MaterialProperty::VertexAnimateWind: return "vertex_animate_wind";
case MaterialProperty::Undefined: return "undefined";
default:
{
Expand All @@ -89,9 +90,9 @@ namespace Spartan
SetProperty(MaterialProperty::ColorG, 1.0f);
SetProperty(MaterialProperty::ColorB, 1.0f);
SetProperty(MaterialProperty::ColorA, 1.0f);
SetProperty(MaterialProperty::RoughnessMultiplier, 1.0f);
SetProperty(MaterialProperty::UvTilingX, 1.0f);
SetProperty(MaterialProperty::UvTilingY, 1.0f);
SetProperty(MaterialProperty::MultiplierRoughness, 1.0f);
SetProperty(MaterialProperty::TextureTilingX, 1.0f);
SetProperty(MaterialProperty::TextureTilingY, 1.0f);
}

bool Material::LoadFromFile(const std::string& file_path)
Expand Down Expand Up @@ -190,19 +191,19 @@ namespace Spartan
float multiplier = texture != nullptr;
if (texture_type == MaterialTexture::Roughness)
{
SetProperty(MaterialProperty::RoughnessMultiplier, multiplier);
SetProperty(MaterialProperty::MultiplierRoughness, multiplier);
}
else if (texture_type == MaterialTexture::Metalness)
{
SetProperty(MaterialProperty::MetalnessMultiplier, multiplier);
SetProperty(MaterialProperty::MultiplierMetalness, multiplier);
}
else if (texture_type == MaterialTexture::Normal)
{
SetProperty(MaterialProperty::NormalMultiplier, multiplier);
SetProperty(MaterialProperty::MultiplierNormal, multiplier);
}
else if (texture_type == MaterialTexture::Height)
{
SetProperty(MaterialProperty::HeightMultiplier, multiplier);
SetProperty(MaterialProperty::MultiplierHeight, multiplier);
}
}

Expand Down Expand Up @@ -294,7 +295,7 @@ namespace Spartan
}

// Transparent objects are typically see-through (low roughness) so use the alpha as the roughness multiplier.
m_properties[static_cast<uint32_t>(MaterialProperty::RoughnessMultiplier)] = value * 0.5f;
m_properties[static_cast<uint32_t>(MaterialProperty::MultiplierRoughness)] = value * 0.5f;
}

m_properties[static_cast<uint32_t>(property_type)] = value;
Expand Down
57 changes: 29 additions & 28 deletions runtime/Rendering/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,44 @@ namespace Spartan
enum class MaterialTexture
{
Color,
Color2, // A second color for blending purposes
Roughness, // Specifies microfacet roughness of the surface for diffuse and specular reflection
Metalness, // Blends between a non-metallic and metallic material model
Color2, // a second color for blending purposes
Roughness, // specifies microfacet roughness of the surface for diffuse and specular reflection
Metalness, // blends between a non-metallic and metallic material model
Normal,
Normal2, // A second normal for blending purposes
Occlusion, // A texture that will be mixed with ssgi.
Emission, // A texture that will cause a surface to be lit, works nice with bloom.
Height, // Perceived depth for parallax mapping.
AlphaMask, // A texture which will use pixel shader discards for transparent pixels.
Normal2, // a second normal for blending purposes
Occlusion, // a texture that will be mixed with ssgi.
Emission, // a texture that will cause a surface to be lit, works nice with bloom.
Height, // perceived depth for parallax mapping.
AlphaMask, // a texture which will use pixel shader discards for transparent pixels.
Undefined
};

enum class MaterialProperty
{
Clearcoat, // Extra white specular layer on top of others
Clearcoat_Roughness, // Roughness of clearcoat specular
Anisotropic, // Amount of anisotropy for specular reflection
AnisotropicRotation, // Rotates the direction of anisotropy, with 1.0 going full circle
Sheen , // Amount of soft velvet like reflection near edges
SheenTint, // Mix between white and using base color for sheen reflection
ColorTint, // Diffuse or metal surface color
CanBeEdited,
SingleTextureRoughnessMetalness,
Clearcoat, // extra white specular layer on top of others
Clearcoat_Roughness, // roughness of clearcoat specular
Anisotropic, // amount of anisotropy for specular reflection
AnisotropicRotation, // rotates the direction of anisotropy, with 1.0 going full circle
Sheen , // amount of soft velvet like reflection near edges
SheenTint, // mix between white and using base color for sheen reflection
ColorTint, // diffuse or metal surface color
ColorR,
ColorG,
ColorB,
ColorA,
RoughnessMultiplier,
MetalnessMultiplier,
NormalMultiplier,
HeightMultiplier,
UvTilingX,
UvTilingY,
UvOffsetX,
UvOffsetY,
SingleTextureRoughnessMetalness,
CanBeEdited,
SlopeBased,
AnimateUVs,
MultiplierRoughness,
MultiplierMetalness,
MultiplierNormal,
MultiplierHeight,
TextureTilingX,
TextureTilingY,
TextureOffsetX,
TextureOffsetY,
TextureAnimate,
TextureSlopeBased,
VertexAnimateWind,
Undefined
};

Expand Down Expand Up @@ -105,6 +106,6 @@ namespace Spartan

private:
std::array<std::shared_ptr<RHI_Texture>, 11> m_textures;
std::array<float, 23> m_properties;
std::array<float, 24> m_properties;
};
}
Loading

0 comments on commit 1a83a1f

Please sign in to comment.