| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- uniform float4x4 ViewProj;
- uniform texture_rect image;
- sampler_state def_sampler {
- Filter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- struct VertInOut {
- float4 pos : POSITION;
- float2 uv : TEXCOORD0;
- };
- VertInOut VSDefault(VertInOut vert_in)
- {
- VertInOut vert_out;
- vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
- vert_out.uv = vert_in.uv;
- return vert_out;
- }
- float4 PSDrawBare(VertInOut vert_in) : TARGET
- {
- return image.Sample(def_sampler, vert_in.uv);
- }
- float4 PSDrawOpaque(VertInOut vert_in) : TARGET
- {
- return float4(image.Sample(def_sampler, vert_in.uv).rgb, 1.0);
- }
- float srgb_nonlinear_to_linear_channel(float u)
- {
- return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
- }
- float3 srgb_nonlinear_to_linear(float3 v)
- {
- return float3(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b));
- }
- float4 PSDrawSrgbDecompress(VertInOut vert_in) : TARGET
- {
- float4 rgba = image.Sample(def_sampler, vert_in.uv);
- rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
- return rgba;
- }
- float4 PSDrawSrgbDecompressPremultiplied(VertInOut vert_in) : TARGET
- {
- float4 rgba = image.Sample(def_sampler, vert_in.uv);
- rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
- rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
- return rgba;
- }
- technique Draw
- {
- pass
- {
- vertex_shader = VSDefault(vert_in);
- pixel_shader = PSDrawBare(vert_in);
- }
- }
- technique DrawOpaque
- {
- pass
- {
- vertex_shader = VSDefault(vert_in);
- pixel_shader = PSDrawOpaque(vert_in);
- }
- }
- technique DrawSrgbDecompress
- {
- pass
- {
- vertex_shader = VSDefault(vert_in);
- pixel_shader = PSDrawSrgbDecompress(vert_in);
- }
- }
- technique DrawSrgbDecompressPremultiplied
- {
- pass
- {
- vertex_shader = VSDefault(vert_in);
- pixel_shader = PSDrawSrgbDecompressPremultiplied(vert_in);
- }
- }
|