2D Fragment Shader rendering Blue instead of White
Asked Answered
I

2

0

Hi all,

new to shaders so please take it easy on me!

I am trying to implement filters to simulate colour blindness. It should be a simple linear transformation, but for some reason the shader is out putting blue instead of white.

I've tried a few different things and so far i am quite confused!

`void fragment(){
// start off with white
	vec4 curr_col = vec4(1.0, 1.0, 1.0, 1.0);

//precomputed transformation to simulate red colour blindess
	mat3 vienot_protan_from_lRGB = mat3(vec3( 0.11238, 0.88762, 0.00000),
								vec3(0.11238, 0.88762, -0.00000),
								vec3(0.00401, -0.00401, 1.00000));

//	testing manual matrix multiplication. 
	curr_col = vec4(0.11238 + 0.88762,
					0.11238 + 0.88762,
					0.00401 - 0.00401 + 1.00000,
					1.0);
//  outputs correctly and renders white
//	COLOR = curr_col;

//	my implementation of matrix multiplcation
//	vec3 result = vec3(
//						vienot_protan_from_lRGB[0][0]*COLOR.r +
//						vienot_protan_from_lRGB[1][0]*COLOR.g +
//						vienot_protan_from_lRGB[2][0]*COLOR.b,
//						vienot_protan_from_lRGB[0][1]*COLOR.r +
//						vienot_protan_from_lRGB[1][1]*COLOR.g +
//						vienot_protan_from_lRGB[2][1]*COLOR.b,
//						vienot_protan_from_lRGB[0][2]*COLOR.r +
//						vienot_protan_from_lRGB[1][2]*COLOR.g +
//						vienot_protan_from_lRGB[2][2]*COLOR.b);
//
//	incorrectly outputs blue
//	COLOR = vec4(result, COLOR.a);

// GLSL built in matrix multiplcation
	vec4 result = vec4(vienot_protan_from_lRGB * curr_col.rgb, curr_col.a);
//	incorrectly outputs blue
	COLOR = result;`

current output, should be a white square instead!

Cheers,
DD

Islander answered 16/9, 2022 at 10:54 Comment(0)
B
0

Not sure where you got the code for the matrix from, but there are two formats, row-major and column-major. It's likely the numbers you got are in the reverse. You can either transpose the matrix, or just type the numbers in again correctly (a transpose is flipping everything along the identity diagonal).

Befit answered 16/9, 2022 at 10:58 Comment(0)
I
0

Befit you absolute hero. Thank you!

Islander answered 16/9, 2022 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.