From 136e895f8349a8afe930d49c6b430baa2efe44a2 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Wed, 27 Sep 2023 05:22:32 -0400 Subject: [PATCH] Further interaction outline tweaks (tonemap rework) (#19898) --- Resources/Prototypes/Shaders/outline.yml | 6 +++++- Resources/Textures/Shaders/outline.swsl | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Resources/Prototypes/Shaders/outline.yml b/Resources/Prototypes/Shaders/outline.yml index 83b99f07ea..57ea6a485a 100644 --- a/Resources/Prototypes/Shaders/outline.yml +++ b/Resources/Prototypes/Shaders/outline.yml @@ -4,7 +4,9 @@ path: "/Textures/Shaders/outline.swsl" params: outline_color: "#FF000055" - light_boost: 1 + light_boost: 2 + light_gamma: 1.5 + light_whitepoint: 48 - type: shader id: SelectionOutlineInrange @@ -13,3 +15,5 @@ params: outline_color: "#00FF0055" light_boost: 2 + light_gamma: 0.9 + light_whitepoint: 1 diff --git a/Resources/Textures/Shaders/outline.swsl b/Resources/Textures/Shaders/outline.swsl index d465946ae6..bef244555c 100644 --- a/Resources/Textures/Shaders/outline.swsl +++ b/Resources/Textures/Shaders/outline.swsl @@ -31,6 +31,12 @@ uniform highp float outline_width; // = 2.0; uniform highp vec4 outline_color; // =vec4(1.0,0.0,0.0,0.33); uniform bool outline_fullbright; // =false; uniform highp float light_boost; // = 4.0; +uniform highp float light_gamma; // = 1.0; +uniform highp float light_whitepoint; // = 1.0; + +highp float grayscale(highp vec3 col) { + return mix(0.0, 1.0, (col.r * 0.299) + (col.g * 0.587) + (col.b * 0.114)); //These luminance values are taken from Rec. ITU-R BT.601-7. This isn't suitable for player-facing grayscaling due to SDTV having a funky colorspace, but it's perfect for outlines. +} void fragment() { highp vec4 col = zTexture(UV); @@ -72,7 +78,7 @@ void fragment() { maxa = max(a, maxa); mina = min(a, mina); - lowp float sampledLight = outline_fullbright ? 1.0 : sqrt(mix(0.0, 1.0, (lightSample.r * 0.34) + (lightSample.g * 0.5) + (lightSample.b * 0.16)) * light_boost); - COLOR = mix(col, outline_color * vec4(vec3(sampledLight), 1.0), maxa - col.a); + lowp float sampledLight = outline_fullbright ? 1.0 : clamp( (pow( grayscale(lightSample.rgb) * light_whitepoint, light_gamma) / light_whitepoint ) * light_boost, 0.0, 1.0); + COLOR = mix(col, outline_color * vec4(vec3(1.0), sampledLight), maxa - col.a); lightSample = vec3(1.0); } -- 2.51.2