mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Material editor: Allow negatives again with R²G²B²
There seems to be people using it.
This commit is contained in:
parent
afd7aab37d
commit
ffb8f0e8d3
2 changed files with 27 additions and 7 deletions
|
|
@ -483,13 +483,13 @@ public partial class ModEditWindow
|
|||
private static bool ColorPicker( string label, string tooltip, Vector3 input, Action< Vector3 > setter, string letter = "" )
|
||||
{
|
||||
var ret = false;
|
||||
var inputSqrt = Vector3.SquareRoot( input );
|
||||
var inputSqrt = PseudoSqrtRgb( input );
|
||||
var tmp = inputSqrt;
|
||||
if( ImGui.ColorEdit3( label, ref tmp,
|
||||
ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.DisplayRGB | ImGuiColorEditFlags.InputRGB | ImGuiColorEditFlags.NoTooltip )
|
||||
ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.DisplayRGB | ImGuiColorEditFlags.InputRGB | ImGuiColorEditFlags.NoTooltip | ImGuiColorEditFlags.HDR )
|
||||
&& tmp != inputSqrt )
|
||||
{
|
||||
setter( tmp * tmp );
|
||||
setter( PseudoSquareRgb( tmp ) );
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
|
@ -505,4 +505,24 @@ public partial class ModEditWindow
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Functions to deal with squared RGB values without making negatives useless.
|
||||
|
||||
private static float PseudoSquareRgb(float x)
|
||||
=> x < 0.0f ? -(x * x) : (x * x);
|
||||
|
||||
private static Vector3 PseudoSquareRgb(Vector3 vec)
|
||||
=> new(PseudoSquareRgb(vec.X), PseudoSquareRgb(vec.Y), PseudoSquareRgb(vec.Z));
|
||||
|
||||
private static Vector4 PseudoSquareRgb(Vector4 vec)
|
||||
=> new(PseudoSquareRgb(vec.X), PseudoSquareRgb(vec.Y), PseudoSquareRgb(vec.Z), vec.W);
|
||||
|
||||
private static float PseudoSqrtRgb(float x)
|
||||
=> x < 0.0f ? -MathF.Sqrt(-x) : MathF.Sqrt(x);
|
||||
|
||||
private static Vector3 PseudoSqrtRgb(Vector3 vec)
|
||||
=> new(PseudoSqrtRgb(vec.X), PseudoSqrtRgb(vec.Y), PseudoSqrtRgb(vec.Z));
|
||||
|
||||
private static Vector4 PseudoSqrtRgb(Vector4 vec)
|
||||
=> new(PseudoSqrtRgb(vec.X), PseudoSqrtRgb(vec.Y), PseudoSqrtRgb(vec.Z), vec.W);
|
||||
}
|
||||
|
|
@ -147,11 +147,11 @@ public partial class ModEditWindow
|
|||
ImGui.SetNextItemWidth(editorWidth);
|
||||
var value = new Vector3(values);
|
||||
if (_squaredRgb)
|
||||
value = Vector3.SquareRoot(value);
|
||||
value = PseudoSqrtRgb(value);
|
||||
if (ImGui.ColorEdit3("##0", ref value, ImGuiColorEditFlags.Float | (_clamped ? 0 : ImGuiColorEditFlags.HDR)) && !disabled)
|
||||
{
|
||||
if (_squaredRgb)
|
||||
value *= value;
|
||||
value = PseudoSquareRgb(value);
|
||||
if (_clamped)
|
||||
value = Vector3.Clamp(value, Vector3.Zero, Vector3.One);
|
||||
value.CopyTo(values);
|
||||
|
|
@ -165,11 +165,11 @@ public partial class ModEditWindow
|
|||
ImGui.SetNextItemWidth(editorWidth);
|
||||
var value = new Vector4(values);
|
||||
if (_squaredRgb)
|
||||
value = new Vector4(MathF.Sqrt(value.X), MathF.Sqrt(value.Y), MathF.Sqrt(value.Z), value.W);
|
||||
value = PseudoSqrtRgb(value);
|
||||
if (ImGui.ColorEdit4("##0", ref value, ImGuiColorEditFlags.Float | ImGuiColorEditFlags.AlphaPreviewHalf | (_clamped ? 0 : ImGuiColorEditFlags.HDR)) && !disabled)
|
||||
{
|
||||
if (_squaredRgb)
|
||||
value *= new Vector4(value.X, value.Y, value.Z, 1.0f);
|
||||
value = PseudoSquareRgb(value);
|
||||
if (_clamped)
|
||||
value = Vector4.Clamp(value, Vector4.Zero, Vector4.One);
|
||||
value.CopyTo(values);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue