diff --git a/res/shaders/common.hlsl b/res/shaders/common.hlsl index 2bee7ef3..c15b17d8 100644 --- a/res/shaders/common.hlsl +++ b/res/shaders/common.hlsl @@ -1,6 +1,7 @@ #define DECL(t, n) t n : n -#define DECL_PS(n) float4 n : SV_POSITION +#define DESV(t, n, s) t n : s +/* Linear color form sRGB color */ float4 linear_from_srgb(float4 srgb) { return float4(pow(srgb.rgb, 2.2), srgb.a); diff --git a/res/shaders/grid.hlsl b/res/shaders/grid.hlsl index 4b890314..5d1f2319 100644 --- a/res/shaders/grid.hlsl +++ b/res/shaders/grid.hlsl @@ -1,5 +1,10 @@ #include "shaders/common.hlsl" +cbuffer constants : register(b0) +{ + float4x4 G_projection; +}; + struct vs_input { DECL(float4, pos); DECL(float, line_thickness); @@ -13,7 +18,7 @@ struct vs_input { }; struct ps_input { - DECL_PS(screen_pos); + DESV(float4, screen_pos, SV_POSITION); DECL(float, line_thickness); DECL(float, line_spacing); DECL(float2, offset); @@ -24,16 +29,15 @@ struct ps_input { DECL(float4, y_lin); }; -cbuffer vs_constants : register(b0) -{ - float4x4 projection; -}; +/* ========================== * + * Vertex shader + * ========================== */ ps_input vs_main(vs_input input) { ps_input output; - output.screen_pos = mul(projection, float4(input.pos.xy, 0.f, 1.f)); + output.screen_pos = mul(G_projection, float4(input.pos.xy, 0.f, 1.f)); output.line_thickness = input.line_thickness; output.line_spacing = input.line_spacing; output.offset = input.offset; @@ -46,6 +50,10 @@ ps_input vs_main(vs_input input) return output; } +/* ========================== * + * Pixel shader + * ========================== */ + float4 ps_main(ps_input input) : SV_TARGET { float2 grid_pos = input.screen_pos.xy + input.offset; diff --git a/res/shaders/triangle.hlsl b/res/shaders/triangle.hlsl index c0096b73..3c233004 100644 --- a/res/shaders/triangle.hlsl +++ b/res/shaders/triangle.hlsl @@ -1,13 +1,11 @@ #include "shaders/common.hlsl" -struct { - SamplerState sampler0; - Texture2D texture0; -} globals; +SamplerState G_sampler0; +Texture2D G_texture0; cbuffer constants : register(b0) { - float4x4 projection; + float4x4 G_projection; }; struct vs_input { @@ -17,24 +15,32 @@ struct vs_input { }; struct ps_input { - DECL_PS(screen_pos); + DESV(float4, screen_pos, SV_POSITION); DECL(float2, uv); DECL(float4, tint_lin); }; +/* ========================== * + * Vertex shader + * ========================== */ + ps_input vs_main(vs_input input) { ps_input output; - output.screen_pos = mul(projection, float4(input.pos.xy, 0.f, 1.f)); + output.screen_pos = mul(G_projection, float4(input.pos.xy, 0.f, 1.f)); output.uv = input.uv; output.tint_lin = linear_from_srgb(input.tint_srgb); return output; } +/* ========================== * + * Pixel shader + * ========================== */ + float4 ps_main(ps_input input) : SV_TARGET { - float4 color = globals.texture0.Sample(globals.sampler0, input.uv) * input.tint_lin; + float4 color = G_texture0.Sample(G_sampler0, input.uv) * input.tint_lin; return color; } diff --git a/src/gpu_dx11.c b/src/gpu_dx11.c index 41ca891d..f54bdb40 100644 --- a/src/gpu_dx11.c +++ b/src/gpu_dx11.c @@ -776,7 +776,7 @@ INTERNAL void reload_shader(struct dx11_shader *old_shader, struct dx11_shader_d *old_shader = new_shader; } else { error_msg = string_format(scratch.arena, - LIT("Failed to compile shader \"%F\": %F"), + LIT("Failed to compile shader \"%F\":\n%F"), FMT_STR(name), FMT_STR(comp_error)); shader_release(&new_shader);