Last active
November 2, 2015 11:25
-
-
Save Shell64/6a5e7d904633e5958efd to your computer and use it in GitHub Desktop.
Daltonism shader for LOVE
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
uniform float colorblind_mode = 0.0; | |
const mat3 protanopia = mat3(0.567, 0.433, 0 , 0.558, 0.442, 0 , 0 , 0.242 ,0.758); | |
const mat3 protanomaly = mat3(0.817, 0.183, 0 , 0.333, 0.667, 0 , 0 , 0.125 ,0.875); | |
const mat3 deuteranopia = mat3(0.625, 0.375, 0 , 0.7 , 0.3 , 0 , 0 , 0.3 ,0.7 ); | |
const mat3 deuteranomaly = mat3(0.8 , 0.2 , 0 , 0.258, 0.742, 0 , 0 , 0.142 ,0.858); | |
const mat3 tritanopia = mat3(0.95 , 0.05 , 0 , 0 , 0.433, 0.567, 0 , 0.475 ,0.525); | |
const mat3 tritanomaly = mat3(0.967, 0.033, 0 , 0 , 0.733, 0.267, 0 , 0.183 ,0.817); | |
const mat3 achromatopsia = mat3(0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587 ,0.114); | |
const mat3 achromatomaly = mat3(0.618, 0.320, 0.062, 0.163, 0.775, 0.062, 0.163, 0.320 ,0.516); | |
const mat3 RGBtoLMS = mat3( //Convert from color to LMS | |
17.8824, 43.5161, 4.11935, | |
3.45565, 27.1554, 3.86714, | |
0.0299566, 0.184309, 1.46709 | |
); | |
const mat3 LMStoRGB = mat3( //Convert from LMS to color | |
0.0809444479, -0.130504409, 0.116721066, | |
-0.0102485335, 0.0540193266, -0.113614708, | |
-0.000365296938, -0.00412161469, 0.693511405 | |
); | |
const mat3 ERRtoMOD = mat3( //Error modifications | |
0.0, 0.0, 0.0, | |
2.0, 2.0, 0.0, | |
2.0, 0.0, 2.0 | |
); | |
vec4 Simulate(vec4 color) { | |
vec3 lms_color = color.rgb; | |
if(colorblind_mode == 0.0) { | |
return color; | |
} else { | |
//Simulate color blindness | |
if(colorblind_mode == 1.0) { | |
lms_color = lms_color * protanopia; | |
} | |
else if(colorblind_mode == 1.5) { | |
lms_color = lms_color * protanomaly; | |
} | |
else if(colorblind_mode == 2.0) { | |
lms_color = lms_color * deuteranopia; | |
} | |
else if(colorblind_mode == 2.5) { | |
lms_color = lms_color * deuteranomaly; | |
} | |
else if(colorblind_mode == 3.0) { | |
lms_color = lms_color * tritanopia; | |
} | |
else if(colorblind_mode == 3.5) { | |
lms_color = lms_color * tritanomaly; | |
} | |
else if(colorblind_mode == 4.0) { | |
lms_color = lms_color * achromatopsia; | |
} | |
else if(colorblind_mode == 4.5) { | |
lms_color = lms_color * achromatomaly; | |
} | |
color.rgb = lms_color.rgb; | |
return color; | |
} | |
} | |
vec4 effect(vec4 colour, sampler2D texture, vec2 uv, vec2 pixel_coords) { | |
return Simulate(texture2D(texture, uv)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment