Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from Exter-N/hdr
Browse files Browse the repository at this point in the history
Improve HDR color handling
  • Loading branch information
chirpxiv authored Oct 3, 2023
2 parents a037b5b + e71c745 commit 1232098
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions PalettePlus/Extensions/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@

namespace PalettePlus.Extensions {
internal static class VectorExtensions {
private static float RgbSqrt(float x)
=> x < 0.0f ? -MathF.Sqrt(-x) : MathF.Sqrt(x);

internal static Vector3 RgbSqrt(this Vector3 vec) => new(
(float)Math.Sqrt(vec.X),
(float)Math.Sqrt(vec.Y),
(float)Math.Sqrt(vec.Z)
RgbSqrt(vec.X),
RgbSqrt(vec.Y),
RgbSqrt(vec.Z)
);

internal static Vector4 RgbSqrt(this Vector4 vec) => new(
(float)Math.Sqrt(vec.X),
(float)Math.Sqrt(vec.Y),
(float)Math.Sqrt(vec.Z),
RgbSqrt(vec.X),
RgbSqrt(vec.Y),
RgbSqrt(vec.Z),
vec.W
);

internal static Vector3 RgbPow2(this Vector3 vec) => vec * vec;
private static float RgbPow2(float x)
=> x < 0.0f ? -(x * x) : x * x;

internal static Vector3 RgbPow2(this Vector3 vec) => new(
RgbPow2(vec.X),
RgbPow2(vec.Y),
RgbPow2(vec.Z)
);

internal static Vector4 RgbPow2(this Vector4 vec) => new(
vec.X * vec.X,
vec.Y * vec.Y,
vec.Z * vec.Z,
RgbPow2(vec.X),
RgbPow2(vec.Y),
RgbPow2(vec.Z),
vec.W
);
}
Expand Down
4 changes: 2 additions & 2 deletions PalettePlus/Interface/Components/PaletteEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static bool DrawField(Palette defaults, ref Palette palette, ref ParamCo

var alpha = field.Attributes.Any(attr => attr is ShowAlpha);
if (alpha) {
if (ImGui.ColorEdit4(label, ref vec4))
if (ImGui.ColorEdit4(label, ref vec4, ImGuiColorEditFlags.AlphaPreviewHalf | ImGuiColorEditFlags.HDR))
newVal = vec4.RgbPow2();
} else {
var vec3 = new Vector3(vec4.X, vec4.Y, vec4.Z);
Expand All @@ -137,7 +137,7 @@ private static bool DrawField(Palette defaults, ref Palette palette, ref ParamCo
}
} else if (data is Vector3 vec3) {
vec3 = vec3.RgbSqrt();
if (ImGui.ColorEdit3(label, ref vec3))
if (ImGui.ColorEdit3(label, ref vec3, ImGuiColorEditFlags.HDR))
newVal = vec3.RgbPow2();
} else if (data is float flt) {
var slider = (Slider?)field.Attributes.FirstOrDefault(attr => attr is Slider);
Expand Down

0 comments on commit 1232098

Please sign in to comment.