forked from Dynamitos/Seele
Delete invasive font atlas tests
This commit is contained in:
1 parent
22a90fe07c
commit
1bc73b6d2f
9 files changed
+37
-263
No files matched your search
+31
-22
@@ -1,5 +1,12 @@
|
||||
import Common;
|
||||
|
||||
// Per-quad render data, read from the EXISTING pParams.elements storage buffer (bound on the
|
||||
// CPU side by UIPass as SE_DESCRIPTOR_TYPE_STORAGE_BUFFER). We read it here as a plain SSBO so
|
||||
// every value (x/y/w/h, color, opacity, uvOffset/uvSize, textureIndex) is EXACT — not barycentric
|
||||
// interpolated the way the old code passed it as a STYLE vertex attribute (which corrupted the
|
||||
// transparency and shifted glyphs). The C++ RenderElementStyle layout (glm: vec3=12B, vec2=8B)
|
||||
// is byte-identical to this slang struct (float3=12B, float2=8B); Slang's default SSBO packing
|
||||
// (offsets 0,4,8,12,16,28,32,36,40,48,52) matches it 1:1.
|
||||
struct RenderElementStyle
|
||||
{
|
||||
float x;
|
||||
@@ -10,30 +17,33 @@ struct RenderElementStyle
|
||||
float opacity;
|
||||
float z;
|
||||
uint textureIndex;
|
||||
// UV rect for textured quads (glyphs: their rect in the font atlas)
|
||||
float2 uvOffset;
|
||||
float2 uvSize;
|
||||
float2 pad;
|
||||
};
|
||||
|
||||
struct UIParameter
|
||||
{
|
||||
StructuredBuffer<RenderElementStyle> elements;
|
||||
SamplerState sampler;
|
||||
Texture2D textures[];
|
||||
StructuredBuffer<RenderElementStyle> elements;
|
||||
Texture2D textures[]; // must be last (unsized)
|
||||
};
|
||||
|
||||
ParameterBlock<UIParameter> pParams;
|
||||
|
||||
// Varyings carry only per-fragment continuous data (the corner uv in quad-local space) + the
|
||||
// per-quad instance id (uint, not interpolated — exact per fragment). Position is SV_Position.
|
||||
// Everything else comes from the non-interpolated pParams SSBO.
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float2 texCoords : TEXCOORD;
|
||||
RenderElementStyle style : STYLE;
|
||||
uint instanceId : INSTANCENUM;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput vertexMain(uint vertexId : SV_VertexID, uint instanceId: SV_InstanceID)
|
||||
VertexOutput vertexMain(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
|
||||
{
|
||||
// Read the per-quad rect from the non-interpolated SSBO (exact values).
|
||||
RenderElementStyle style = pParams.elements[instanceId];
|
||||
float xMin = style.x;
|
||||
float xMax = xMin + style.w;
|
||||
@@ -46,38 +56,37 @@ VertexOutput vertexMain(uint vertexId : SV_VertexID, uint instanceId: SV_Instanc
|
||||
float4(xMax, yMax, 1, 1)
|
||||
};
|
||||
VertexOutput output;
|
||||
// The UI is a 2D overlay in *screen* pixel space (top-left origin, y down).
|
||||
// The 3D scene camera's projectionMatrix is meaningless for these coordinates,
|
||||
// so build a 2D ortho screen->NDC projection from the viewport size instead:
|
||||
// 2D ortho screen->NDC (screen is top-left / y-down; NDC is bottom-left / y-up):
|
||||
// ndcX = (x / W) * 2 - 1
|
||||
// ndcY = 1 - (y / H) * 2 (flip y: screen is top-down, NDC is bottom-up)
|
||||
// The UI must NOT be transformed by pViewParams.projectionMatrix (the 3D camera).
|
||||
// ndcY = 1 - (y / H) * 2
|
||||
float2 ndc = float2(
|
||||
coordinates[vertexId].x * pViewParams.invScreenDimensions.x * 2.0 - 1.0,
|
||||
1.0 - coordinates[vertexId].y * pViewParams.invScreenDimensions.y * 2.0
|
||||
);
|
||||
output.position = float4(ndc, style.z, 1.0);
|
||||
output.texCoords = coordinates[vertexId].zw;
|
||||
output.style = style;
|
||||
output.texCoords = coordinates[vertexId].zw; // quad-local uv, interpolated per-fragment
|
||||
output.instanceId = instanceId; // uint varying: exact per-fragment (not interpolated)
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(
|
||||
float2 texCoords : TEXCOORD,
|
||||
RenderElementStyle style : STYLE
|
||||
uint instanceId : INSTANCENUM
|
||||
) : SV_Target
|
||||
{
|
||||
if(style.textureIndex == -1) {
|
||||
// Re-read the per-quad data from the non-interpolated SSBO: exact uvOffset/uvSize, exact
|
||||
// color, exact opacity. (Interpolating these as vertex attributes corrupted transparency
|
||||
// and shifted the sampling — the bug the old STYLE-attribute code had.)
|
||||
RenderElementStyle style = pParams.elements[instanceId];
|
||||
if(style.textureIndex == 4294967295u) {
|
||||
// untextured quad (solid background)
|
||||
return float4(style.color, style.opacity);
|
||||
}
|
||||
// Glyph quads: the texture is the font's per-size atlas (R8_UNORM, coverage in the R
|
||||
// channel, A baked to 1.0). Reading it as a Texture2D gives (R=coverage, G=0, B=0, A=1)
|
||||
// — so the alpha we want is in .r, NOT .a (using .a would make every pixel opaque).
|
||||
// Output the pure text color + coverage as alpha; the pipeline's SRC_ALPHA blend then
|
||||
// applies the coverage exactly once (do NOT premultiply here or it'd be squared).
|
||||
// The UV rect (style.uvOffset/uvSize) selects the glyph inside the atlas; plain
|
||||
// textured UI quads use the full-rect default (0,0,1,1).
|
||||
// Textured quad (glyph): the texture is the font atlas (R8_UNORM, coverage in R, A baked
|
||||
// to 1.0). Sampled as float4 that gives (R=coverage, G=0, B=0, A=1) — the alpha we want is
|
||||
// .r, not .a. Output pure text color + coverage as alpha; the pipeline's SRC_ALPHA blend
|
||||
// applies the coverage exactly once (do NOT premultiply or it'd be squared).
|
||||
float2 uv = style.uvOffset + texCoords * style.uvSize;
|
||||
float4 tex = pParams.textures[style.textureIndex].Sample(pParams.sampler, uv);
|
||||
float coverage = tex.r;
|
||||
|
||||
Reference in new issue
Block a user