135 lines
3.8 KiB
Plaintext
135 lines
3.8 KiB
Plaintext
////////////////////////////////////////////////////////////
|
|
//~ Backdrop shader
|
|
|
|
ComputeShader2D(V_BackdropCS, 8, 8)
|
|
{
|
|
V_DParams params = G_Dereference<V_DParams>(V_ShaderConst_Params)[0];
|
|
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
|
|
|
|
Vec2U32 target_pos = SV_DispatchThreadID;
|
|
Vec2I32 target_size = params.target_size;
|
|
if (target_pos.x < target_size.x && target_pos.y < target_size.y)
|
|
{
|
|
Vec4 result = 0;
|
|
|
|
/* Checkered square color */
|
|
{
|
|
i32 color_idx = 0;
|
|
Vec4 colors[2] = {
|
|
params.background_color_a,
|
|
params.background_color_b
|
|
};
|
|
Vec2 world_pos = mul(params.draw_to_world_xf, Vec3(target_pos, 1));
|
|
Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(2, 2));
|
|
if (world_pos_modded.x < 1)
|
|
{
|
|
color_idx = !color_idx;
|
|
}
|
|
if (world_pos_modded.y < 1)
|
|
{
|
|
color_idx = !color_idx;
|
|
}
|
|
if (world_pos.x < 0)
|
|
{
|
|
color_idx = !color_idx;
|
|
}
|
|
if (world_pos.y < 0)
|
|
{
|
|
color_idx = !color_idx;
|
|
}
|
|
result = colors[color_idx];
|
|
}
|
|
|
|
/* Axis color */
|
|
{
|
|
f32 half_thickness = 1;
|
|
Vec2 zero_screen = mul(params.world_to_draw_xf, Vec3(0, 0, 1));
|
|
f32 x_dist = abs(target_pos.x - zero_screen.x);
|
|
f32 y_dist = abs(target_pos.y - zero_screen.y);
|
|
if (y_dist <= half_thickness)
|
|
{
|
|
result = Color_Red;
|
|
}
|
|
else if (x_dist <= half_thickness)
|
|
{
|
|
result = Color_Green;
|
|
}
|
|
}
|
|
|
|
target[target_pos] = result;
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Quad shader
|
|
|
|
//////////////////////////////
|
|
//- Vertex shader
|
|
|
|
VertexShader(V_DQuadVS, V_DQuadPSInput)
|
|
{
|
|
V_DParams params = G_Dereference<V_DParams>(V_ShaderConst_Params)[0];
|
|
StructuredBuffer<V_DQuad> quads = G_Dereference<V_DQuad>(params.quads);
|
|
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
|
|
|
|
V_DQuad quad = quads[SV_InstanceID];
|
|
|
|
Vec2 rect_uv = RectUvFromVertexId(SV_VertexID);
|
|
// Vec2 tex_uv = lerp(quad.tex_uv0, quad.tex_uv1, rect_uv);
|
|
// Vec2 target_pos = lerp(quad.p0, quad.p1, rect_uv);
|
|
Vec2 target_pos = 0;
|
|
|
|
V_DQuadPSInput result;
|
|
result.sv_position = Vec4(NdcFromPos(target_pos, countof(target)).xy, 0, 1);
|
|
result.quad_idx = SV_InstanceID;
|
|
return result;
|
|
}
|
|
|
|
//////////////////////////////
|
|
//- Pixel shader
|
|
|
|
PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input)
|
|
{
|
|
V_DParams params = G_Dereference<V_DParams>(V_ShaderConst_Params)[0];
|
|
StructuredBuffer<V_DQuad> quads = G_Dereference<V_DQuad>(params.quads);
|
|
V_DQuad quad = quads[input.quad_idx];
|
|
|
|
Vec4 final_color = 0;
|
|
|
|
V_DQuadPSOutput output;
|
|
output.sv_target0 = final_color;
|
|
return output;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Shape shader
|
|
|
|
//////////////////////////////
|
|
//- Vertex shader
|
|
|
|
VertexShader(V_DVertVS, V_DVertPSInput)
|
|
{
|
|
V_DParams params = G_Dereference<V_DParams>(V_ShaderConst_Params)[0];
|
|
StructuredBuffer<V_DVert> verts = G_Dereference<V_DVert>(params.shape_verts);
|
|
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
|
|
|
|
V_DVert vert = verts[SV_VertexID];
|
|
|
|
Vec2 target_pos = vert.pos;
|
|
|
|
V_DVertPSInput result;
|
|
result.sv_position = Vec4(NdcFromPos(target_pos, countof(target)).xy, 0, 1);
|
|
result.color_lin = vert.color_lin;
|
|
return result;
|
|
}
|
|
|
|
//////////////////////////////
|
|
//- Pixel shader
|
|
|
|
PixelShader(V_DVertPS, V_DVertPSOutput, V_DVertPSInput input)
|
|
{
|
|
V_DVertPSOutput output;
|
|
output.sv_target0 = input.color_lin;
|
|
return output;
|
|
}
|