Skip to content

Commit

Permalink
[Material] Added subsurface scattering and index of refraction proper…
Browse files Browse the repository at this point in the history
…ties (not wired to anything yet)
  • Loading branch information
PanosK92 committed Nov 30, 2023
1 parent 0358324 commit 3eec4d4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
5 changes: 5 additions & 0 deletions data/shaders/common_textures.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ struct MaterialProperties
{
float sheen;
float3 sheen_tint;

float anisotropic;
float anisotropic_rotation;
float clearcoat;
float clearcoat_roughness;

float subsurface_scattering;
float ior;
float2 padding;
};

// storage
Expand Down
15 changes: 9 additions & 6 deletions editor/Widgets/Properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,6 @@ void Properties::ShowMaterial(Material* material) const
}
};

show_property("Clearcoat", "Extra white specular layer on top of others", MaterialTexture::Undefined, MaterialProperty::Clearcoat);
show_property("Clearcoat roughness", "Roughness of clearcoat specular", MaterialTexture::Undefined, MaterialProperty::Clearcoat_Roughness);
show_property("Anisotropic", "Amount of anisotropy for specular reflection", MaterialTexture::Undefined, MaterialProperty::Anisotropic);
show_property("Anisotropic rotation", "Rotates the direction of anisotropy, with 1.0 going full circle", MaterialTexture::Undefined, MaterialProperty::AnisotropicRotation);
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::MultiplierRoughness);
show_property("Metalness", "Blends between a non-metallic and metallic material model", MaterialTexture::Metalness, MaterialProperty::MultiplierMetalness);
Expand All @@ -766,6 +760,15 @@ void Properties::ShowMaterial(Material* material) const
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);

show_property("Clearcoat", "Extra white specular layer on top of others", MaterialTexture::Undefined, MaterialProperty::Clearcoat);
show_property("Clearcoat roughness", "Roughness of clearcoat specular", MaterialTexture::Undefined, MaterialProperty::Clearcoat_Roughness);
show_property("Anisotropic", "Amount of anisotropy for specular reflection", MaterialTexture::Undefined, MaterialProperty::Anisotropic);
show_property("Anisotropic rotation", "Rotates the direction of anisotropy, with 1.0 going full circle", MaterialTexture::Undefined, MaterialProperty::AnisotropicRotation);
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("Subsurface scattering","Amount of translucency", MaterialTexture::Undefined, MaterialProperty::MultiplierSubsurfaceScattering);
show_property("IOR", "Index of refraction", MaterialTexture::Undefined, MaterialProperty::Ior);
}

// UV
Expand Down
2 changes: 1 addition & 1 deletion runtime/RHI/RHI_StructuredBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Spartan
~RHI_StructuredBuffer();

void Update(void* data);
void ResetOffset() { m_offset = 0; }
void ResetOffset() { m_offset = 0; first_update = true; }
uint32_t GetStride() const { return m_stride; }
uint32_t GetOffset() const { return m_offset; }
void* GetRhiResource() const { return m_rhi_resource; }
Expand Down
2 changes: 2 additions & 0 deletions runtime/Rendering/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ namespace Spartan
case MaterialProperty::ColorG: return "color_g";
case MaterialProperty::ColorB: return "color_b";
case MaterialProperty::ColorA: return "color_a";
case MaterialProperty::Ior: return "ior";
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::MultiplierSubsurfaceScattering: return "multiplier_subsurface_scattering";
case MaterialProperty::TextureTilingX: return "texture_tiling_x";
case MaterialProperty::TextureTilingY: return "texture_tiling_y";
case MaterialProperty::TextureOffsetX: return "texture_offset_x";
Expand Down
4 changes: 3 additions & 1 deletion runtime/Rendering/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace Spartan
MultiplierMetalness,
MultiplierNormal,
MultiplierHeight,
Ior,
MultiplierSubsurfaceScattering,
TextureTilingX,
TextureTilingY,
TextureOffsetX,
Expand Down Expand Up @@ -107,6 +109,6 @@ namespace Spartan

private:
std::array<std::shared_ptr<RHI_Texture>, 11> m_textures;
std::array<float, 26> m_properties;
std::array<float, 28> m_properties;
};
}
3 changes: 3 additions & 0 deletions runtime/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ namespace Spartan
material_properties.clearcoat_roughness = material->GetProperty(MaterialProperty::Clearcoat_Roughness);
material_properties.sheen = material->GetProperty(MaterialProperty::Sheen);
material_properties.sheen_tint = material->GetProperty(MaterialProperty::SheenTint);
material_properties.subsurface_scattering = material->GetProperty(MaterialProperty::MultiplierSubsurfaceScattering);
material_properties.ior = material->GetProperty(MaterialProperty::Ior);

uint32_t index = static_cast<uint32_t>(material->GetObjectId() % materials.size());
materials[index] = material_properties;
Expand Down Expand Up @@ -925,6 +927,7 @@ namespace Spartan
GetStructuredBuffer(Renderer_StructuredBuffer::Material)->Update(&materials[0]);
materials_dirty = false;
}

cmd_list->SetStructuredBuffer(Renderer_BindingsUav::sb_materials, GetStructuredBuffer(Renderer_StructuredBuffer::Material));
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/Rendering/Renderer_Buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ namespace Spartan
{
float sheen;
Math::Vector3 sheen_tint;

float anisotropic;
float anisotropic_rotation;
float clearcoat;
float clearcoat_roughness;

float subsurface_scattering;
float ior;
Math::Vector2 padding;
};
}

0 comments on commit 3eec4d4

Please sign in to comment.