Added Gameboy and NES render modes

This commit is contained in:
Robert Beckebans 2024-07-31 18:11:43 +02:00
parent ea78cf42e3
commit 676c970886
14 changed files with 693 additions and 149 deletions

View file

@ -9,7 +9,7 @@ bind "F3" "toggle r_forceAmbient 0.5 1.0 0"
bind "F4" "toggle r_skipInteractions"
bind "F5" "savegame quick"
bind "F6" "toggle r_showLightGrid 1 3 4 0"
bind "F7" "toggle r_renderMode 0 1 2 3 4 5 6 7"
bind "F7" "toggle r_renderMode 0 1 2 3 4 5 6 7 8 9 10 11"
bind "F8" "toggle r_useCRTPostFX 0 1 2"
bind "F9" "loadgame quick"
//bind "F10" "toggle com_fixedTic"

View file

@ -613,8 +613,8 @@ void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::AdjustFi
// RB begin
case SYSTEM_FIELD_RENDERMODE:
{
static const int numValues = 8;
static const int values[numValues] = { 0, 1, 2, 3, 4, 5, 6, 7 };
static const int numValues = 12;
static const int values[numValues] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
r_renderMode.SetInteger( AdjustOption( r_renderMode.GetInteger(), values, numValues, adjustAmount ) );
break;
}
@ -793,14 +793,18 @@ idSWFScriptVar idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings
}
case SYSTEM_FIELD_RENDERMODE:
{
static const int numValues = 8;
static const int numValues = 12;
static const char* values[numValues] =
{
"Doom 3",
"2-bit",
"2-bit Hi",
"Commodore 64",
"Commodore 64 Hi",
"Amstrad CPC 6128",
"Amstrad CPC 6128 Hi",
"NES",
"NES Hi",
"Sega Genesis",
"Sega Genesis Highres",
"Sony PSX",

View file

@ -443,14 +443,18 @@ float idConsoleLocal::DrawFPS( float y )
aaMode = aaValues[ r_antiAliasing.GetInteger() ];
}
static const int rrNumValues = 8;
static const int rrNumValues = 12;
static const char* rrValues[rrNumValues] =
{
"None",
"Doom",
"2-bit",
"2-bit Hi",
"C64",
"C64 Hi",
"CPC",
"CPC Hi",
"NES",
"NES Hi",
"Sega",
"Sega Hi",
"Sony PSX",

View file

@ -6364,7 +6364,13 @@ void idRenderBackend::PostProcess( const void* data )
float jitterTexScale[4] = {};
if( r_renderMode.GetInteger() == RENDERMODE_C64 || r_renderMode.GetInteger() == RENDERMODE_C64_HIGHRES )
if( r_renderMode.GetInteger() == RENDERMODE_2BIT || r_renderMode.GetInteger() == RENDERMODE_2BIT_HIGHRES )
{
jitterTexScale[0] = r_renderMode.GetInteger() == RENDERMODE_2BIT_HIGHRES ? 2.0 : 1.0;
renderProgManager.BindShader_PostProcess_Retro2Bit();
}
else if( r_renderMode.GetInteger() == RENDERMODE_C64 || r_renderMode.GetInteger() == RENDERMODE_C64_HIGHRES )
{
jitterTexScale[0] = r_renderMode.GetInteger() == RENDERMODE_C64_HIGHRES ? 2.0 : 1.0;
@ -6376,6 +6382,12 @@ void idRenderBackend::PostProcess( const void* data )
renderProgManager.BindShader_PostProcess_RetroCPC();
}
else if( r_renderMode.GetInteger() == RENDERMODE_NES || r_renderMode.GetInteger() == RENDERMODE_NES_HIGHRES )
{
jitterTexScale[0] = r_renderMode.GetInteger() == RENDERMODE_NES_HIGHRES ? 2.0 : 1.0;
renderProgManager.BindShader_PostProcess_RetroNES();
}
else if( r_renderMode.GetInteger() == RENDERMODE_GENESIS || r_renderMode.GetInteger() == RENDERMODE_GENESIS_HIGHRES )
{
jitterTexScale[0] = r_renderMode.GetInteger() == RENDERMODE_GENESIS_HIGHRES ? 2.0 : 1.0;

View file

@ -1264,10 +1264,14 @@ extern idCVar r_crtVignette;
enum RenderMode
{
RENDERMODE_DOOM,
RENDERMODE_2BIT,
RENDERMODE_2BIT_HIGHRES,
RENDERMODE_C64,
RENDERMODE_C64_HIGHRES,
RENDERMODE_CPC,
RENDERMODE_CPC_HIGHRES,
RENDERMODE_NES,
RENDERMODE_NES_HIGHRES,
RENDERMODE_GENESIS,
RENDERMODE_GENESIS_HIGHRES,
RENDERMODE_PSX,

View file

@ -531,8 +531,10 @@ void idRenderProgManager::Init( nvrhi::IDevice* device )
{ BUILTIN_SKYBOX, "builtin/legacy/skybox", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_WOBBLESKY, "builtin/legacy/wobblesky", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_POSTPROCESS, "builtin/post/postprocess", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_POSTPROCESS_RETRO_2BIT, "builtin/post/retro_2bit", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_POSTPROCESS_RETRO_C64, "builtin/post/retro_c64", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_POSTPROCESS_RETRO_CPC, "builtin/post/retro_cpc", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL2 },
{ BUILTIN_POSTPROCESS_RETRO_NES, "builtin/post/retro_nes", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_POSTPROCESS_RETRO_GENESIS, "builtin/post/retro_genesis", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_POSTPROCESS_RETRO_PSX, "builtin/post/retro_ps1", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
{ BUILTIN_CRT_MATTIAS, "builtin/post/crt_mattias", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },

View file

@ -369,8 +369,10 @@ enum
BUILTIN_WOBBLESKY,
BUILTIN_POSTPROCESS,
// RB begin
BUILTIN_POSTPROCESS_RETRO_2BIT, // CGA, Gameboy, cool for Gamejams
BUILTIN_POSTPROCESS_RETRO_C64, // Commodore 64
BUILTIN_POSTPROCESS_RETRO_CPC, // Amstrad 6128
BUILTIN_POSTPROCESS_RETRO_NES, // NES
BUILTIN_POSTPROCESS_RETRO_GENESIS, // Sega Genesis / Megadrive
BUILTIN_POSTPROCESS_RETRO_PSX, // Sony Playstation 1
BUILTIN_CRT_MATTIAS,
@ -836,6 +838,16 @@ public:
BindShader_Builtin( BUILTIN_POSTPROCESS_RETRO_CPC );
}
void BindShader_PostProcess_Retro2Bit()
{
BindShader_Builtin( BUILTIN_POSTPROCESS_RETRO_2BIT );
}
void BindShader_PostProcess_RetroNES()
{
BindShader_Builtin( BUILTIN_POSTPROCESS_RETRO_NES );
}
void BindShader_PostProcess_RetroGenesis()
{
BindShader_Builtin( BUILTIN_POSTPROCESS_RETRO_GENESIS );

View file

@ -302,7 +302,7 @@ idCVar r_crtVignette( "r_crtVignette", "0.8", CVAR_RENDERER | CVAR_FLOAT | CVAR_
idCVar r_retroDitherScale( "r_retroDitherScale", "0.3", CVAR_RENDERER | CVAR_FLOAT | CVAR_NEW, "" );
idCVar r_renderMode( "r_renderMode", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER | CVAR_NEW, "0 = Doom, 1 = Commodore 64, 2 = Commodore 64 Highres, 3 = Amstrad CPC 6128, 4 = Amstrad CPC 6128 Highres, 5 = Sega Genesis, 6 = Sega Genesis Highres, 7 = Sony PSX", 0, 7 );
idCVar r_renderMode( "r_renderMode", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER | CVAR_NEW, "0 = Doom, 1 = Commodore 64, 2 = Commodore 64 Highres, 3 = Amstrad CPC 6128, 4 = Amstrad CPC 6128 Highres, 5 = Gameboy, 6 = Gameboy Highres, 7 = NES, 8 = NES Highres, 9 = Sega Genesis, 10 = Sega Genesis Highres, 11 = Sony PSX", 0, 11 );
idCVar r_psxVertexJitter( "r_psxVertexJitter", "0.5", CVAR_RENDERER | CVAR_FLOAT | CVAR_NEW, "", 0.0f, 0.75f );
// RB end

View file

@ -0,0 +1,224 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2024 Robert Beckebans
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 <http://www.gnu.org/licenses/>.
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*
Texture2D t_BaseColor : register( t0 VK_DESCRIPTOR_SET( 0 ) );
Texture2D t_BlueNoise : register( t1 VK_DESCRIPTOR_SET( 0 ) );
SamplerState s_LinearClamp : register(s0 VK_DESCRIPTOR_SET( 1 ) );
SamplerState s_LinearWrap : 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*
#define RESOLUTION_DIVISOR 4.0
#define NUM_COLORS 4
float3 Average( float3 pal[NUM_COLORS] )
{
float3 sum = _float3( 0 );
for( int i = 0; i < NUM_COLORS; i++ )
{
sum += pal[i];
}
return sum / float( NUM_COLORS );
}
float3 Deviation( float3 pal[NUM_COLORS] )
{
float3 sum = _float3( 0 );
float3 avg = Average( pal );
for( int i = 0; i < NUM_COLORS; i++ )
{
sum += abs( pal[i] - avg );
}
return sum / float( NUM_COLORS );
}
// squared distance to avoid the sqrt of distance function
float ColorCompare( float3 a, float3 b )
{
float3 diff = b - a;
return dot( diff, diff );
}
// find nearest palette color using Euclidean distance
float3 LinearSearch( float3 c, float3 pal[NUM_COLORS] )
{
int index = 0;
float minDist = ColorCompare( c, pal[0] );
for( int i = 1; i < NUM_COLORS; i++ )
{
float dist = ColorCompare( c, pal[i] );
if( dist < minDist )
{
minDist = dist;
index = i;
}
}
return pal[index];
}
#define RGB(r, g, b) float3(float(r)/255.0, float(g)/255.0, float(b)/255.0)
void main( PS_IN fragment, out PS_OUT result )
{
#if 0
// Gameboy
const float3 palette[NUM_COLORS] = // 4
{
RGB( 27, 42, 9 ),
RGB( 14, 69, 11 ),
RGB( 73, 107, 34 ),
RGB( 154, 158, 63 ),
};
#elif 0
// Moonlight GB
// https://lospec.com/palette-list/moonlight-gb
const float3 palette[NUM_COLORS] = // 4
{
RGB( 15, 5, 45 ),
RGB( 32, 54, 113 ),
RGB( 54, 134, 143 ),
RGB( 95, 199, 93 ),
};
#elif 0
// Hollow
// https://lospec.com/palette-list/hollow
const float3 palette[NUM_COLORS] = // 4
{
RGB( 15, 15, 27 ),
RGB( 86, 90, 117 ),
RGB( 198, 183, 190 ),
RGB( 250, 251, 246 ),
};
#else
// https://lospec.com/palette-list/2bit-demichrome
const float3 palette[NUM_COLORS] = // 4
{
RGB( 33, 30, 32 ),
RGB( 85, 85, 104 ),
RGB( 160, 160, 139 ),
RGB( 233, 239, 236 ),
};
#endif
float2 uv = ( fragment.texcoord0 );
float2 uvPixelated = floor( fragment.position.xy / RESOLUTION_DIVISOR ) * RESOLUTION_DIVISOR;
float3 quantizationPeriod = _float3( 1.0 / NUM_COLORS );
float3 quantDeviation = Deviation( palette );
// get pixellated base color
float3 color = t_BaseColor.Sample( s_LinearClamp, uvPixelated * rpWindowCoord.xy ).rgb;
float2 uvDither = uvPixelated;
//if( rpJitterTexScale.x > 1.0 )
{
uvDither = fragment.position.xy / ( RESOLUTION_DIVISOR / rpJitterTexScale.x );
}
float dither = DitherArray8x8( uvDither ) - 0.5;
#if 0
if( uv.y < 0.0625 )
{
color = HSVToRGB( float3( uv.x, 1.0, uv.y * 16.0 ) );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.125 )
{
// quantized
color = HSVToRGB( float3( uv.x, 1.0, ( uv.y - 0.0625 ) * 16.0 ) );
color = LinearSearch( color, palette );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.1875 )
{
// dithered quantized
color = HSVToRGB( float3( uv.x, 1.0, ( uv.y - 0.125 ) * 16.0 ) );
color.rgb += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
color = LinearSearch( color, palette );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.25 )
{
color = _float3( uv.x );
color = floor( color * NUM_COLORS ) * ( 1.0 / ( NUM_COLORS - 1.0 ) );
color += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
color = LinearSearch( color.rgb, palette );
result.color = float4( color, 1.0 );
return;
}
#endif
color.rgb += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
// find closest color match from C64 color palette
color = LinearSearch( color.rgb, palette );
result.color = float4( color, 1.0 );
}

View file

@ -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 <http://www.gnu.org/licenses/>.
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;
}

View file

@ -53,7 +53,7 @@ struct PS_OUT
#define RESOLUTION_DIVISOR 4.0
#define NUM_COLORS 4 // original 27
#define NUM_COLORS 32 // original 27
float3 Average( float3 pal[NUM_COLORS] )
@ -319,6 +319,7 @@ void main( PS_IN fragment, out PS_OUT result )
{
#if 0
// Amstrad CPC colors https://www.cpcwiki.eu/index.php/CPC_Palette
// those are the original colors but they are too saturated and kinda suck
const float3 palette[NUM_COLORS] =
{
RGB( 0, 0, 0 ), // black
@ -364,7 +365,7 @@ void main( PS_IN fragment, out PS_OUT result )
#endif
};
#elif 0
#elif 1
// Tweaked LOSPEC CPC BOY PALETTE which is less saturated by Arne Niklas Jansson
// https://lospec.com/palette-list/cpc-boy
@ -404,134 +405,6 @@ void main( PS_IN fragment, out PS_OUT result )
RGB( 36, 49, 55 ),
};
#elif 0
// NES 1
// https://lospec.com/palette-list/nintendo-entertainment-system
const float3 palette[NUM_COLORS] = // 55
{
RGB( 0, 0, 0 ),
RGB( 252, 252, 252 ),
RGB( 248, 248, 248 ),
RGB( 188, 188, 188 ),
RGB( 124, 124, 124 ),
RGB( 164, 228, 252 ),
RGB( 60, 188, 252 ),
RGB( 0, 120, 248 ),
RGB( 0, 0, 252 ),
RGB( 184, 184, 248 ),
RGB( 104, 136, 252 ),
RGB( 0, 88, 248 ),
RGB( 0, 0, 188 ),
RGB( 216, 184, 248 ),
RGB( 152, 120, 248 ),
RGB( 104, 68, 252 ),
RGB( 68, 40, 188 ),
RGB( 248, 184, 248 ),
RGB( 248, 120, 248 ),
RGB( 216, 0, 204 ),
RGB( 148, 0, 132 ),
RGB( 248, 164, 192 ),
RGB( 248, 88, 152 ),
RGB( 228, 0, 88 ),
RGB( 168, 0, 32 ),
RGB( 240, 208, 176 ),
RGB( 248, 120, 88 ),
RGB( 248, 56, 0 ),
RGB( 168, 16, 0 ),
RGB( 252, 224, 168 ),
RGB( 252, 160, 68 ),
RGB( 228, 92, 16 ),
RGB( 136, 20, 0 ),
RGB( 248, 216, 120 ),
RGB( 248, 184, 0 ),
RGB( 172, 124, 0 ),
RGB( 80, 48, 0 ),
RGB( 216, 248, 120 ),
RGB( 184, 248, 24 ),
RGB( 0, 184, 0 ),
RGB( 0, 120, 0 ),
RGB( 184, 248, 184 ),
RGB( 88, 216, 84 ),
RGB( 0, 168, 0 ),
RGB( 0, 104, 0 ),
RGB( 184, 248, 216 ),
RGB( 88, 248, 152 ),
RGB( 0, 168, 68 ),
RGB( 0, 88, 0 ),
RGB( 0, 252, 252 ),
RGB( 0, 232, 216 ),
RGB( 0, 136, 136 ),
RGB( 0, 64, 88 ),
RGB( 248, 216, 248 ),
RGB( 120, 120, 120 ),
};
#elif 0
// NES Advanced
// https://lospec.com/palette-list/nes-advanced
const float3 palette[NUM_COLORS] = // 55
{
RGB( 0, 0, 0 ),
RGB( 38, 35, 47 ),
RGB( 49, 64, 71 ),
RGB( 89, 109, 98 ),
RGB( 146, 156, 116 ),
RGB( 200, 197, 163 ),
RGB( 252, 252, 252 ),
RGB( 27, 55, 127 ),
RGB( 20, 122, 191 ),
RGB( 64, 175, 221 ),
RGB( 178, 219, 244 ),
RGB( 24, 22, 103 ),
RGB( 59, 44, 150 ),
RGB( 112, 106, 225 ),
RGB( 143, 149, 238 ),
RGB( 68, 10, 65 ),
RGB( 129, 37, 147 ),
RGB( 204, 75, 185 ),
RGB( 236, 153, 219 ),
RGB( 63, 0, 17 ),
RGB( 179, 28, 53 ),
RGB( 239, 32, 100 ),
RGB( 242, 98, 130 ),
RGB( 150, 8, 17 ),
RGB( 232, 24, 19 ),
RGB( 167, 93, 105 ),
RGB( 236, 158, 164 ),
RGB( 86, 13, 4 ),
RGB( 196, 54, 17 ),
RGB( 226, 106, 18 ),
RGB( 240, 175, 102 ),
RGB( 42, 26, 20 ),
RGB( 93, 52, 42 ),
RGB( 166, 110, 70 ),
RGB( 223, 156, 110 ),
RGB( 142, 78, 17 ),
RGB( 216, 149, 17 ),
RGB( 234, 209, 30 ),
RGB( 245, 235, 107 ),
RGB( 47, 84, 28 ),
RGB( 90, 131, 27 ),
RGB( 162, 187, 30 ),
RGB( 198, 223, 107 ),
RGB( 15, 69, 15 ),
RGB( 0, 139, 18 ),
RGB( 11, 203, 18 ),
RGB( 62, 243, 63 ),
RGB( 17, 81, 83 ),
RGB( 12, 133, 99 ),
RGB( 4, 191, 121 ),
RGB( 106, 230, 170 ),
RGB( 38, 39, 38 ),
RGB( 81, 79, 76 ),
RGB( 136, 126, 131 ),
RGB( 179, 170, 192 ),
};
#elif 0
// Atari STE
@ -613,17 +486,6 @@ void main( PS_IN fragment, out PS_OUT result )
RGB( 46, 43, 18 ),
};
#elif 0
// Gameboy
const float3 palette[NUM_COLORS] = // 4
{
RGB( 27, 42, 9 ),
RGB( 14, 69, 11 ),
RGB( 73, 107, 34 ),
RGB( 154, 158, 63 ),
};
#elif 0
// Hollow

View file

@ -0,0 +1,306 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2024 Robert Beckebans
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 <http://www.gnu.org/licenses/>.
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*
Texture2D t_BaseColor : register( t0 VK_DESCRIPTOR_SET( 0 ) );
Texture2D t_BlueNoise : register( t1 VK_DESCRIPTOR_SET( 0 ) );
SamplerState s_LinearClamp : register(s0 VK_DESCRIPTOR_SET( 1 ) );
SamplerState s_LinearWrap : 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*
#define RESOLUTION_DIVISOR 4.0
#define NUM_COLORS 55
float3 Average( float3 pal[NUM_COLORS] )
{
float3 sum = _float3( 0 );
for( int i = 0; i < NUM_COLORS; i++ )
{
sum += pal[i];
}
return sum / float( NUM_COLORS );
}
float3 Deviation( float3 pal[NUM_COLORS] )
{
float3 sum = _float3( 0 );
float3 avg = Average( pal );
for( int i = 0; i < NUM_COLORS; i++ )
{
sum += abs( pal[i] - avg );
}
return sum / float( NUM_COLORS );
}
// squared distance to avoid the sqrt of distance function
float ColorCompare( float3 a, float3 b )
{
float3 diff = b - a;
return dot( diff, diff );
}
// find nearest palette color using Euclidean distance
float3 LinearSearch( float3 c, float3 pal[NUM_COLORS] )
{
int index = 0;
float minDist = ColorCompare( c, pal[0] );
for( int i = 1; i < NUM_COLORS; i++ )
{
float dist = ColorCompare( c, pal[i] );
if( dist < minDist )
{
minDist = dist;
index = i;
}
}
return pal[index];
}
#define RGB(r, g, b) float3(float(r)/255.0, float(g)/255.0, float(b)/255.0)
void main( PS_IN fragment, out PS_OUT result )
{
#if 0
// NES 1
// https://lospec.com/palette-list/nintendo-entertainment-system
const float3 palette[NUM_COLORS] = // 55
{
RGB( 0, 0, 0 ),
RGB( 252, 252, 252 ),
RGB( 248, 248, 248 ),
RGB( 188, 188, 188 ),
RGB( 124, 124, 124 ),
RGB( 164, 228, 252 ),
RGB( 60, 188, 252 ),
RGB( 0, 120, 248 ),
RGB( 0, 0, 252 ),
RGB( 184, 184, 248 ),
RGB( 104, 136, 252 ),
RGB( 0, 88, 248 ),
RGB( 0, 0, 188 ),
RGB( 216, 184, 248 ),
RGB( 152, 120, 248 ),
RGB( 104, 68, 252 ),
RGB( 68, 40, 188 ),
RGB( 248, 184, 248 ),
RGB( 248, 120, 248 ),
RGB( 216, 0, 204 ),
RGB( 148, 0, 132 ),
RGB( 248, 164, 192 ),
RGB( 248, 88, 152 ),
RGB( 228, 0, 88 ),
RGB( 168, 0, 32 ),
RGB( 240, 208, 176 ),
RGB( 248, 120, 88 ),
RGB( 248, 56, 0 ),
RGB( 168, 16, 0 ),
RGB( 252, 224, 168 ),
RGB( 252, 160, 68 ),
RGB( 228, 92, 16 ),
RGB( 136, 20, 0 ),
RGB( 248, 216, 120 ),
RGB( 248, 184, 0 ),
RGB( 172, 124, 0 ),
RGB( 80, 48, 0 ),
RGB( 216, 248, 120 ),
RGB( 184, 248, 24 ),
RGB( 0, 184, 0 ),
RGB( 0, 120, 0 ),
RGB( 184, 248, 184 ),
RGB( 88, 216, 84 ),
RGB( 0, 168, 0 ),
RGB( 0, 104, 0 ),
RGB( 184, 248, 216 ),
RGB( 88, 248, 152 ),
RGB( 0, 168, 68 ),
RGB( 0, 88, 0 ),
RGB( 0, 252, 252 ),
RGB( 0, 232, 216 ),
RGB( 0, 136, 136 ),
RGB( 0, 64, 88 ),
RGB( 248, 216, 248 ),
RGB( 120, 120, 120 ),
};
#else
// NES Advanced
// https://lospec.com/palette-list/nes-advanced
const float3 palette[NUM_COLORS] = // 55
{
RGB( 0, 0, 0 ),
RGB( 38, 35, 47 ),
RGB( 49, 64, 71 ),
RGB( 89, 109, 98 ),
RGB( 146, 156, 116 ),
RGB( 200, 197, 163 ),
RGB( 252, 252, 252 ),
RGB( 27, 55, 127 ),
RGB( 20, 122, 191 ),
RGB( 64, 175, 221 ),
RGB( 178, 219, 244 ),
RGB( 24, 22, 103 ),
RGB( 59, 44, 150 ),
RGB( 112, 106, 225 ),
RGB( 143, 149, 238 ),
RGB( 68, 10, 65 ),
RGB( 129, 37, 147 ),
RGB( 204, 75, 185 ),
RGB( 236, 153, 219 ),
RGB( 63, 0, 17 ),
RGB( 179, 28, 53 ),
RGB( 239, 32, 100 ),
RGB( 242, 98, 130 ),
RGB( 150, 8, 17 ),
RGB( 232, 24, 19 ),
RGB( 167, 93, 105 ),
RGB( 236, 158, 164 ),
RGB( 86, 13, 4 ),
RGB( 196, 54, 17 ),
RGB( 226, 106, 18 ),
RGB( 240, 175, 102 ),
RGB( 42, 26, 20 ),
RGB( 93, 52, 42 ),
RGB( 166, 110, 70 ),
RGB( 223, 156, 110 ),
RGB( 142, 78, 17 ),
RGB( 216, 149, 17 ),
RGB( 234, 209, 30 ),
RGB( 245, 235, 107 ),
RGB( 47, 84, 28 ),
RGB( 90, 131, 27 ),
RGB( 162, 187, 30 ),
RGB( 198, 223, 107 ),
RGB( 15, 69, 15 ),
RGB( 0, 139, 18 ),
RGB( 11, 203, 18 ),
RGB( 62, 243, 63 ),
RGB( 17, 81, 83 ),
RGB( 12, 133, 99 ),
RGB( 4, 191, 121 ),
RGB( 106, 230, 170 ),
RGB( 38, 39, 38 ),
RGB( 81, 79, 76 ),
RGB( 136, 126, 131 ),
RGB( 179, 170, 192 ),
};
#endif
float2 uv = ( fragment.texcoord0 );
float2 uvPixelated = floor( fragment.position.xy / RESOLUTION_DIVISOR ) * RESOLUTION_DIVISOR;
float3 quantizationPeriod = _float3( 1.0 / NUM_COLORS );
float3 quantDeviation = Deviation( palette );
// get pixellated base color
float3 color = t_BaseColor.Sample( s_LinearClamp, uvPixelated * rpWindowCoord.xy ).rgb;
float2 uvDither = uvPixelated;
//if( rpJitterTexScale.x > 1.0 )
{
uvDither = fragment.position.xy / ( RESOLUTION_DIVISOR / rpJitterTexScale.x );
}
float dither = DitherArray8x8( uvDither ) - 0.5;
#if 0
if( uv.y < 0.0625 )
{
color = HSVToRGB( float3( uv.x, 1.0, uv.y * 16.0 ) );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.125 )
{
// quantized
color = HSVToRGB( float3( uv.x, 1.0, ( uv.y - 0.0625 ) * 16.0 ) );
color = LinearSearch( color, palette );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.1875 )
{
// dithered quantized
color = HSVToRGB( float3( uv.x, 1.0, ( uv.y - 0.125 ) * 16.0 ) );
color.rgb += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
color = LinearSearch( color, palette );
result.color = float4( color, 1.0 );
return;
}
else if( uv.y < 0.25 )
{
color = _float3( uv.x );
color = floor( color * NUM_COLORS ) * ( 1.0 / ( NUM_COLORS - 1.0 ) );
color += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
color = LinearSearch( color.rgb, palette );
result.color = float4( color, 1.0 );
return;
}
#endif
color.rgb += float3( dither, dither, dither ) * quantDeviation * rpJitterTexScale.y;
// find closest color match from C64 color palette
color = LinearSearch( color.rgb, palette );
result.color = float4( color, 1.0 );
}

View file

@ -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 <http://www.gnu.org/licenses/>.
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;
}

View file

@ -56,6 +56,10 @@ builtin/post/retro_c64.vs.hlsl -T vs
builtin/post/retro_c64.ps.hlsl -T ps
builtin/post/retro_cpc.vs.hlsl -T vs
builtin/post/retro_cpc.ps.hlsl -T ps
builtin/post/retro_2bit.vs.hlsl -T vs
builtin/post/retro_2bit.ps.hlsl -T ps
builtin/post/retro_nes.vs.hlsl -T vs
builtin/post/retro_nes.ps.hlsl -T ps
builtin/post/retro_genesis.vs.hlsl -T vs
builtin/post/retro_genesis.ps.hlsl -T ps
builtin/post/retro_ps1.vs.hlsl -T vs