shader global naming
This commit is contained in:
parent
3d48c0c3de
commit
721151f04a
@ -1,6 +1,7 @@
|
|||||||
#define DECL(t, n) t n : n
|
#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)
|
float4 linear_from_srgb(float4 srgb)
|
||||||
{
|
{
|
||||||
return float4(pow(srgb.rgb, 2.2), srgb.a);
|
return float4(pow(srgb.rgb, 2.2), srgb.a);
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
#include "shaders/common.hlsl"
|
#include "shaders/common.hlsl"
|
||||||
|
|
||||||
|
cbuffer constants : register(b0)
|
||||||
|
{
|
||||||
|
float4x4 G_projection;
|
||||||
|
};
|
||||||
|
|
||||||
struct vs_input {
|
struct vs_input {
|
||||||
DECL(float4, pos);
|
DECL(float4, pos);
|
||||||
DECL(float, line_thickness);
|
DECL(float, line_thickness);
|
||||||
@ -13,7 +18,7 @@ struct vs_input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ps_input {
|
struct ps_input {
|
||||||
DECL_PS(screen_pos);
|
DESV(float4, screen_pos, SV_POSITION);
|
||||||
DECL(float, line_thickness);
|
DECL(float, line_thickness);
|
||||||
DECL(float, line_spacing);
|
DECL(float, line_spacing);
|
||||||
DECL(float2, offset);
|
DECL(float2, offset);
|
||||||
@ -24,16 +29,15 @@ struct ps_input {
|
|||||||
DECL(float4, y_lin);
|
DECL(float4, y_lin);
|
||||||
};
|
};
|
||||||
|
|
||||||
cbuffer vs_constants : register(b0)
|
/* ========================== *
|
||||||
{
|
* Vertex shader
|
||||||
float4x4 projection;
|
* ========================== */
|
||||||
};
|
|
||||||
|
|
||||||
ps_input vs_main(vs_input input)
|
ps_input vs_main(vs_input input)
|
||||||
{
|
{
|
||||||
ps_input output;
|
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_thickness = input.line_thickness;
|
||||||
output.line_spacing = input.line_spacing;
|
output.line_spacing = input.line_spacing;
|
||||||
output.offset = input.offset;
|
output.offset = input.offset;
|
||||||
@ -46,6 +50,10 @@ ps_input vs_main(vs_input input)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Pixel shader
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
float4 ps_main(ps_input input) : SV_TARGET
|
float4 ps_main(ps_input input) : SV_TARGET
|
||||||
{
|
{
|
||||||
float2 grid_pos = input.screen_pos.xy + input.offset;
|
float2 grid_pos = input.screen_pos.xy + input.offset;
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
#include "shaders/common.hlsl"
|
#include "shaders/common.hlsl"
|
||||||
|
|
||||||
struct {
|
SamplerState G_sampler0;
|
||||||
SamplerState sampler0;
|
Texture2D G_texture0;
|
||||||
Texture2D texture0;
|
|
||||||
} globals;
|
|
||||||
|
|
||||||
cbuffer constants : register(b0)
|
cbuffer constants : register(b0)
|
||||||
{
|
{
|
||||||
float4x4 projection;
|
float4x4 G_projection;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vs_input {
|
struct vs_input {
|
||||||
@ -17,24 +15,32 @@ struct vs_input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ps_input {
|
struct ps_input {
|
||||||
DECL_PS(screen_pos);
|
DESV(float4, screen_pos, SV_POSITION);
|
||||||
DECL(float2, uv);
|
DECL(float2, uv);
|
||||||
DECL(float4, tint_lin);
|
DECL(float4, tint_lin);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Vertex shader
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
ps_input vs_main(vs_input input)
|
ps_input vs_main(vs_input input)
|
||||||
{
|
{
|
||||||
ps_input output;
|
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.uv = input.uv;
|
||||||
output.tint_lin = linear_from_srgb(input.tint_srgb);
|
output.tint_lin = linear_from_srgb(input.tint_srgb);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Pixel shader
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
float4 ps_main(ps_input input) : SV_TARGET
|
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;
|
return color;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -776,7 +776,7 @@ INTERNAL void reload_shader(struct dx11_shader *old_shader, struct dx11_shader_d
|
|||||||
*old_shader = new_shader;
|
*old_shader = new_shader;
|
||||||
} else {
|
} else {
|
||||||
error_msg = string_format(scratch.arena,
|
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(name),
|
||||||
FMT_STR(comp_error));
|
FMT_STR(comp_error));
|
||||||
shader_release(&new_shader);
|
shader_release(&new_shader);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user