@@ -150,6 +150,20 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
150150 var pixels = textureSample (t_diffuse , s_diffuse , in . tex_coords );
151151 var viewport_resolution = 1 .0 / vec2 (f32 (feature_uniform . width ), f32 (feature_uniform . height ));
152152
153+ if feature_uniform . gamma != 0u {
154+ // todo! modify the pixels to account for gamma
155+ // see https://www.w3.org/TR/2003/REC-PNG-20031110/#13Decoder-gamma-handling
156+ let gamma_value = f32 (feature_uniform . gamma ) / 100000 .0 ;
157+ let inv_gamma = 1 .0 / gamma_value ;
158+
159+ pixels = vec4 <f32 >(
160+ pow (pixels . r , inv_gamma ),
161+ pow (pixels . g , inv_gamma ),
162+ pow (pixels . b , inv_gamma ),
163+ pixels . a
164+ );
165+ }
166+
153167 if feature_uniform . edge_detect == 1u {
154168 pixels = detect_edge (in . tex_coords , viewport_resolution );
155169 }
@@ -162,11 +176,6 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
162176 pixels = gaussian_blur (in . tex_coords , f32 (feature_uniform . radius ), viewport_resolution );
163177 }
164178
165- if feature_uniform . gamma != 0u {
166- // todo! modify the pixels to account for gamma
167- // see https://www.w3.org/TR/2003/REC-PNG-20031110/#13Decoder-gamma-handling
168- }
169-
170179 if feature_uniform . grayscale == 1u {
171180 var y = (pixels . r * 0 .29891 + pixels . g * 0 .58661 + pixels . b * 0 .11448 );
172181 pixels = vec4 (y , y , y , 1 .0 );
0 commit comments