| 1 |
// Color Look Up Table Shader ================================================== |
| 2 |
|
| 3 |
// Configuration --------------------------------------------------------------- |
| 4 |
|
| 5 |
#define CLUT_ENABLED 1 |
| 6 |
|
| 7 |
// Key to toggle CLUT on or off. See MSDN, "Virtual-Key Codes", |
| 8 |
// msdn.microsoft.com/library/windows/desktop/dd375731%28v=vs.85%29.aspx |
| 9 |
// for a list of key codes. |
| 10 |
#define CLUT_TOGGLEKEY 0x24 // 0x24 = HOME key |
| 11 |
|
| 12 |
// NOTE that only textures with a height of 2 ^ n and a width of <height> ^ 2 |
| 13 |
// will work correctly! E.g. <width>x<height>: 256x16, 1024x32, 4096x64 |
| 14 |
#define CLUT_TEXTURE "ColorLookupTable.png" |
| 15 |
#define CLUT_TEXTURE_WIDTH ${WIDTH} |
| 16 |
#define CLUT_SIZE ${HEIGHT} |
| 17 |
|
| 18 |
// END Configuration ----------------------------------------------------------- |
| 19 |
|
| 20 |
#pragma message "\nColor Look Up Table Shader ${VERSION}\n" |
| 21 |
#pragma reshade showtogglemessage |
| 22 |
|
| 23 |
texture2D ColorLookupTable_texColor : COLOR; |
| 24 |
|
| 25 |
texture ColorLookupTable_texCLUT < string source = CLUT_TEXTURE; > |
| 26 |
{ |
| 27 |
Width = CLUT_TEXTURE_WIDTH; |
| 28 |
Height = CLUT_SIZE; |
| 29 |
Format = ${FORMAT}; |
| 30 |
}; |
| 31 |
|
| 32 |
sampler2D ColorLookupTable_samplerColor |
| 33 |
{ |
| 34 |
Texture = ColorLookupTable_texColor; |
| 35 |
MinFilter = LINEAR; |
| 36 |
MagFilter = LINEAR; |
| 37 |
MipFilter = LINEAR; |
| 38 |
AddressU = Clamp; |
| 39 |
AddressV = Clamp; |
| 40 |
}; |
| 41 |
|
| 42 |
sampler2D ColorLookupTable_samplerCLUT |
| 43 |
{ |
| 44 |
Texture = ColorLookupTable_texCLUT; |
| 45 |
MinFilter = LINEAR; |
| 46 |
MagFilter = LINEAR; |
| 47 |
MipFilter = LINEAR; |
| 48 |
AddressU = Clamp; |
| 49 |
AddressV = Clamp; |
| 50 |
}; |
| 51 |
|
| 52 |
void ColorLookupTable_VS(in uint id : SV_VertexID, |
| 53 |
out float4 position : SV_Position, |
| 54 |
out float2 texcoord : TEXCOORD0) |
| 55 |
{ |
| 56 |
texcoord.x = (id == 2) ? 2.0 : 0.0; |
| 57 |
texcoord.y = (id == 1) ? 2.0 : 0.0; |
| 58 |
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); |
| 59 |
} |
| 60 |
|
| 61 |
#define CLUTscale float2(1.0 / CLUT_TEXTURE_WIDTH, 1.0 / CLUT_SIZE) |
| 62 |
|
| 63 |
float4 ColorLookupTable_PS(in float4 position : SV_Position, |
| 64 |
in float2 texcoord : TEXCOORD) : SV_Target |
| 65 |
{ |
| 66 |
float4 color = tex2D(ColorLookupTable_samplerColor, texcoord.xy); |
| 67 |
|
| 68 |
float3 CLUTcoord = float3((color.rg * (CLUT_SIZE - 1) + 0.5) * CLUTscale, |
| 69 |
color.b * (CLUT_SIZE - 1)); |
| 70 |
float shift = floor(CLUTcoord.z); |
| 71 |
CLUTcoord.x += shift * CLUTscale.y; |
| 72 |
color.rgb = lerp(tex2D(ColorLookupTable_samplerCLUT, CLUTcoord.xy).rgb, |
| 73 |
tex2D(ColorLookupTable_samplerCLUT, |
| 74 |
float2(CLUTcoord.x + CLUTscale.y, CLUTcoord.y)).rgb, |
| 75 |
CLUTcoord.z - shift); |
| 76 |
|
| 77 |
return color; |
| 78 |
} |
| 79 |
|
| 80 |
technique ColorLookupTable < bool enabled = CLUT_ENABLED; toggle = CLUT_TOGGLEKEY; > |
| 81 |
{ |
| 82 |
pass |
| 83 |
{ |
| 84 |
VertexShader = ColorLookupTable_VS; |
| 85 |
PixelShader = ColorLookupTable_PS; |
| 86 |
} |
| 87 |
} |