decal slopeBlendPower

This commit is contained in:
Turánszki János
2023-03-16 17:38:55 +01:00
parent 615a064f20
commit 892bbf0e13
13 changed files with 66 additions and 9 deletions
@@ -1162,6 +1162,8 @@ The decal component is a textured sticker that can be put down onto meshes. Most
- SetBaseColorOnlyAlpha(bool value) -- Set decal to only use alpha from base color texture. Useful for blending normalmap-only decals
- IsBaseColorOnlyAlpha() : bool
- SetSlopeBlendPower(float value)
- GetSlopeBlendPower() : float
## Canvas
+17 -2
View File
@@ -10,7 +10,7 @@ void DecalWindow::Create(EditorComponent* _editor)
{
editor = _editor;
wi::gui::Window::Create(ICON_DECAL " Decal", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE);
SetSize(XMFLOAT2(300, 180));
SetSize(XMFLOAT2(300, 200));
closeButton.SetTooltip("Delete DecalComponent");
OnClose([=](wi::gui::EventArgs args) {
@@ -53,6 +53,19 @@ void DecalWindow::Create(EditorComponent* _editor)
});
AddWidget(&onlyalphaCheckBox);
slopeBlendPowerSlider.Create(0, 8, 0, 1000, "Slope Blend: ");
slopeBlendPowerSlider.SetSize(XMFLOAT2(100, hei));
slopeBlendPowerSlider.SetTooltip("Set a power factor for blending on surface slopes. 0 = no slope blend, increasing = more slope blend");
slopeBlendPowerSlider.OnSlide([=](wi::gui::EventArgs args) {
Scene& scene = editor->GetCurrentScene();
DecalComponent* decal = scene.decals.GetComponent(entity);
if (decal != nullptr)
{
decal->slopeBlendPower = args.fValue;
}
});
AddWidget(&slopeBlendPowerSlider);
y += step;
infoLabel.Create("");
@@ -80,6 +93,7 @@ void DecalWindow::SetEntity(Entity entity)
{
SetEnabled(true);
onlyalphaCheckBox.SetCheck(decal->IsBaseColorOnlyAlpha());
slopeBlendPowerSlider.SetValue(decal->slopeBlendPower);
}
else
{
@@ -98,7 +112,7 @@ void DecalWindow::ResizeLayout()
auto add = [&](wi::gui::Widget& widget) {
if (!widget.IsVisible())
return;
const float margin_left = 80;
const float margin_left = 100;
const float margin_right = 40;
widget.SetPos(XMFLOAT2(margin_left, y));
widget.SetSize(XMFLOAT2(width - margin_left - margin_right, widget.GetScale().y));
@@ -127,5 +141,6 @@ void DecalWindow::ResizeLayout()
add_fullwidth(infoLabel);
add_right(placementCheckBox);
add_right(onlyalphaCheckBox);
add(slopeBlendPowerSlider);
}
+2 -1
View File
@@ -12,9 +12,10 @@ public:
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
wi::gui::Label infoLabel;
wi::gui::CheckBox placementCheckBox;
wi::gui::CheckBox onlyalphaCheckBox;
wi::gui::Label infoLabel;
wi::gui::Slider slopeBlendPowerSlider;
void ResizeLayout() override;
};
+4 -2
View File
@@ -532,7 +532,8 @@ inline void ForwardDecals(inout Surface surface, inout float4 surfaceMap)
float4 decalColor = decal.GetColor();
// blend out if close to cube Z:
const float edgeBlend = 1 - pow(saturate(abs(clipSpacePos.z)), 8);
decalColor.a *= edgeBlend;
const float slopeBlend = decal.GetConeAngleCos() > 0 ? pow(saturate(dot(surface.N, decal.GetDirection())), decal.GetConeAngleCos()) : 1;
decalColor.a *= edgeBlend * slopeBlend;
[branch]
if (decalTexture >= 0)
{
@@ -862,7 +863,8 @@ inline void TiledDecals(inout Surface surface, uint flatTileIndex, inout float4
float4 decalColor = decal.GetColor();
// blend out if close to cube Z:
const float edgeBlend = 1 - pow(saturate(abs(clipSpacePos.z)), 8);
decalColor.a *= edgeBlend;
const float slopeBlend = decal.GetConeAngleCos() > 0 ? pow(saturate(dot(surface.N, decal.GetDirection())), decal.GetConeAngleCos()) : 1;
decalColor.a *= edgeBlend * slopeBlend;
[branch]
if (decalTexture >= 0)
{
+2 -1
View File
@@ -534,7 +534,8 @@ struct Surface
float4 decalColor = decal.GetColor();
// blend out if close to cube Z:
const float edgeBlend = 1 - pow(saturate(abs(clipSpacePos.z)), 8);
decalColor.a *= edgeBlend;
const float slopeBlend = decal.GetConeAngleCos() > 0 ? pow(saturate(dot(N, decal.GetDirection())), decal.GetConeAngleCos()) : 1;
decalColor.a *= edgeBlend * slopeBlend;
[branch]
if (decalTexture >= 0)
{
+2
View File
@@ -3768,6 +3768,8 @@ void UpdateRenderData(
float emissive_mul = 1 + decal.emissive;
shaderentity.SetColor(float4(decal.color.x * emissive_mul, decal.color.y * emissive_mul, decal.color.z * emissive_mul, decal.color.w));
shaderentity.shadowAtlasMulAdd = decal.texMulAdd;
shaderentity.SetConeAngleCos(decal.slopeBlendPower);
shaderentity.SetDirection(decal.front);
shaderentity.SetIndices(matrixCounter, 0);
shadermatrix = XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal.world));
+1 -1
View File
@@ -3770,7 +3770,7 @@ namespace wi::scene
decal.world = transform.world;
XMMATRIX W = XMLoadFloat4x4(&decal.world);
XMVECTOR front = XMVectorSet(0, 0, 1, 0);
XMVECTOR front = XMVectorSet(0, 0, -1, 0);
front = XMVector3TransformNormal(front, W);
XMStoreFloat3(&decal.front, front);
+1 -1
View File
@@ -39,7 +39,7 @@ namespace wi::scene
wi::ecs::ComponentManager<CameraComponent>& cameras = componentLibrary.Register<CameraComponent>("wi::scene::Scene::cameras");
wi::ecs::ComponentManager<EnvironmentProbeComponent>& probes = componentLibrary.Register<EnvironmentProbeComponent>("wi::scene::Scene::probes");
wi::ecs::ComponentManager<ForceFieldComponent>& forces = componentLibrary.Register<ForceFieldComponent>("wi::scene::Scene::forces", 1); // version = 1
wi::ecs::ComponentManager<DecalComponent>& decals = componentLibrary.Register<DecalComponent>("wi::scene::Scene::decals");
wi::ecs::ComponentManager<DecalComponent>& decals = componentLibrary.Register<DecalComponent>("wi::scene::Scene::decals", 1); // version = 1
wi::ecs::ComponentManager<AnimationComponent>& animations = componentLibrary.Register<AnimationComponent>("wi::scene::Scene::animations", 1); // version = 1
wi::ecs::ComponentManager<AnimationDataComponent>& animation_datas = componentLibrary.Register<AnimationDataComponent>("wi::scene::Scene::animation_datas");
wi::ecs::ComponentManager<EmittedParticleSystem>& emitters = componentLibrary.Register<EmittedParticleSystem>("wi::scene::Scene::emitters");
+20
View File
@@ -5805,6 +5805,8 @@ int HumanoidComponent_BindLua::SetLookAt(lua_State* L)
Luna<DecalComponent_BindLua>::FunctionType DecalComponent_BindLua::methods[] = {
lunamethod(DecalComponent_BindLua, SetBaseColorOnlyAlpha),
lunamethod(DecalComponent_BindLua, IsBaseColorOnlyAlpha),
lunamethod(DecalComponent_BindLua, SetSlopeBlendPower),
lunamethod(DecalComponent_BindLua, GetSlopeBlendPower),
{ NULL, NULL }
};
Luna<DecalComponent_BindLua>::PropertyType DecalComponent_BindLua::properties[] = {
@@ -5829,5 +5831,23 @@ int DecalComponent_BindLua::IsBaseColorOnlyAlpha(lua_State* L)
wi::lua::SSetBool(L, component->IsBaseColorOnlyAlpha());
return 1;
}
int DecalComponent_BindLua::SetSlopeBlendPower(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
component->slopeBlendPower = wi::lua::SGetFloat(L, 1);
}
else
{
wi::lua::SError(L, "SetSlopeBlendPower(float value) not enough arguments!");
}
return 0;
}
int DecalComponent_BindLua::GetSlopeBlendPower(lua_State* L)
{
wi::lua::SSetFloat(L, component->slopeBlendPower);
return 1;
}
}
+2
View File
@@ -1685,6 +1685,8 @@ namespace wi::lua::scene
int SetBaseColorOnlyAlpha(lua_State* L);
int IsBaseColorOnlyAlpha(lua_State* L);
int SetSlopeBlendPower(lua_State* L);
int GetSlopeBlendPower(lua_State* L);
};
}
+2
View File
@@ -1052,6 +1052,8 @@ namespace wi::scene
};
uint32_t _flags = EMPTY;
float slopeBlendPower = 0;
// Set decal to only use alpha from base color texture. Useful for blending normalmap-only decals
constexpr void SetBaseColorOnlyAlpha(bool value) { if (value) { _flags |= BASECOLOR_ONLY_ALPHA; } else { _flags ^= BASECOLOR_ONLY_ALPHA; } }
+10
View File
@@ -983,10 +983,20 @@ namespace wi::scene
if (archive.IsReadMode())
{
archive >> _flags;
if (seri.GetVersion() >= 1)
{
archive >> slopeBlendPower;
}
}
else
{
archive << _flags;
if (seri.GetVersion() >= 1)
{
archive << slopeBlendPower;
}
}
}
void AnimationComponent::Serialize(wi::Archive& archive, EntitySerializer& seri)
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 179;
const int revision = 180;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);