shader global naming

This commit is contained in:
jacob 2025-05-25 23:17:34 -05:00
parent 3d48c0c3de
commit 721151f04a
4 changed files with 31 additions and 16 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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);