@@ -4,7 +4,7 @@ struct VertexInput {
44 @location (1 ) dim : u32 ,
55 @location (2 ) uv : u32 ,
66 @location (3 ) color : u32 ,
7- @location (4 ) content_type : u32 ,
7+ @location (4 ) content_type_with_srgb : u32 ,
88 @location (5 ) depth : f32 ,
99}
1010
@@ -32,8 +32,7 @@ var mask_atlas_texture: texture_2d<f32>;
3232@group (0 ) @binding (3 )
3333var atlas_sampler : sampler ;
3434
35- fn srgb_to_linear (srgb : u32 ) -> f32 {
36- let c = f32 (srgb ) / 255 .0 ;
35+ fn srgb_to_linear (c : f32 ) -> f32 {
3736 if c <= 0 .04045 {
3837 return c / 12 .92 ;
3938 } else {
@@ -78,15 +77,31 @@ fn vs_main(in_vert: VertexInput) -> VertexOutput {
7877
7978 vert_output . position . y *= - 1 .0 ;
8079
81- vert_output . color = vec4 <f32 >(
82- srgb_to_linear ((color & 0x00ff0000u ) >> 16u ),
83- srgb_to_linear ((color & 0x0000ff00u ) >> 8u ),
84- srgb_to_linear (color & 0x000000ffu ),
85- f32 ((color & 0xff000000u ) >> 24u ) / 255 .0 ,
86- );
80+ let content_type = in_vert . content_type_with_srgb & 0xffffu ;
81+ let srgb = (in_vert . content_type_with_srgb & 0xffff0000u ) >> 16u ;
82+
83+ switch srgb {
84+ case 0u : {
85+ vert_output . color = vec4 <f32 >(
86+ f32 ((color & 0x00ff0000u ) >> 16u ) / 255 .0 ,
87+ f32 ((color & 0x0000ff00u ) >> 8u ) / 255 .0 ,
88+ f32 (color & 0x000000ffu ) / 255 .0 ,
89+ f32 ((color & 0xff000000u ) >> 24u ) / 255 .0 ,
90+ );
91+ }
92+ case 1u : {
93+ vert_output . color = vec4 <f32 >(
94+ srgb_to_linear (f32 ((color & 0x00ff0000u ) >> 16u ) / 255 .0 ),
95+ srgb_to_linear (f32 ((color & 0x0000ff00u ) >> 8u ) / 255 .0 ),
96+ srgb_to_linear (f32 (color & 0x000000ffu ) / 255 .0 ),
97+ f32 ((color & 0xff000000u ) >> 24u ) / 255 .0 ,
98+ );
99+ }
100+ default : {}
101+ }
87102
88103 var dim : vec2 <u32 > = vec2 (0u );
89- switch in_vert . content_type {
104+ switch content_type {
90105 case 0u : {
91106 dim = textureDimensions (color_atlas_texture );
92107 break ;
@@ -98,7 +113,7 @@ fn vs_main(in_vert: VertexInput) -> VertexOutput {
98113 default : {}
99114 }
100115
101- vert_output . content_type = in_vert . content_type ;
116+ vert_output . content_type = content_type ;
102117
103118 vert_output . uv = vec2 <f32 >(uv ) / vec2 <f32 >(dim );
104119
0 commit comments