duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

Daltonize.fx (2556B)


      1 /**
      2  * Daltonization algorithm by daltonize.org
      3  * http://www.daltonize.org/2010/05/lms-daltonization-algorithm.html
      4  * Originally ported to ReShade by IDDQD, modified for ReShade 3.0 by crosire
      5  */
      6 
      7 uniform int Type <
      8 	ui_type = "combo";
      9 	ui_items = "Protanopia\0Deuteranopia\0Tritanopia\0";
     10 > = 0;
     11 
     12 #include "ReShade.fxh"
     13 
     14 float3 PS_DaltonizeFXmain(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
     15 {
     16 	float3 input = tex2D(ReShade::BackBuffer, texcoord).rgb;
     17 
     18 	// RGB to LMS matrix conversion
     19 	float OnizeL = (17.8824f * input.r) + (43.5161f * input.g) + (4.11935f * input.b);
     20 	float OnizeM = (3.45565f * input.r) + (27.1554f * input.g) + (3.86714f * input.b);
     21 	float OnizeS = (0.0299566f * input.r) + (0.184309f * input.g) + (1.46709f * input.b);
     22 	
     23 	// Simulate color blindness
     24 	float Daltl, Daltm, Dalts;
     25 
     26 	if (Type == 0) // Protanopia - reds are greatly reduced (1% men)
     27 	{
     28 		Daltl = 0.0f * OnizeL + 2.02344f * OnizeM + -2.52581f * OnizeS;
     29 		Daltm = 0.0f * OnizeL + 1.0f * OnizeM + 0.0f * OnizeS;
     30 		Dalts = 0.0f * OnizeL + 0.0f * OnizeM + 1.0f * OnizeS;
     31 	}
     32 	else if (Type == 1) // Deuteranopia - greens are greatly reduced (1% men)
     33 	{
     34 		Daltl = 1.0f * OnizeL + 0.0f * OnizeM + 0.0f * OnizeS;
     35 		Daltm = 0.494207f * OnizeL + 0.0f * OnizeM + 1.24827f * OnizeS;
     36 		Dalts = 0.0f * OnizeL + 0.0f * OnizeM + 1.0f * OnizeS;
     37 	}
     38 	else if (Type == 2) // Tritanopia - blues are greatly reduced (0.003% population)
     39 	{
     40 		Daltl = 1.0f * OnizeL + 0.0f * OnizeM + 0.0f * OnizeS;
     41 		Daltm = 0.0f * OnizeL + 1.0f * OnizeM + 0.0f * OnizeS;
     42 		Dalts = -0.395913f * OnizeL + 0.801109f * OnizeM + 0.0f * OnizeS;
     43 	}
     44 	
     45 	// LMS to RGB matrix conversion
     46 	float3 error;
     47 	error.r = (0.0809444479f * Daltl) + (-0.130504409f * Daltm) + (0.116721066f * Dalts);
     48 	error.g = (-0.0102485335f * Daltl) + (0.0540193266f * Daltm) + (-0.113614708f * Dalts);
     49 	error.b = (-0.000365296938f * Daltl) + (-0.00412161469f * Daltm) + (0.693511405f * Dalts);
     50 	
     51 	// Isolate invisible colors to color vision deficiency (calculate error matrix)
     52 	error = (input - error);
     53 	
     54 	// Shift colors towards visible spectrum (apply error modifications)
     55 	float3 correction;
     56 	correction.r = 0; // (error.r * 0.0) + (error.g * 0.0) + (error.b * 0.0);
     57 	correction.g = (error.r * 0.7) + (error.g * 1.0); // + (error.b * 0.0);
     58 	correction.b = (error.r * 0.7) + (error.b * 1.0); // + (error.g * 0.0);
     59 	
     60 	// Add compensation to original values
     61 	correction = input + correction;
     62 	
     63 	return correction;
     64 }
     65 
     66 technique Daltonize
     67 {
     68 	pass
     69 	{
     70 		VertexShader = PostProcessVS;
     71 		PixelShader = PS_DaltonizeFXmain;
     72 	}
     73 }