From 04b50c093397b596a3da2ab16f86c37341bf2f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Wed, 24 Sep 2025 07:53:06 +0200 Subject: [PATCH] crt shader improvements --- WickedEngine/shaders/crt_screenCS.hlsl | 6 +++--- WickedEngine/wiRenderPath3D.cpp | 4 ++-- WickedEngine/wiRenderer.cpp | 7 +++++-- WickedEngine/wiRenderer.h | 4 +++- WickedEngine/wiVersion.cpp | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/WickedEngine/shaders/crt_screenCS.hlsl b/WickedEngine/shaders/crt_screenCS.hlsl index fdade2c12..98750e652 100644 --- a/WickedEngine/shaders/crt_screenCS.hlsl +++ b/WickedEngine/shaders/crt_screenCS.hlsl @@ -41,12 +41,12 @@ static const float maskLight=1.5; // sRGB to Linear. // Assuing using sRGB typed textures this should not be needed. float ToLinear1(float c){return(c<=0.04045)?c/12.92:pow((c+0.055)/1.055,2.4);} -float3 ToLinear(float3 c){return float3(ToLinear1(c.r),ToLinear1(c.g),ToLinear1(c.b));} +float3 ToLinear(float3 c){return postprocess.params0.y ? float3(ToLinear1(c.r),ToLinear1(c.g),ToLinear1(c.b)) : c;} // Linear to sRGB. // Assuing using sRGB typed textures this should not be needed. float ToSrgb1(float c){return(c<0.0031308?c*12.92:1.055*pow(c,0.41666)-0.055);} -float3 ToSrgb(float3 c){return float3(ToSrgb1(c.r),ToSrgb1(c.g),ToSrgb1(c.b));} +float3 ToSrgb(float3 c){return postprocess.params0.y ? float3(ToSrgb1(c.r),ToSrgb1(c.g),ToSrgb1(c.b)) : c;} // Nearest emulated sample given floating point position and texel offset. // Also zero's off screen. @@ -157,7 +157,7 @@ void main(uint3 DTid : SV_DispatchThreadID) float2 uv = (DTid.xy + 0.5) * postprocess.resolution_rcp.xy; //uv = Warp(uv); color.rgb=Tri(uv)*Mask(DTid.xy); - color.rgb *= 1 + sin(GetTime() * 100) * postprocess.params0.x; + color.rgb *= 1 + postprocess.params0.x; color.rgb=ToSrgb(color.rgb); output[DTid.xy] = color; diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index d386768e7..12cd053fe 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -2505,7 +2505,7 @@ namespace wi if (getCRTFilterEnabled()) { - wi::renderer::Postprocess_CRT(*rt_read, *rt_write, cmd); + wi::renderer::Postprocess_CRT(*rt_read, *rt_write, cmd, 0, 0, true); std::swap(rt_read, rt_write); } @@ -2730,7 +2730,7 @@ namespace wi if (camera.IsCRT() && getSceneUpdateEnabled()) { - wi::renderer::Postprocess_CRT(camera.render_to_texture.rendertarget_render, camera.render_to_texture.rendertarget_display, cmd, 0.2f); + wi::renderer::Postprocess_CRT(camera.render_to_texture.rendertarget_render, camera.render_to_texture.rendertarget_display, cmd, 0.2f, frameCB.time * 100, false); std::swap(camera.render_to_texture.rendertarget_render, camera.render_to_texture.rendertarget_display); } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 50f73bd29..71a65fb9a 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -16851,7 +16851,9 @@ void Postprocess_CRT( const Texture& input, const Texture& output, CommandList cmd, - float flicker + float flicker_amount, + float flicker_time, + bool srgb ) { ScopedGPUProfiling("Postprocess_CRT", cmd); @@ -16868,7 +16870,8 @@ void Postprocess_CRT( postprocess.resolution.y = desc.height; postprocess.resolution_rcp.x = 1.0f / postprocess.resolution.x; postprocess.resolution_rcp.y = 1.0f / postprocess.resolution.y; - postprocess.params0.x = flicker; + postprocess.params0.x = std::sin(flicker_time) * flicker_amount; + postprocess.params0.y = srgb ? 1.0f : 0.0f; device->PushConstants(&postprocess, sizeof(postprocess), cmd); const GPUResource* uavs[] = { diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 74b249987..669167f15 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -849,7 +849,9 @@ namespace wi::renderer const wi::graphics::Texture& input, const wi::graphics::Texture& output, wi::graphics::CommandList cmd, - float flicker = 0 + float flicker_amount = 0, + float flicker_timer = 0, + bool srgb = true // if true, then srgb->linear->crt filter->srgb conversion will be done ); enum class Tonemap { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index fb2e549ab..0b5117625 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 828; + const int revision = 829; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);