Skip to content

Commit

Permalink
interior mapping (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Jan 25, 2025
1 parent 4d9bd4a commit 4c53158
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 12 deletions.
Binary file added Content/models/interior_mapping.wiscene
Binary file not shown.
147 changes: 146 additions & 1 deletion Editor/MaterialWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,110 @@ void MaterialWindow::Create(EditorComponent* _editor)
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->blend_with_terrain_height = args.fValue;
material->SetBlendWithTerrainHeight(args.fValue);
}
});
AddWidget(&blendTerrainSlider);

interiorScaleXSlider.Create(1, 10, 1, 1000, "Interior Scale X: ");
interiorScaleXSlider.SetTooltip("Set the cubemap scale for the interior mapping (if material uses interior mapping shader)");
interiorScaleXSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingScale(XMFLOAT3(args.fValue, material->interiorMappingScale.y, material->interiorMappingScale.z));
}
});
AddWidget(&interiorScaleXSlider);

interiorScaleYSlider.Create(1, 10, 1, 1000, "Interior Scale Y: ");
interiorScaleYSlider.SetTooltip("Set the cubemap scale for the interior mapping (if material uses interior mapping shader)");
interiorScaleYSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingScale(XMFLOAT3(material->interiorMappingScale.x, args.fValue, material->interiorMappingScale.z));
}
});
AddWidget(&interiorScaleYSlider);

interiorScaleZSlider.Create(1, 10, 1, 1000, "Interior Scale Z: ");
interiorScaleZSlider.SetTooltip("Set the cubemap scale for the interior mapping (if material uses interior mapping shader)");
interiorScaleZSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingScale(XMFLOAT3(material->interiorMappingScale.x, material->interiorMappingScale.y, args.fValue));
}
});
AddWidget(&interiorScaleZSlider);

interiorOffsetXSlider.Create(-10, 10, 0, 2000, "Interior Offset X: ");
interiorOffsetXSlider.SetTooltip("Set the cubemap offset for the interior mapping (if material uses interior mapping shader)");
interiorOffsetXSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingOffset(XMFLOAT3(args.fValue, material->interiorMappingOffset.y, material->interiorMappingOffset.z));
}
});
AddWidget(&interiorOffsetXSlider);

interiorOffsetYSlider.Create(-10, 10, 0, 2000, "Interior Offset Y: ");
interiorOffsetYSlider.SetTooltip("Set the cubemap offset for the interior mapping (if material uses interior mapping shader)");
interiorOffsetYSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingOffset(XMFLOAT3(material->interiorMappingOffset.x, args.fValue, material->interiorMappingOffset.z));
}
});
AddWidget(&interiorOffsetYSlider);

interiorOffsetZSlider.Create(-10, 10, 0, 2000, "Interior Offset Z: ");
interiorOffsetZSlider.SetTooltip("Set the cubemap offset for the interior mapping (if material uses interior mapping shader)");
interiorOffsetZSlider.OnSlide([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingOffset(XMFLOAT3(material->interiorMappingOffset.x, material->interiorMappingOffset.y, args.fValue));
}
});
AddWidget(&interiorOffsetZSlider);

interiorRotationSlider.Create(0, 360, 0, 360, "Interior Rotation: ");
interiorRotationSlider.SetTooltip("Set the cubemap horizontal rotation for the interior mapping (if material uses interior mapping shader)");
interiorRotationSlider.OnSlide([&](wi::gui::EventArgs args) {
float radians = wi::math::DegreesToRadians(args.fValue);
wi::scene::Scene& scene = editor->GetCurrentScene();
for (auto& x : editor->translator.selected)
{
MaterialComponent* material = get_material(scene, x);
if (material == nullptr)
continue;
material->SetInteriorMappingRotation(radians);
}
});
AddWidget(&interiorRotationSlider);


//
hei = 20;
Expand Down Expand Up @@ -947,6 +1046,14 @@ void MaterialWindow::Create(EditorComponent* _editor)
{
const Texture& texture = material->textures[args.iValue].resource.GetTexture();
tooltiptext += "\nResolution: " + std::to_string(texture.desc.width) + " * " + std::to_string(texture.desc.height);
if (texture.desc.array_size > 0)
{
tooltiptext += " * " + std::to_string(texture.desc.array_size);
}
if (has_flag(texture.desc.misc_flags, ResourceMiscFlag::TEXTURECUBE))
{
tooltiptext += " (cubemap)";
}
tooltiptext += "\nMip levels: " + std::to_string(texture.desc.mip_levels);
tooltiptext += "\nFormat: ";
tooltiptext += GetFormatString(texture.desc.format);
Expand Down Expand Up @@ -1115,6 +1222,7 @@ void MaterialWindow::SetEntity(Entity entity)
shaderTypeComboBox.AddItem("Water", MaterialComponent::SHADERTYPE_WATER);
shaderTypeComboBox.AddItem("Cartoon", MaterialComponent::SHADERTYPE_CARTOON);
shaderTypeComboBox.AddItem("Unlit", MaterialComponent::SHADERTYPE_UNLIT);
shaderTypeComboBox.AddItem("Interior", MaterialComponent::SHADERTYPE_INTERIORMAPPING);
for (auto& x : wi::renderer::GetCustomShaders())
{
shaderTypeComboBox.AddItem("*" + x.name);
Expand Down Expand Up @@ -1177,6 +1285,13 @@ void MaterialWindow::SetEntity(Entity entity)
clearcoatSlider.SetValue(material->clearcoat);
clearcoatRoughnessSlider.SetValue(material->clearcoatRoughness);
blendTerrainSlider.SetValue(material->blend_with_terrain_height);
interiorScaleXSlider.SetValue(material->interiorMappingScale.x);
interiorScaleYSlider.SetValue(material->interiorMappingScale.y);
interiorScaleZSlider.SetValue(material->interiorMappingScale.z);
interiorOffsetXSlider.SetValue(material->interiorMappingOffset.x);
interiorOffsetYSlider.SetValue(material->interiorMappingOffset.y);
interiorOffsetZSlider.SetValue(material->interiorMappingOffset.z);
interiorRotationSlider.SetValue(wi::math::RadiansToDegrees(material->interiorMappingRotation));

shadingRateComboBox.SetEnabled(wi::graphics::GetDevice()->CheckCapability(GraphicsDeviceCapability::VARIABLE_RATE_SHADING));

Expand Down Expand Up @@ -1247,6 +1362,9 @@ void MaterialWindow::ResizeLayout()
y += padding;
};

Scene& scene = editor->GetCurrentScene();
MaterialComponent* material = scene.materials.GetComponent(entity);

add_fullwidth(materialNameField);
add_right(shadowReceiveCheckBox);
add_right(shadowCasterCheckBox);
Expand Down Expand Up @@ -1289,6 +1407,33 @@ void MaterialWindow::ResizeLayout()
add(clearcoatSlider);
add(clearcoatRoughnessSlider);
add(blendTerrainSlider);
if (material != nullptr && material->shaderType == MaterialComponent::SHADERTYPE_INTERIORMAPPING)
{
interiorScaleXSlider.SetVisible(true);
interiorScaleYSlider.SetVisible(true);
interiorScaleZSlider.SetVisible(true);
interiorOffsetXSlider.SetVisible(true);
interiorOffsetYSlider.SetVisible(true);
interiorOffsetZSlider.SetVisible(true);
interiorRotationSlider.SetVisible(true);
add(interiorScaleXSlider);
add(interiorScaleYSlider);
add(interiorScaleZSlider);
add(interiorOffsetXSlider);
add(interiorOffsetYSlider);
add(interiorOffsetZSlider);
add(interiorRotationSlider);
}
else
{
interiorScaleXSlider.SetVisible(false);
interiorScaleYSlider.SetVisible(false);
interiorScaleZSlider.SetVisible(false);
interiorOffsetXSlider.SetVisible(false);
interiorOffsetYSlider.SetVisible(false);
interiorOffsetZSlider.SetVisible(false);
interiorRotationSlider.SetVisible(false);
}
add(colorComboBox);
add_fullwidth(colorPicker);
add(textureSlotComboBox);
Expand Down
7 changes: 7 additions & 0 deletions Editor/MaterialWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class MaterialWindow : public wi::gui::Window
wi::gui::Slider clearcoatSlider;
wi::gui::Slider clearcoatRoughnessSlider;
wi::gui::Slider blendTerrainSlider;
wi::gui::Slider interiorScaleXSlider;
wi::gui::Slider interiorScaleYSlider;
wi::gui::Slider interiorScaleZSlider;
wi::gui::Slider interiorOffsetXSlider;
wi::gui::Slider interiorOffsetYSlider;
wi::gui::Slider interiorOffsetZSlider;
wi::gui::Slider interiorRotationSlider;

wi::gui::ComboBox colorComboBox;
wi::gui::ColorPicker colorPicker;
Expand Down
1 change: 1 addition & 0 deletions WickedEngine/shaders/ShaderInterop_Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum IMAGE_FLAGS
IMAGE_FLAG_ANGULAR_INVERSE = 1u << 7u,
IMAGE_FLAG_DISTORTION_MASK = 1u << 8u,
IMAGE_FLAG_HIGHLIGHT = 1u << 9u,
IMAGE_FLAG_CUBEMAP_BASE = 1u << 10u,
};

struct alignas(16) ImageConstants
Expand Down
5 changes: 4 additions & 1 deletion WickedEngine/shaders/ShaderInterop_Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ struct alignas(16) ShaderMaterial
inline half GetAnisotropySin() { return unpack_half4(aniso_anisosin_anisocos_terrainblend).y; }
inline half GetAnisotropyCos() { return unpack_half4(aniso_anisosin_anisocos_terrainblend).z; }
inline half GetTerrainBlendRcp() { return unpack_half4(aniso_anisosin_anisocos_terrainblend).w; }
inline half3 GetInteriorScale() { return unpack_half3(subsurfaceScattering); }
inline half3 GetInteriorOffset() { return unpack_half3(subsurfaceScattering_inv); }
inline half2 GetInteriorSinCos() { return half2(unpack_half4(subsurfaceScattering).w, unpack_half4(subsurfaceScattering_inv).w); }
inline uint GetStencilRef() { return options_stencilref >> 24u; }
#endif // __cplusplus

Expand Down Expand Up @@ -470,7 +473,7 @@ struct alignas(16) ShaderTypeBin
uint4 padding; // 32-byte alignment
#endif // __SCE__ || __PSSL__
};
static const uint SHADERTYPE_BIN_COUNT = 11;
static const uint SHADERTYPE_BIN_COUNT = 12;

struct alignas(16) VisibilityTile
{
Expand Down
Loading

0 comments on commit 4c53158

Please sign in to comment.