From 13f9ee8cfb73ffc58b78216ac3e846b0c3c9b7b1 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Thu, 28 Dec 2023 15:29:50 +0100 Subject: [PATCH] Added old MatthiasCRT shader to crt_newpixie.*.hlsl --- neo/renderer/RenderBackend.cpp | 11 +- neo/renderer/RenderCommon.h | 1 + neo/shaders/builtin/post/crt_newpixie.ps.hlsl | 123 ++++++++++++++++++ neo/shaders/builtin/post/crt_newpixie.vs.hlsl | 55 ++++++++ 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 neo/shaders/builtin/post/crt_newpixie.ps.hlsl create mode 100644 neo/shaders/builtin/post/crt_newpixie.vs.hlsl diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index 614d4b05..d8fed322 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -6178,6 +6178,7 @@ void idRenderBackend::PostProcess( const void* data ) void idRenderBackend::CRTPostProcess() { +#if 1 //renderLog.OpenMainBlock( MRB_POSTPROCESS ); renderLog.OpenBlock( "Render_CRTPostFX", colorBlue ); @@ -6209,6 +6210,13 @@ void idRenderBackend::CRTPostProcess() renderProgManager.BindShader_CrtNewPixie(); + float windowCoordParm[4]; + windowCoordParm[0] = 1.0f / screenWidth; + windowCoordParm[1] = 1.0f / screenHeight; + windowCoordParm[2] = screenWidth; + windowCoordParm[3] = screenHeight; + SetFragmentParm( RENDERPARM_WINDOWCOORD, windowCoordParm ); // rpWindowCoord + float jitterTexOffset[4]; jitterTexOffset[0] = 1.0f / globalImages->blueNoiseImage256->GetUploadWidth(); jitterTexOffset[1] = 1.0f / globalImages->blueNoiseImage256->GetUploadHeight(); @@ -6231,7 +6239,7 @@ void idRenderBackend::CRTPostProcess() } GL_SelectTexture( 0 ); - renderProgManager.Unbind(); + //renderProgManager.Unbind(); // copy LDR result to DX12 / Vulkan swapchain image BlitParameters blitParms; @@ -6245,4 +6253,5 @@ void idRenderBackend::CRTPostProcess() renderLog.CloseBlock(); //renderLog.CloseMainBlock(); +#endif } diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index f3f4f7fa..8cc17f0c 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -751,6 +751,7 @@ struct crtPostProcessCommand_t { renderCommand_t commandId; renderCommand_t* next; + int padding; }; //======================================================================= diff --git a/neo/shaders/builtin/post/crt_newpixie.ps.hlsl b/neo/shaders/builtin/post/crt_newpixie.ps.hlsl new file mode 100644 index 00000000..e5815c07 --- /dev/null +++ b/neo/shaders/builtin/post/crt_newpixie.ps.hlsl @@ -0,0 +1,123 @@ +/* +=========================================================================== + +newpixie CRT + +Copyright (c) 2016 Mattias Gustavsson +Copyright (c) 2023 Robert Beckebans + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +=========================================================================== +*/ + +#include "global_inc.hlsl" + + +// *INDENT-OFF* +Texture2D t_CurrentRender : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_BlueNoise : register( t1 VK_DESCRIPTOR_SET( 0 ) ); + +SamplerState LinearSampler : register(s0 VK_DESCRIPTOR_SET( 1 ) ); +SamplerState samp1 : register(s1 VK_DESCRIPTOR_SET( 1 ) ); // blue noise 256 + +struct PS_IN +{ + float4 position : SV_Position; + float2 texcoord0 : TEXCOORD0_centroid; +}; + +struct PS_OUT +{ + float4 color : SV_Target0; +}; +// *INDENT-ON* + + +float2 curve( float2 uv ) +{ + uv = ( uv - 0.5 ) * 2.0; + uv *= 1.1; + uv.x *= 1.0 + pow( ( abs( uv.y ) / 5.0 ), 2.0 ); + uv.y *= 1.0 + pow( ( abs( uv.x ) / 4.0 ), 2.0 ); + uv = ( uv / 2.0 ) + 0.5; + uv = uv * 0.92 + 0.04; + return uv; +} + +void main( PS_IN fragment, out PS_OUT result ) +{ + //float2 uv = ( fragment.texcoord0 ); + + //float4 color = t_Screen.Sample( samp0, uv ); + + float2 iResolution = rpWindowCoord.zw; + float iTime = rpJitterTexOffset.x; + + float2 q = fragment.texcoord0.xy; + q = saturate( q ); + + float2 uv = q; + uv = curve( uv ); + float3 oricol = t_CurrentRender.Sample( LinearSampler, float2( q.x, q.y ) ).xyz; + float3 col; + float x = sin( 0.3 * iTime + uv.y * 21.0 ) * sin( 0.7 * iTime + uv.y * 29.0 ) * sin( 0.3 + 0.33 * iTime + uv.y * 31.0 ) * 0.0017; + + col.r = t_CurrentRender.Sample( LinearSampler, float2( x + uv.x + 0.001, uv.y + 0.001 ) ).x + 0.05; + col.g = t_CurrentRender.Sample( LinearSampler, float2( x + uv.x + 0.000, uv.y - 0.002 ) ).y + 0.05; + col.b = t_CurrentRender.Sample( LinearSampler, float2( x + uv.x - 0.002, uv.y + 0.000 ) ).z + 0.05; + col.r += 0.08 * t_CurrentRender.Sample( LinearSampler, 0.75 * float2( x + 0.025, -0.027 ) + float2( uv.x + 0.001, uv.y + 0.001 ) ).x; + col.g += 0.05 * t_CurrentRender.Sample( LinearSampler, 0.75 * float2( x + -0.022, -0.02 ) + float2( uv.x + 0.000, uv.y - 0.002 ) ).y; + col.b += 0.08 * t_CurrentRender.Sample( LinearSampler, 0.75 * float2( x + -0.02, -0.018 ) + float2( uv.x - 0.002, uv.y + 0.000 ) ).z; + + col = clamp( col * 0.6 + 0.4 * col * col * 1.0, 0.0, 1.0 ); + + float vig = ( 0.0 + 1.0 * 16.0 * uv.x * uv.y * ( 1.0 - uv.x ) * ( 1.0 - uv.y ) ); + col *= _float3( pow( vig, 0.3 ) ); + + col *= float3( 0.95, 1.05, 0.95 ); + col *= 2.8; + + float scans = clamp( 0.35 + 0.35 * sin( 3.5 * iTime + uv.y * iResolution.y * 1.5 ), 0.0, 1.0 ); + + float s = pow( scans, 1.7 ); + col = col * _float3( 0.4 + 0.7 * s ) ; + + col *= 1.0 + 0.01 * sin( 110.0 * iTime ); + if( uv.x < 0.0 || uv.x > 1.0 ) + { + col *= 0.0; + } + if( uv.y < 0.0 || uv.y > 1.0 ) + { + col *= 0.0; + } + + col *= 1.0 - 0.65 * _float3( clamp( ( fmod( fragment.texcoord0.x, 2.0 ) - 1.0 ) * 2.0, 0.0, 1.0 ) ); + + float comp = smoothstep( 0.1, 0.9, sin( iTime ) ); + + // Remove the next line to stop cross-fade between original and postprocess + //col = mix( col, oricol, comp ); + + result.color = float4( col.x, col.y, col.z, 1.0 ); + + //result.color = tex2D(samp0, fragment.texcoord0.xy ); + //result.color = float4(1.0f, 1.0f, 1.0f, 1.0f); +} diff --git a/neo/shaders/builtin/post/crt_newpixie.vs.hlsl b/neo/shaders/builtin/post/crt_newpixie.vs.hlsl new file mode 100644 index 00000000..75519fe8 --- /dev/null +++ b/neo/shaders/builtin/post/crt_newpixie.vs.hlsl @@ -0,0 +1,55 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include "global_inc.hlsl" + + +// *INDENT-OFF* +struct VS_IN +{ + float4 position : POSITION; + float2 texcoord : TEXCOORD0; + float4 normal : NORMAL; + float4 tangent : TANGENT; + float4 color : COLOR0; + float4 color2 : COLOR1; +}; + +struct VS_OUT { + float4 position : SV_Position; + float2 texcoord0 : TEXCOORD0_centroid; +}; +// *INDENT-ON* + +void main( VS_IN vertex, out VS_OUT result ) +{ + result.position = vertex.position; + result.position.y = -result.position.y; + + result.texcoord0 = vertex.texcoord; +} \ No newline at end of file