Skip to content

Commit

Permalink
Fixed some stuff related to hover fade in.
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendly0Fire committed Feb 27, 2022
1 parent 923559e commit 4e2413d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 37 deletions.
5 changes: 3 additions & 2 deletions GW2Radial/include/Wheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Wheel : public SettingsMenu::Implementer
protected:
void Sort();
void UpdateConstantBuffer(ID3D11DeviceContext* ctx, const fVector4& spriteDimensions, float fadeIn, float animationTimer,
const std::vector<WheelElement*>& activeElements, const std::vector<float>& hoveredFadeIns, float timeLeft, bool showIcon, bool tilt);
const std::vector<WheelElement*>& activeElements, const std::span<float>& hoveredFadeIns, float timeLeft, bool showIcon, bool tilt);
void UpdateConstantBuffer(ID3D11DeviceContext* ctx, const fVector4& baseSpriteDimensions);

static const mstime conditionallyDelayedFadeOutTime = 500;
Expand Down Expand Up @@ -185,6 +185,7 @@ class Wheel : public SettingsMenu::Implementer
friend class WheelElement;
friend class CustomWheelsManager;

static inline const uint MaxHoverFadeIns = 12;
struct WheelCB
{
fVector3 wipeMaskData;
Expand All @@ -193,7 +194,7 @@ class Wheel : public SettingsMenu::Implementer
float centerScale;
int elementCount;
float globalOpacity;
float hoverFadeIns[12];
float hoverFadeIns[MaxHoverFadeIns];
float timeLeft;
bool showIcon;
};
Expand Down
2 changes: 1 addition & 1 deletion GW2Radial/include/WheelElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class WheelElement
struct WheelElementCB
{
fVector4 adjustedColor;
int elementId;
float elementHoverFadeIn;
bool premultiplyAlpha;
};

Expand Down
9 changes: 5 additions & 4 deletions GW2Radial/shaders/Wheel.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ float4 Wheel(PS_INPUT In) : SV_Target0
int localMountId = (int) round(coordsPolar.y / singleMountAngle);
if (localMountId >= elementCount)
localMountId -= elementCount;
float hoverFadeIn = hoverFadeIns[localMountId];
float hoverFadeIn = GetHoverFadeIn(localMountId);
bool isLocalMountHovered = hoverFadeIn > 0.f;

hoverFadeIn = min(hoverFadeIn, wheelFadeIn.x);
Expand Down Expand Up @@ -72,10 +72,11 @@ float4 Wheel(PS_INPUT In) : SV_Target0
border_mask *= 2.f - smoothstep(centerScale + 0.01f, centerScale + 0.1f, coordsPolar.x);

// Also brighten when the dead zone is hovered and has an action assigned to it
if (hoverFadeIns[elementCount] > 0.f)
float centerHoverFadeIn = GetHoverFadeIn(elementCount);
if (centerHoverFadeIn > 0.f)
{
color.rgb *= lerp(lerp(1.f, 1.5f, hoverFadeIns[elementCount]), 1.f, center_mask);
center_mask = lerp(center_mask, 1 - luma * 0.2f, hoverFadeIns[elementCount]);
color.rgb *= lerp(lerp(1.f, 1.5f, centerHoverFadeIn), 1.f, center_mask);
center_mask = lerp(center_mask, 1 - luma * 0.2f, centerHoverFadeIn);
}

// Combine all masks, ensuring that the edge and center masks never increase brightness when combined and that the border mask never darkens the circle
Expand Down
22 changes: 3 additions & 19 deletions GW2Radial/shaders/WheelElement.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@

float4 WheelElement(PS_INPUT In) : SV_Target
{
float hoverFadeIn = hoverFadeIns[elementId];

float shadow;
float4 color = BaseMountImage(In.UV, IconTexture, MainSampler, shadow);

const float3 lumaDot = float3(0.2126, 0.7152, 0.0722);
float luma = dot(color.rgb, lumaDot);
float3 fadedColor = lerp(color.rgb, luma, 0.33f);
float3 finalColor = fadedColor;

float3 glow = 0;
if(hoverFadeIn > 0.f)
{
finalColor = lerp(fadedColor, color.rgb, hoverFadeIn);

float glowMask = 0;
glowMask += 1.f - IconTexture.Sample(MainSampler, In.UV + float2(0.01f, 0.01f)).r;
glowMask += 1.f - IconTexture.Sample(MainSampler, In.UV + float2(-0.01f, 0.01f)).r;
glowMask += 1.f - IconTexture.Sample(MainSampler, In.UV + float2(0.01f, -0.01f)).r;
glowMask += 1.f - IconTexture.Sample(MainSampler, In.UV + float2(-0.01f, -0.01f)).r;

glow = color.rgb * (glowMask / 4) * hoverFadeIn * 0.5f * (0.5f + 0.5f * srnoise(In.UV * 3.18f + 0.15f * float2(cos(animationTimer * 3), sin(animationTimer * 2))));
}
float3 fadedColor = lerp(color.rgb, luma, 0.4f);
float3 finalColor = lerp(fadedColor, color.rgb, elementHoverFadeIn);

return float4(finalColor.rgb + glow, max(color.a, shadow)) * wheelFadeIn.x * globalOpacity;
return float4(finalColor.rgb, color.a) * wheelFadeIn.x * globalOpacity;
}
7 changes: 5 additions & 2 deletions GW2Radial/shaders/common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ cbuffer Wheel : register(b0)
bool showIcon;
};

static float hoverFadeIns[WHEEL_MAX_ELEMENT_COUNT] = (float[WHEEL_MAX_ELEMENT_COUNT])hoverFadeIns_;
float GetHoverFadeIn(int i)
{
return hoverFadeIns_[i >> 2][i & 3];
}

cbuffer WheelElement : register(b1)
{
float4 adjustedColor;
int elementId;
float elementHoverFadeIn;
bool premultiplyAlpha;
};

Expand Down
21 changes: 13 additions & 8 deletions GW2Radial/src/Wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,30 +450,33 @@ void Wheel::Draw(ID3D11DeviceContext* ctx)

const float fadeTimer = std::min(1.f, (currentTime - (currentTriggerTime_ + displayDelayOption_.value())) / float(animationTimeOption_.value() * 0.5f));

std::vector<float> hoveredFadeIns;
std::transform(activeElements.begin(), activeElements.end(), std::back_inserter(hoveredFadeIns),
std::array<float, MaxHoverFadeIns> hoveredFadeIns;
std::transform(activeElements.begin(), activeElements.end(), hoveredFadeIns.begin(),
[&](const WheelElement* elem) { return elem->hoverFadeIn(currentTime, this); });

auto& lastHoverFadeIn = hoveredFadeIns[activeElements.size()];
switch(CenterBehavior(centerBehaviorOption_.value()))
{
case CenterBehavior::PREVIOUS:
if(previousUsed_)
hoveredFadeIns.push_back(previousUsed_->hoverFadeIn(currentTime, this));
lastHoverFadeIn = previousUsed_->hoverFadeIn(currentTime, this);
break;
case CenterBehavior::FAVORITE:
{
auto fav = centerFavoriteOption_.value();
if (fav >= 0 && fav < wheelElements_.size()) {
hoveredFadeIns.push_back(wheelElements_[fav]->hoverFadeIn(currentTime, this));
lastHoverFadeIn = wheelElements_[fav]->hoverFadeIn(currentTime, this);
break;
}
}
[[fallthrough]];
default:
hoveredFadeIns.push_back(0.f);
lastHoverFadeIn = 0.f;
break;
}

for (uint i = activeElements.size() + 1; i < MaxHoverFadeIns; i++)
hoveredFadeIns[i] = 0.f;

ShaderManager::i().SetShaders(ctx, vs_, psWheel_);
ctx->OMSetBlendState(blendState_.Get(), nullptr, 0xffffffff);
Expand Down Expand Up @@ -563,7 +566,9 @@ void Wheel::Draw(ID3D11DeviceContext* ctx)
spriteDimensions.x += spriteDimensions.z * 0.5f;
spriteDimensions.y += spriteDimensions.w * 0.5f;

UpdateConstantBuffer(ctx, spriteDimensions, std::min(absDt * 2, 1.f), fmod(currentTime / 1010.f, 55000.f), {}, {}, timeLeft, conditionallyDelayed_ != nullptr, false);
std::array<float, MaxHoverFadeIns> hoveredFadeIns;
std::fill(hoveredFadeIns.begin(), hoveredFadeIns.end(), 0.f);
UpdateConstantBuffer(ctx, spriteDimensions, std::min(absDt * 2, 1.f), fmod(currentTime / 1010.f, 55000.f), {}, hoveredFadeIns, timeLeft, conditionallyDelayed_ != nullptr, false);
if (conditionallyDelayed_)
conditionallyDelayed_->SetShaderState(ctx);

Expand All @@ -579,7 +584,7 @@ void Wheel::Draw(ID3D11DeviceContext* ctx)
}

void Wheel::UpdateConstantBuffer(ID3D11DeviceContext* ctx, const fVector4& spriteDimensions, float fadeIn, float animationTimer,
const std::vector<WheelElement*>& activeElements, const std::vector<float>& hoveredFadeIns, float timeLeft, bool showIcon, bool tilt)
const std::vector<WheelElement*>& activeElements, const std::span<float>& hoveredFadeIns, float timeLeft, bool showIcon, bool tilt)
{
cb_s->wipeMaskData = wipeMaskData_;
cb_s->wheelFadeIn = fadeIn;
Expand All @@ -589,7 +594,7 @@ void Wheel::UpdateConstantBuffer(ID3D11DeviceContext* ctx, const fVector4& sprit
cb_s->globalOpacity = opacityMultiplierOption_.value() * 0.01f;
cb_s->timeLeft = timeLeft;
cb_s->showIcon = showIcon;
memcpy_s(cb_s->hoverFadeIns, sizeof(cb_s->hoverFadeIns), hoveredFadeIns.data(), hoveredFadeIns.size() * sizeof(float));
memcpy_s(cb_s->hoverFadeIns, sizeof(cb_s->hoverFadeIns), hoveredFadeIns.data(), MaxHoverFadeIns * sizeof(float));

cb_s.Update(ctx);
ctx->PSSetConstantBuffers(0, 1, cb_s.buffer().GetAddressOf());
Expand Down
2 changes: 1 addition & 1 deletion GW2Radial/src/WheelElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void WheelElement::SetShaderState(ID3D11DeviceContext* ctx, const fVector4& spri

auto& sm = ShaderManager::i();

cb_s->elementId = elementId();
cb_s->elementHoverFadeIn = hoverRatio;
cb_s->adjustedColor = shadow ? fVector4 { 0.f, 0.f, 0.f, shadowStrength_ } : adjustedColor;
cb_s->premultiplyAlpha = shadow ? false : premultiplyAlpha_;

Expand Down

0 comments on commit 4e2413d

Please sign in to comment.