fized xna shader compatability with copious static consts
This commit is contained in:
parent
2343743a43
commit
e5d45f5d48
|
@ -30,25 +30,23 @@ float4 hsv2rgb(float4 c) {
|
|||
|
||||
DECLARE_TEXTURE(sprite, 0); // The sprite texture
|
||||
|
||||
// All of the uniform rgb and hsv colors don't have premultipled alpha!
|
||||
// We need to multiply the alpha in by hand.
|
||||
uniform float recolor1_threshold;
|
||||
uniform float4 recolor1_rgb_from;
|
||||
uniform float4 recolor1_rgb_to;
|
||||
|
||||
uniform float rehue1_threshold;
|
||||
uniform float4 rehue1_threshold_mul;
|
||||
uniform float4 rehue1_rgb_from;
|
||||
uniform float4 rehue1_rgb_to;
|
||||
uniform float4 rehue1_hsv_from;
|
||||
uniform float4 rehue1_hsv_to;
|
||||
static const float rehue1_threshold_norm = rehue1_threshold * length(rehue1_threshold_mul);
|
||||
static const float4 rehue1_hsv_from = rgb2hsv(rehue1_rgb_from);
|
||||
static const float4 rehue1_hsv_to = rgb2hsv(rehue1_rgb_to);
|
||||
|
||||
uniform float rehue2_threshold;
|
||||
uniform float4 rehue2_threshold_mul;
|
||||
uniform float4 rehue2_rgb_from;
|
||||
uniform float4 rehue2_rgb_to;
|
||||
uniform float4 rehue2_hsv_from;
|
||||
uniform float4 rehue2_hsv_to;
|
||||
static const float rehue2_threshold_norm = rehue2_threshold * length(rehue2_threshold_mul);
|
||||
static const float4 rehue2_hsv_from = rgb2hsv(rehue2_rgb_from);
|
||||
static const float4 rehue2_hsv_to = rgb2hsv(rehue2_rgb_to);
|
||||
|
||||
|
||||
float4 hueshift(
|
||||
|
@ -59,24 +57,33 @@ float4 hueshift(
|
|||
return hsv2rgb(hsv_clamp);
|
||||
}
|
||||
|
||||
float4 multiplya(float4 color) {
|
||||
return color * float4(color.aaa, 1.0);
|
||||
}
|
||||
|
||||
float4 ps_main(float4 pos: SV_Position, float4 sprite_color: COLOR0, float2 uv: TEXCOORD0): COLOR {
|
||||
|
||||
float4 ps_main(
|
||||
float4 pos: SV_Position, float4 sprite_color: COLOR0, float2 uv: TEXCOORD0
|
||||
): COLOR {
|
||||
float4 tex_rgb = SAMPLE_TEXTURE(sprite, uv);
|
||||
float4 tex_hsv = rgb2hsv(tex_rgb);
|
||||
|
||||
// replace recolor1_rgb_from with recolor1_rgb_to if in threshold
|
||||
if (distance(tex_rgb, recolor1_rgb_from) < recolor1_threshold) {
|
||||
return recolor1_rgb_to * sprite_color;
|
||||
// Multiply the alpha in because our colors are not premultiplied
|
||||
return multiplya(recolor1_rgb_to) * sprite_color;
|
||||
}
|
||||
|
||||
// hue-shift tex_hsv by the difference between rehue1_hsv_to - rehue1_hsv_from,
|
||||
// only if it is in threshold scaled by the threshold multipler
|
||||
if (distance(tex_hsv * rehue1_threshold_mul, rehue1_hsv_from * rehue1_threshold_mul) < rehue1_threshold_norm) {
|
||||
return hueshift(tex_hsv, rehue1_hsv_from, rehue1_hsv_to) * sprite_color;
|
||||
return multiplya(hueshift(tex_hsv, rehue1_hsv_from, rehue1_hsv_to))
|
||||
* sprite_color;
|
||||
}
|
||||
|
||||
if (distance(tex_hsv * rehue2_threshold_mul, rehue2_hsv_from * rehue2_threshold_mul) < rehue2_threshold_norm) {
|
||||
return hueshift(tex_hsv, rehue2_hsv_from, rehue2_hsv_to) * sprite_color;
|
||||
return multiplya(hueshift(tex_hsv, rehue2_hsv_from, rehue2_hsv_to))
|
||||
* sprite_color;
|
||||
}
|
||||
|
||||
return tex_rgb * sprite_color;
|
||||
|
|
|
@ -202,24 +202,24 @@ namespace Celeste.Mod.AvaliSkin {
|
|||
// works at 0.12 minus the dark brown (actually works for real)
|
||||
FxRecolor.Parameters["rehue1_threshold"].SetValue(0.07f);
|
||||
FxRecolor.Parameters["rehue1_threshold_mul"].SetValue(
|
||||
new Vector4(1f, 0.1f, 0.1f, 0f)
|
||||
new Vector4(1f, 0.1f, 0.3f, 0f)
|
||||
);
|
||||
FxRecolor.Parameters["rehue1_rgb_from"].SetValue(
|
||||
(new Color((byte) 0xa2, 0x88, 0x5c, 0xff)).ToVector4() // #a2885c
|
||||
FxRecolor.Parameters["rehue1_hsv_from"].SetValue(
|
||||
(new Color((byte) 0xa2, 0x88, 0x5c, 0xff)).ToHSV() // #a2885c
|
||||
);
|
||||
FxRecolor.Parameters["rehue1_hsv_to"].SetValue(
|
||||
lightColor2.ToHSV()
|
||||
);
|
||||
FxRecolor.Parameters["rehue1_rgb_to"].SetValue(
|
||||
lightColor2.ToVector4()
|
||||
); // #433722
|
||||
|
||||
FxRecolor.Parameters["rehue2_threshold"].SetValue(0.07f);
|
||||
FxRecolor.Parameters["rehue2_threshold_mul"].SetValue(
|
||||
new Vector4(1f, .8f, .8f, 0f)
|
||||
);
|
||||
FxRecolor.Parameters["rehue2_rgb_from"].SetValue(
|
||||
(new Color((byte) 0x4e, 0x4e, 0x4e, 0xff)).ToVector4() // #4e4e4e
|
||||
FxRecolor.Parameters["rehue2_hsv_from"].SetValue(
|
||||
(new Color((byte) 0x4e, 0x4e, 0x4e, 0xff)).ToHSV() // #4e4e4e
|
||||
);
|
||||
FxRecolor.Parameters["rehue2_rgb_to"].SetValue(
|
||||
darkColor2.ToVector4()
|
||||
FxRecolor.Parameters["rehue2_hsv_to"].SetValue(
|
||||
darkColor2.ToHSV()
|
||||
);
|
||||
|
||||
FxRecolor.CurrentTechnique = FxRecolor.Techniques["Recolor"];
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
|
@ -75,6 +76,33 @@ namespace Celeste.Mod.AvaliSkin {
|
|||
public static Color Premultiply(this Color color) {
|
||||
return Color.FromNonPremultiplied(color.ToVector4());
|
||||
}
|
||||
|
||||
// From https://web.archive.org/web/20200213094821/http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
|
||||
public static Vector4 ToHSV(this Color color) {
|
||||
// custom deconstructors are broken on mono
|
||||
float r = color.R / 255.0f;
|
||||
float g = color.G / 255.0f;
|
||||
float b = color.B / 255.0f;
|
||||
float a = color.A / 255.0f;
|
||||
|
||||
float K = 0f;
|
||||
|
||||
if (g < b) {
|
||||
b = Interlocked.Exchange(ref g, b);
|
||||
K = -1f;
|
||||
}
|
||||
|
||||
if (r < g) {
|
||||
g = Interlocked.Exchange(ref r, g);
|
||||
K = -2f / 6f - K;
|
||||
}
|
||||
|
||||
float chroma = r - Math.Min(g, b);
|
||||
float h = Math.Abs(K + (g - b) / (6f * chroma + 1e-20f));
|
||||
float s = chroma / (r + 1e-20f);
|
||||
float v = r;
|
||||
|
||||
return new Vector4(h, s, v, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue