From 5d44c186691f42a8a64c895c67079ebe2515ea71 Mon Sep 17 00:00:00 2001 From: yum Date: Sat, 12 Aug 2023 17:49:41 -0700 Subject: Improve numerical stability in raymarcher Increase units by a factor of 100 to avoid running into numerical instability on 32-bit floats. This comes at zero measured performance cost. This makes a visible difference in quality. Other minor changes: * Raymarching loop tries to get up to 4x closer than MINIMUM_HIT_DISTANCE before bailing out. This comes at no measured performance cost. * Convert `fixed` types to `float` in STT_text.cginc. --- Shaders/STT_text.cginc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Shaders/STT_text.cginc') diff --git a/Shaders/STT_text.cginc b/Shaders/STT_text.cginc index 095df6a..dae613b 100644 --- a/Shaders/STT_text.cginc +++ b/Shaders/STT_text.cginc @@ -38,7 +38,7 @@ float prng(float2 p) return frac(sin(dot(p, float2(561.0, 885.0))) * 776.2) / 2.0; } -bool f3ltf3(fixed3 a, fixed3 b) +bool f3ltf3(float3 a, float3 b) { return (a[0] < b[0]) * (a[1] < b[1]) * @@ -125,7 +125,7 @@ float4 GetLetter(float2 uv) { letter_uv.x += lerp(0, (noise - 0.5) * iddx / 4.0, add_dithering); letter_uv.y += lerp(0, (noise - 0.5) * iddy / 4.0, add_dithering); - fixed4 text = fixed4(0, 0, 0, 0); + float4 text = float4(0, 0, 0, 0); int which_texture = (int) floor(letter / (uint) (64 * 128)); [forcecase] switch (which_texture) { @@ -165,14 +165,14 @@ float4 GetLetter(float2 uv) { break; default: // Return some distinctive pattern that will look like a bug. - return fixed4(1, 0, _SinTime[0], 1); + return float4(1, 0, _SinTime[0], 1); } // The edges of each letter cell can be slightly grey due to mip maps. // Detect this and shade it as the background. - fixed3 grey = 0.7; + float3 grey = 0.7; bool disc = !(!f3ltf3(text.rgb, grey) * !discard_text * !is_emote); - return lerp(fixed4(text.rgb, 1), 0, disc); + return lerp(float4(text.rgb, 1), 0, disc); } #endif // __STT_TEXT_INC__ -- cgit v1.2.3