mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-03 04:28:12 +00:00
rect shader improvements, moved calculations from pixel to vertex shader
This commit is contained in:
committed by
Ryan Fleury
parent
9a2ae21b89
commit
a77d457f51
@@ -63,18 +63,15 @@ str8_lit_comp(
|
|||||||
"\n"
|
"\n"
|
||||||
"struct Vertex2Pixel\n"
|
"struct Vertex2Pixel\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 position : SV_POSITION;\n"
|
" float4 position : SV_POSITION;\n"
|
||||||
" float2 rect_half_size_px : PSIZE;\n"
|
" nointerpolation float2 rect_half_size_px : PSIZE;\n"
|
||||||
" float2 texcoord_pct : TEX;\n"
|
" float2 texcoord_pct : TEX;\n"
|
||||||
" float2 cornercoord_pct : COLC;\n"
|
" float2 sdf_sample_pos : SDF;\n"
|
||||||
" float4 color00 : COL0;\n"
|
" float4 tint : TINT;\n"
|
||||||
" float4 color01 : COL1;\n"
|
" float corner_radius_px : CRAD;\n"
|
||||||
" float4 color10 : COL2;\n"
|
" nointerpolation float border_thickness_px : BTHC;\n"
|
||||||
" float4 color11 : COL3;\n"
|
" nointerpolation float softness_px : SFT;\n"
|
||||||
" float corner_radius_px : CRAD;\n"
|
" nointerpolation float omit_texture : OTX;\n"
|
||||||
" float border_thickness_px : BTHC;\n"
|
|
||||||
" float softness_px : SFT;\n"
|
|
||||||
" float omit_texture : OTX;\n"
|
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Texture2D main_t2d : register(t0);\n"
|
"Texture2D main_t2d : register(t0);\n"
|
||||||
@@ -105,24 +102,17 @@ str8_lit_comp(
|
|||||||
" //- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)\n"
|
" //- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)\n"
|
||||||
" float2 dst_p_verts_px[] =\n"
|
" float2 dst_p_verts_px[] =\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" mul(xform, float3(dst_p0_px.x, dst_p1_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),\n"
|
" float2(dst_p0_px.x, viewport_size_px.y - dst_p1_px.y),\n"
|
||||||
" mul(xform, float3(dst_p0_px.x, dst_p0_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),\n"
|
" float2(dst_p0_px.x, viewport_size_px.y - dst_p0_px.y),\n"
|
||||||
" mul(xform, float3(dst_p1_px.x, dst_p1_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),\n"
|
" float2(dst_p1_px.x, viewport_size_px.y - dst_p1_px.y),\n"
|
||||||
" mul(xform, float3(dst_p1_px.x, dst_p0_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),\n"
|
" float2(dst_p1_px.x, viewport_size_px.y - dst_p0_px.y),\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
" float2 src_p_verts_pct[] =\n"
|
" float2 src_p_verts_px[] =\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" float2(src_p0_px.x/texture_t2d_size_px.x, src_p1_px.y/texture_t2d_size_px.y),\n"
|
" float2(src_p0_px.x, src_p1_px.y),\n"
|
||||||
" float2(src_p0_px.x/texture_t2d_size_px.x, src_p0_px.y/texture_t2d_size_px.y),\n"
|
" float2(src_p0_px.x, src_p0_px.y),\n"
|
||||||
" float2(src_p1_px.x/texture_t2d_size_px.x, src_p1_px.y/texture_t2d_size_px.y),\n"
|
" float2(src_p1_px.x, src_p1_px.y),\n"
|
||||||
" float2(src_p1_px.x/texture_t2d_size_px.x, src_p0_px.y/texture_t2d_size_px.y),\n"
|
" float2(src_p1_px.x, src_p0_px.y),\n"
|
||||||
" };\n"
|
|
||||||
" float2 dst_c_verts_pct[] =\n"
|
|
||||||
" {\n"
|
|
||||||
" float2(0, 1),\n"
|
|
||||||
" float2(0, 0),\n"
|
|
||||||
" float2(1, 1),\n"
|
|
||||||
" float2(1, 0),\n"
|
|
||||||
" };\n"
|
" };\n"
|
||||||
" float dst_r_verts_px[] =\n"
|
" float dst_r_verts_px[] =\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
@@ -131,21 +121,26 @@ str8_lit_comp(
|
|||||||
" cpu2vertex.corner_radii_px.w,\n"
|
" cpu2vertex.corner_radii_px.w,\n"
|
||||||
" cpu2vertex.corner_radii_px.z,\n"
|
" cpu2vertex.corner_radii_px.z,\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
|
" float4 src_color[] = {\n"
|
||||||
|
" cpu2vertex.color01,\n"
|
||||||
|
" cpu2vertex.color00,\n"
|
||||||
|
" cpu2vertex.color11,\n"
|
||||||
|
" cpu2vertex.color10,\n"
|
||||||
|
" };\n"
|
||||||
|
" float2 dst_verts_pct = float2(\n"
|
||||||
|
" (cpu2vertex.vertex_id >> 1) ? 1.f : 0.f,\n"
|
||||||
|
" (cpu2vertex.vertex_id & 1) ? 0.f : 1.f);\n"
|
||||||
" \n"
|
" \n"
|
||||||
" // rjf: fill vertex -> pixel data\n"
|
" // rjf: fill vertex -> pixel data\n"
|
||||||
" Vertex2Pixel vertex2pixel;\n"
|
" Vertex2Pixel vertex2pixel;\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" vertex2pixel.position.x = 2 * dst_p_verts_px[cpu2vertex.vertex_id].x / viewport_size_px.x - 1.f;\n"
|
" vertex2pixel.position.xy = 2.f * mul(xform, float3(dst_p_verts_px[cpu2vertex.vertex_id], 1.f)).xy / viewport_size_px - 1.f;\n"
|
||||||
" vertex2pixel.position.y = 2 * dst_p_verts_px[cpu2vertex.vertex_id].y / viewport_size_px.y - 1.f;\n"
|
|
||||||
" vertex2pixel.position.z = 0.f;\n"
|
" vertex2pixel.position.z = 0.f;\n"
|
||||||
" vertex2pixel.position.w = 1.f;\n"
|
" vertex2pixel.position.w = 1.f;\n"
|
||||||
" vertex2pixel.rect_half_size_px = dst_size_px/2 * xform_scale;\n"
|
" vertex2pixel.rect_half_size_px = dst_size_px / 2.f * xform_scale;\n"
|
||||||
" vertex2pixel.texcoord_pct = src_p_verts_pct[cpu2vertex.vertex_id];\n"
|
" vertex2pixel.texcoord_pct = src_p_verts_px[cpu2vertex.vertex_id] / texture_t2d_size_px;\n"
|
||||||
" vertex2pixel.cornercoord_pct = dst_c_verts_pct[cpu2vertex.vertex_id];\n"
|
" vertex2pixel.sdf_sample_pos = (2.f * dst_verts_pct - 1.f) * vertex2pixel.rect_half_size_px;\n"
|
||||||
" vertex2pixel.color00 = cpu2vertex.color00;\n"
|
" vertex2pixel.tint = src_color[cpu2vertex.vertex_id];\n"
|
||||||
" vertex2pixel.color01 = cpu2vertex.color01;\n"
|
|
||||||
" vertex2pixel.color10 = cpu2vertex.color10;\n"
|
|
||||||
" vertex2pixel.color11 = cpu2vertex.color11;\n"
|
|
||||||
" vertex2pixel.corner_radius_px = dst_r_verts_px[cpu2vertex.vertex_id];\n"
|
" vertex2pixel.corner_radius_px = dst_r_verts_px[cpu2vertex.vertex_id];\n"
|
||||||
" vertex2pixel.border_thickness_px = border_thickness_px;\n"
|
" vertex2pixel.border_thickness_px = border_thickness_px;\n"
|
||||||
" vertex2pixel.softness_px = softness_px;\n"
|
" vertex2pixel.softness_px = softness_px;\n"
|
||||||
@@ -160,9 +155,7 @@ str8_lit_comp(
|
|||||||
"ps_main(Vertex2Pixel vertex2pixel) : SV_TARGET\n"
|
"ps_main(Vertex2Pixel vertex2pixel) : SV_TARGET\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" // rjf: blend corner colors to produce final tint\n"
|
" // rjf: blend corner colors to produce final tint\n"
|
||||||
" float4 top_color = (1-vertex2pixel.cornercoord_pct.x)*vertex2pixel.color00 + (vertex2pixel.cornercoord_pct.x)*vertex2pixel.color10;\n"
|
" float4 tint = vertex2pixel.tint;\n"
|
||||||
" float4 bot_color = (1-vertex2pixel.cornercoord_pct.x)*vertex2pixel.color01 + (vertex2pixel.cornercoord_pct.x)*vertex2pixel.color11;\n"
|
|
||||||
" float4 tint = (1-vertex2pixel.cornercoord_pct.y)*top_color + (vertex2pixel.cornercoord_pct.y)*bot_color;\n"
|
|
||||||
" \n"
|
" \n"
|
||||||
" // rjf: sample texture\n"
|
" // rjf: sample texture\n"
|
||||||
" float4 albedo_sample = float4(1, 1, 1, 1);\n"
|
" float4 albedo_sample = float4(1, 1, 1, 1);\n"
|
||||||
@@ -172,8 +165,7 @@ str8_lit_comp(
|
|||||||
" }\n"
|
" }\n"
|
||||||
" \n"
|
" \n"
|
||||||
" // rjf: determine SDF sample position\n"
|
" // rjf: determine SDF sample position\n"
|
||||||
" float2 sdf_sample_pos = float2((2*vertex2pixel.cornercoord_pct.x-1)*vertex2pixel.rect_half_size_px.x,\n"
|
" float2 sdf_sample_pos = vertex2pixel.sdf_sample_pos;\n"
|
||||||
" (2*vertex2pixel.cornercoord_pct.y-1)*vertex2pixel.rect_half_size_px.y);\n"
|
|
||||||
" \n"
|
" \n"
|
||||||
" // rjf: sample for corners\n"
|
" // rjf: sample for corners\n"
|
||||||
" float corner_sdf_s = rect_sdf(sdf_sample_pos,\n"
|
" float corner_sdf_s = rect_sdf(sdf_sample_pos,\n"
|
||||||
|
|||||||
@@ -62,18 +62,15 @@ struct CPU2Vertex
|
|||||||
|
|
||||||
struct Vertex2Pixel
|
struct Vertex2Pixel
|
||||||
{
|
{
|
||||||
float4 position : SV_POSITION;
|
float4 position : SV_POSITION;
|
||||||
float2 rect_half_size_px : PSIZE;
|
nointerpolation float2 rect_half_size_px : PSIZE;
|
||||||
float2 texcoord_pct : TEX;
|
float2 texcoord_pct : TEX;
|
||||||
float2 cornercoord_pct : COLC;
|
float2 sdf_sample_pos : SDF;
|
||||||
float4 color00 : COL0;
|
float4 tint : TINT;
|
||||||
float4 color01 : COL1;
|
float corner_radius_px : CRAD;
|
||||||
float4 color10 : COL2;
|
nointerpolation float border_thickness_px : BTHC;
|
||||||
float4 color11 : COL3;
|
nointerpolation float softness_px : SFT;
|
||||||
float corner_radius_px : CRAD;
|
nointerpolation float omit_texture : OTX;
|
||||||
float border_thickness_px : BTHC;
|
|
||||||
float softness_px : SFT;
|
|
||||||
float omit_texture : OTX;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture2D main_t2d : register(t0);
|
Texture2D main_t2d : register(t0);
|
||||||
@@ -104,24 +101,17 @@ vs_main(CPU2Vertex cpu2vertex)
|
|||||||
//- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)
|
//- rjf: prep per-vertex arrays to sample from (p: position, t: texcoord, c: colorcoord, r: cornerradius)
|
||||||
float2 dst_p_verts_px[] =
|
float2 dst_p_verts_px[] =
|
||||||
{
|
{
|
||||||
mul(xform, float3(dst_p0_px.x, dst_p1_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),
|
float2(dst_p0_px.x, viewport_size_px.y - dst_p1_px.y),
|
||||||
mul(xform, float3(dst_p0_px.x, dst_p0_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),
|
float2(dst_p0_px.x, viewport_size_px.y - dst_p0_px.y),
|
||||||
mul(xform, float3(dst_p1_px.x, dst_p1_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),
|
float2(dst_p1_px.x, viewport_size_px.y - dst_p1_px.y),
|
||||||
mul(xform, float3(dst_p1_px.x, dst_p0_px.y, 1)).xy * float2(1, -1) + float2(0, viewport_size_px.y),
|
float2(dst_p1_px.x, viewport_size_px.y - dst_p0_px.y),
|
||||||
};
|
};
|
||||||
float2 src_p_verts_pct[] =
|
float2 src_p_verts_px[] =
|
||||||
{
|
{
|
||||||
float2(src_p0_px.x/texture_t2d_size_px.x, src_p1_px.y/texture_t2d_size_px.y),
|
float2(src_p0_px.x, src_p1_px.y),
|
||||||
float2(src_p0_px.x/texture_t2d_size_px.x, src_p0_px.y/texture_t2d_size_px.y),
|
float2(src_p0_px.x, src_p0_px.y),
|
||||||
float2(src_p1_px.x/texture_t2d_size_px.x, src_p1_px.y/texture_t2d_size_px.y),
|
float2(src_p1_px.x, src_p1_px.y),
|
||||||
float2(src_p1_px.x/texture_t2d_size_px.x, src_p0_px.y/texture_t2d_size_px.y),
|
float2(src_p1_px.x, src_p0_px.y),
|
||||||
};
|
|
||||||
float2 dst_c_verts_pct[] =
|
|
||||||
{
|
|
||||||
float2(0, 1),
|
|
||||||
float2(0, 0),
|
|
||||||
float2(1, 1),
|
|
||||||
float2(1, 0),
|
|
||||||
};
|
};
|
||||||
float dst_r_verts_px[] =
|
float dst_r_verts_px[] =
|
||||||
{
|
{
|
||||||
@@ -130,21 +120,26 @@ vs_main(CPU2Vertex cpu2vertex)
|
|||||||
cpu2vertex.corner_radii_px.w,
|
cpu2vertex.corner_radii_px.w,
|
||||||
cpu2vertex.corner_radii_px.z,
|
cpu2vertex.corner_radii_px.z,
|
||||||
};
|
};
|
||||||
|
float4 src_color[] = {
|
||||||
|
cpu2vertex.color01,
|
||||||
|
cpu2vertex.color00,
|
||||||
|
cpu2vertex.color11,
|
||||||
|
cpu2vertex.color10,
|
||||||
|
};
|
||||||
|
float2 dst_verts_pct = float2(
|
||||||
|
(cpu2vertex.vertex_id >> 1) ? 1.f : 0.f,
|
||||||
|
(cpu2vertex.vertex_id & 1) ? 0.f : 1.f);
|
||||||
|
|
||||||
// rjf: fill vertex -> pixel data
|
// rjf: fill vertex -> pixel data
|
||||||
Vertex2Pixel vertex2pixel;
|
Vertex2Pixel vertex2pixel;
|
||||||
{
|
{
|
||||||
vertex2pixel.position.x = 2 * dst_p_verts_px[cpu2vertex.vertex_id].x / viewport_size_px.x - 1.f;
|
vertex2pixel.position.xy = 2.f * mul(xform, float3(dst_p_verts_px[cpu2vertex.vertex_id], 1.f)).xy / viewport_size_px - 1.f;
|
||||||
vertex2pixel.position.y = 2 * dst_p_verts_px[cpu2vertex.vertex_id].y / viewport_size_px.y - 1.f;
|
|
||||||
vertex2pixel.position.z = 0.f;
|
vertex2pixel.position.z = 0.f;
|
||||||
vertex2pixel.position.w = 1.f;
|
vertex2pixel.position.w = 1.f;
|
||||||
vertex2pixel.rect_half_size_px = dst_size_px/2 * xform_scale;
|
vertex2pixel.rect_half_size_px = dst_size_px / 2.f * xform_scale;
|
||||||
vertex2pixel.texcoord_pct = src_p_verts_pct[cpu2vertex.vertex_id];
|
vertex2pixel.texcoord_pct = src_p_verts_px[cpu2vertex.vertex_id] / texture_t2d_size_px;
|
||||||
vertex2pixel.cornercoord_pct = dst_c_verts_pct[cpu2vertex.vertex_id];
|
vertex2pixel.sdf_sample_pos = (2.f * dst_verts_pct - 1.f) * vertex2pixel.rect_half_size_px;
|
||||||
vertex2pixel.color00 = cpu2vertex.color00;
|
vertex2pixel.tint = src_color[cpu2vertex.vertex_id];
|
||||||
vertex2pixel.color01 = cpu2vertex.color01;
|
|
||||||
vertex2pixel.color10 = cpu2vertex.color10;
|
|
||||||
vertex2pixel.color11 = cpu2vertex.color11;
|
|
||||||
vertex2pixel.corner_radius_px = dst_r_verts_px[cpu2vertex.vertex_id];
|
vertex2pixel.corner_radius_px = dst_r_verts_px[cpu2vertex.vertex_id];
|
||||||
vertex2pixel.border_thickness_px = border_thickness_px;
|
vertex2pixel.border_thickness_px = border_thickness_px;
|
||||||
vertex2pixel.softness_px = softness_px;
|
vertex2pixel.softness_px = softness_px;
|
||||||
@@ -159,9 +154,7 @@ float4
|
|||||||
ps_main(Vertex2Pixel vertex2pixel) : SV_TARGET
|
ps_main(Vertex2Pixel vertex2pixel) : SV_TARGET
|
||||||
{
|
{
|
||||||
// rjf: blend corner colors to produce final tint
|
// rjf: blend corner colors to produce final tint
|
||||||
float4 top_color = (1-vertex2pixel.cornercoord_pct.x)*vertex2pixel.color00 + (vertex2pixel.cornercoord_pct.x)*vertex2pixel.color10;
|
float4 tint = vertex2pixel.tint;
|
||||||
float4 bot_color = (1-vertex2pixel.cornercoord_pct.x)*vertex2pixel.color01 + (vertex2pixel.cornercoord_pct.x)*vertex2pixel.color11;
|
|
||||||
float4 tint = (1-vertex2pixel.cornercoord_pct.y)*top_color + (vertex2pixel.cornercoord_pct.y)*bot_color;
|
|
||||||
|
|
||||||
// rjf: sample texture
|
// rjf: sample texture
|
||||||
float4 albedo_sample = float4(1, 1, 1, 1);
|
float4 albedo_sample = float4(1, 1, 1, 1);
|
||||||
@@ -171,8 +164,7 @@ ps_main(Vertex2Pixel vertex2pixel) : SV_TARGET
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rjf: determine SDF sample position
|
// rjf: determine SDF sample position
|
||||||
float2 sdf_sample_pos = float2((2*vertex2pixel.cornercoord_pct.x-1)*vertex2pixel.rect_half_size_px.x,
|
float2 sdf_sample_pos = vertex2pixel.sdf_sample_pos;
|
||||||
(2*vertex2pixel.cornercoord_pct.y-1)*vertex2pixel.rect_half_size_px.y);
|
|
||||||
|
|
||||||
// rjf: sample for corners
|
// rjf: sample for corners
|
||||||
float corner_sdf_s = rect_sdf(sdf_sample_pos,
|
float corner_sdf_s = rect_sdf(sdf_sample_pos,
|
||||||
|
|||||||
Reference in New Issue
Block a user