Last active
January 16, 2023 01:09
-
-
Save Expack3/54acfd983926f5c054efbbd4b4fc54e6 to your computer and use it in GitHub Desktop.
Generic Palletizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generic Palletizer | |
//Created by abelcamarena https://www.shadertoy.com/view/tsKGDm | |
//Adapted by The MacGovern with assistance from Matsilagi and kingeric1992 | |
#include "ReShade.fxh" | |
#include "ReShadeUI.fxh" | |
uniform float PIXEL_FACTOR < | |
ui_type = "drag"; | |
ui_min = 32; ui_max=ReShade::ScreenSize.x; ui_step = 1; | |
ui_label = "SCreen Width"; | |
ui_tooltip = "Determines what screen width to emulate (lower number = bigger pixels)."; | |
> = 320; // Lower num - bigger pixels (this will be the screen width) | |
uniform float COLOR_FACTOR < | |
ui_type = "slider"; | |
ui_min = 1; ui_max=24; ui_step = 1; | |
ui_label = "Color Depth"; | |
ui_tooltip = "Determines the color reproduction quality (higher number = better quality)."; | |
> = 4; // Higher num - higher colors quality | |
static const float4x4 ditherTable = float4x4( | |
float4(-4.0, 0.0, -3.0, 1.0), | |
float4(2.0, -2.0, 3.0, -1.0), | |
float4(-3.0, 1.0, -4.0, 0.0), | |
float4(3.0, -1.0, 2.0, -2.0) | |
); | |
sampler2D SourcePointSampler | |
{ | |
Texture = ReShade::BackBufferTex; | |
MinFilter = POINT; | |
MagFilter = POINT; | |
MipFilter = POINT; | |
AddressU = CLAMP; | |
AddressV = CLAMP; | |
}; | |
float4 PS_GPallete(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target | |
{ | |
// Reduce pixels | |
float2 size = PIXEL_FACTOR * ReShade::ScreenSize.xy/ReShade::ScreenSize.x; | |
float2 coor = floor(vpos.xy/ReShade::ScreenSize.xy * size) ; | |
float2 uv = coor / size; | |
#if (__RENDERER__ >= 0x10000) | |
{ | |
uv.y = 1 - uv.y; | |
} | |
#endif | |
// Get source color | |
float3 col = tex2D(SourcePointSampler, uv).xyz; | |
// Dither | |
col += ditherTable[uint( coor.x ) % 4][uint( coor.y ) % 4] * 0.005; // last number is dithering strength | |
// Reduce colors | |
col = floor(col * COLOR_FACTOR) / COLOR_FACTOR; | |
// Output to screen | |
return float4(col,1); | |
} | |
technique GenericPalettizer | |
{ | |
pass LinearizeDepthPass | |
{ | |
VertexShader = PostProcessVS; | |
PixelShader = PS_GPallete; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment