Color Blind

Based on Physiologically Model for Simulation of Color Vision Deficiency

Science-based shader for color blindness emulation using color matrices (based on data from Machado, Oliveira & Fernandes).  And Brettel & Viénot .

It simulates different types of color blindness depending on the value of  – Type:

  • 0 – Normal Vision
  • 1 – Protanopia
  • 2 – Protonomaly 
  • 3 – Deuteranopia 
  • 4 – Deuteranomaly 
  • 5 – Tritanopie
  • 6 – Tritanomaly
  • 7 – Achromatopsia 
  • 8 – Achromatomaly
Shader code
shader_type canvas_item;
render_mode blend_mix;

uniform int color_deficiency_type : hint_enum(
    "NormalVision", "Protanopia", "Protonomaly",
    "Deuteranopia", "Deuteranomaly", "Tritanopia",
    "Tritanomaly", "Achromatopsia", "Achromatomaly") = 0;

uniform sampler2D screen_texture : hint_screen_texture;

void fragment() {
    vec2 uv = SCREEN_UV;
    vec3 original = texture(screen_texture, uv).rgb;

    // Матрицы для симуляции различных форм цветовой слепоты
    mat3 color_matrices[9] = mat3[](
        mat3( // 0: Normal vision
            vec3(1.0, 0.0, 0.0),
            vec3(0.0, 1.0, 0.0),
            vec3(0.0, 0.0, 1.0)
        ),
        mat3( // 1: Protanopia
            vec3(0.152, 1.053, -0.205),
            vec3(0.115, 0.786, 0.099),
            vec3(-0.004, -0.048, 1.052)
        ),
        mat3( // 2: Protonomaly
            vec3(0.817, 0.333, -0.150),
            vec3(0.333, 0.667,  0.000),
            vec3(-0.017, 0.000, 1.017)
        ),
        mat3( // 3: Deuteranopia
            vec3(0.367, 0.861, -0.228),
            vec3(0.280, 0.673,  0.047),
            vec3(-0.012, 0.043, 0.969)
        ),
        mat3( // 4: Deuteranomaly
            vec3(0.800, 0.200, 0.000),
            vec3(0.258, 0.742, 0.000),
            vec3(0.000, 0.142, 0.858)
        ),
        mat3( // 5: Tritanopia
            vec3(1.256, -0.077, -0.179),
            vec3(-0.078, 0.931, 0.148),
            vec3(0.005, 0.691, 0.304)
        ),
        mat3( // 6: Tritanomaly
            vec3(0.967, 0.033, 0.000),
            vec3(0.000, 0.733, 0.267),
            vec3(0.000, 0.183, 0.817)
        ),
        mat3( // 7: Achromatopsia
            vec3(0.299, 0.299, 0.299),
            vec3(0.587, 0.587, 0.587),
            vec3(0.114, 0.114, 0.114)
        ),
        mat3( // 8: Achromatomaly
            vec3(0.618, 0.320, 0.062),
            vec3(0.163, 0.775, 0.062),
            vec3(0.163, 0.320, 0.516)
        )
    );

    // Применяем нужную матрицу
    mat3 selected_matrix = color_matrices[clamp(color_deficiency_type, 0, 8)];
    COLOR.rgb = selected_matrix * original;
}
Tags
achromatomaly, achromatopsia, badvision, blind, canvas, Color, colorblind, deuteranomaly, deuteranopia, matrix, normalVision, post process, protanopia, protonomaly, shader, tritanomaly, tritanopie, vision
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Riko

UV Spherize

Gerstner Wave

Panoramic Mapping

Related shaders

Color shift Color Reducer post-processing

color splash (show only one color)

Green color replacement shader

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments