Skip to content

Commit

Permalink
Added Daltonic post processing effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Aug 2, 2020
1 parent 2efd7a2 commit 3a9f68f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions Data/DaedalusX64/Shaders/Daltonic/desc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Color altering mode to help daltonic people.
64 changes: 64 additions & 0 deletions Data/DaedalusX64/Shaders/Daltonic/frag.cg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
float3 LMS(float3 input) {
float3 lms = 0;
lms[0] = (17.8824 * input.r) + (43.5161 * input.g) + (4.11935 * input.b);
lms[1] = (3.45565 * input.r) + (27.1554 * input.g) + (3.86714 * input.b);
lms[2] = (0.0299566 * input.r) + (0.184309 * input.g) + (1.46709 * input.b);
return lms;
}

float3 Correction(float3 input, float3 dlms) {
float3 err = 0;
err.r = (0.0809444479 * dlms[0]) + (-0.130504409 * dlms[1]) + (0.116721066 * dlms[2]);
err.g = (-0.0102485335 * dlms[0]) + (0.0540193266 * dlms[1]) + (-0.113614708 * dlms[2]);
err.b = (-0.000365296938 * dlms[0]) + (-0.00412161469 * dlms[1]) + (0.693511405 * dlms[2]);
err = (input - err);
float3 correction = 0;
correction.g = (err.r * 0.7) + (err.g * 1.0);
correction.b = (err.r * 0.7) + (err.b * 1.0);
return input + correction;
}

float4 FragProtanopia(float4 input)
{
float3 lms = LMS(input.rgb);
float3 dlms = 0;
dlms[0] = 0.0 * lms[0] + 2.02344 * lms[1] + -2.52581 * lms[2];
dlms[1] = 0.0 * lms[0] + 1.0 * lms[1] + 0.0 * lms[2];
dlms[2] = 0.0 * lms[0] + 0.0 * lms[1] + 1.0 * lms[2];
return float4(Correction(input, dlms), input.a);
}

float4 FragDeuteranopia(float4 input)
{
half3 lms = LMS(input.rgb);
float3 dlms = 0;
dlms[0] = 1.0 * lms[0] + 0.0 * lms[1] + 0.0 * lms[2];
dlms[1] = 0.494207 * lms[0] + 0.0 * lms[1] + 1.24827 * lms[2];
dlms[2] = 0.0 * lms[0] + 0.0 * lms[1] + 1.0 * lms[2];
return float4(Correction(input, dlms), input.a);
}

float4 FragTritanopia(float4 input)
{
float3 lms = LMS(input.rgb);
float3 dlms = 0;
dlms[0] = 1.0 * lms[0] + 0.0 * lms[1] + 0.0 * lms[2];
dlms[1] = 0.0 * lms[0] + 1.0 * lms[1] + 0.0 * lms[2];
dlms[2] = -0.395913 * lms[0] + 0.801109 * lms[1] + 0.0 * lms[2];
return float4(Correction(input, dlms), input.a);
}

float4 main(
float2 vTexcoord : TEXCOORD0,
uniform sampler2D colorMap : TEXUNIT0,
uniform float Protanopia,
uniform float Deuteranopia,
uniform float Tritanopia) : COLOR
{
float4 sample = tex2D(colorMap, vTexcoord);

if (Tritanopia > 1.0f) return FragTritanopia(sample);
else if (Deuteranopia > 1.0f) return FragDeuteranopia(sample);

return FragProtanopia(sample);
}
3 changes: 3 additions & 0 deletions Data/DaedalusX64/Shaders/Daltonic/unif.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Protanopia=1
Deuteranopia=1
Tritanopia=1
10 changes: 10 additions & 0 deletions Data/DaedalusX64/Shaders/Daltonic/vert.cg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
void main(
float3 position,
float2 texcoord,
uniform float4x4 wvp,
out float4 vPosition : POSITION,
out float2 vTexcoord : TEXCOORD0)
{
vPosition = mul(wvp,float4(position, 1.f));
vTexcoord = texcoord;
}

0 comments on commit 3a9f68f

Please sign in to comment.