Basic crashing text rendering
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
|
||||
struct GlyphData
|
||||
{
|
||||
float2 bearing;
|
||||
float2 size;
|
||||
};
|
||||
struct ViewData
|
||||
{
|
||||
float4x4 projectionMatrix;
|
||||
}
|
||||
layout(set = 0, binding = 0)
|
||||
ConstantBuffer<ViewData> viewData;
|
||||
layout(set = 0, binding = 1)
|
||||
SamplerState glyphSampler;
|
||||
layout(set = 0, binding = 2)
|
||||
StructuredBuffer<GlyphData> glyphData;
|
||||
layout(set = 1)
|
||||
Texture2D glyphTextures[];
|
||||
layout(push_constant)
|
||||
float scale;
|
||||
|
||||
struct VertexStageInput
|
||||
{
|
||||
uint glyphIndex;
|
||||
float2 position;
|
||||
uint vertexId : SV_VertexID;
|
||||
};
|
||||
|
||||
struct VertexStageOutput
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float2 uvCoords : TEXCOORD;
|
||||
uint glyphIndex : GLYPHINDEX;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexStageOutput vertexMain(VertexStageInput input)
|
||||
{
|
||||
GlyphData glyph = glyphData[input.glyphIndex];
|
||||
|
||||
float xpos = input.position.x + glyph.bearing.x * scale;
|
||||
float ypos = input.position.y - (glyph.size.y - glyph.bearing.y) * scale;
|
||||
|
||||
float w = glyph.size.x * scale;
|
||||
float h = glyph.size.y * scale;
|
||||
|
||||
float4 coordinates[4] = {
|
||||
float4(xpos, ypos + h, 0, 0),
|
||||
float4(xpos, ypos, 0, 1),
|
||||
float4(xpos + w, ypos, 1, 0),
|
||||
float4(xpos + w, ypos + h, 1, 1)
|
||||
};
|
||||
float4 vertex = coordinates[input.vertexId];
|
||||
VertexStageOutput output;
|
||||
output.uvCoords = vertex.zw;
|
||||
output.position = mul(viewData.projectionMatrix, float4(vertex.xy, 0, 1));
|
||||
output.glyphIndex = input.glyphIndex;
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(
|
||||
float4 position : SV_Position,
|
||||
float2 uvCoords : TEXCOORD,
|
||||
uint glyphIndex : GLYPHINDEX
|
||||
) : SV_Target
|
||||
{
|
||||
return glyphTextures[glyphIndex].Sample(glyphSampler, uvCoords);
|
||||
}
|
||||
@@ -17,7 +17,6 @@ VertexStageOutput vertexMain(uint vertexId : SV_VertexID)
|
||||
VertexStageOutput output;
|
||||
output.uvCoords = coordinates[vertexId];
|
||||
output.position = float4(output.uvCoords * 2 - 1, 1, 1);
|
||||
output.position.y = -output.position.y;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
slangc ForwardPlus.slang -target spirv -entry vertexMain -profile vs_6_0 -o vertex.spv -I lib/ -D USE_INSTANCING=0 -D NUM_MATERIAL_TEXCOORDS=1
|
||||
slangc ForwardPlus.slang -target spirv -entry fragmentMain -profile ps_6_0 -o fragment.spv -I lib/ -D USE_INSTANCING=0 -D NUM_MATERIAL_TEXCOORDS=1
|
||||
slangc TextPass.slang -target glsl -entry vertexMain -profile vs_6_0 -o vertex.glsl -I lib/ -D INDEX_VIEW_PARAMS=0
|
||||
slangc TextPass.slang -target glsl -entry fragmentMain -profile ps_6_0 -o fragment.glsl -I lib/ -D INDEX_VIEW_PARAMS=0
|
||||
@@ -0,0 +1,20 @@
|
||||
#version 450
|
||||
layout(row_major) uniform;
|
||||
layout(row_major) buffer;
|
||||
|
||||
#line 61 0
|
||||
layout(location = 0)
|
||||
out vec4 _S1;
|
||||
|
||||
|
||||
#line 61
|
||||
void main()
|
||||
{
|
||||
|
||||
#line 61
|
||||
_S1 = vec4(float(0), float(1), float(0), float(1));
|
||||
|
||||
#line 61
|
||||
return;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,114 @@
|
||||
#version 450
|
||||
layout(row_major) uniform;
|
||||
layout(row_major) buffer;
|
||||
|
||||
#line 7 0
|
||||
struct GlyphData_0
|
||||
{
|
||||
vec2 bearing_0;
|
||||
vec2 size_0;
|
||||
};
|
||||
|
||||
|
||||
layout(std430, binding = 1) readonly buffer _S1 {
|
||||
GlyphData_0 _data[];
|
||||
} glyphData_0;
|
||||
|
||||
#line 1
|
||||
struct ViewParameter_0
|
||||
{
|
||||
mat4x4 projectionMatrix_0;
|
||||
};
|
||||
|
||||
|
||||
#line 5
|
||||
layout(binding = 0)
|
||||
layout(std140) uniform _S2
|
||||
{
|
||||
ViewParameter_0 _data;
|
||||
} gViewParams_0;
|
||||
|
||||
#line 5
|
||||
layout(location = 0)
|
||||
out vec2 _S3;
|
||||
|
||||
|
||||
#line 5
|
||||
layout(location = 1)
|
||||
out uint _S4;
|
||||
|
||||
|
||||
#line 5
|
||||
layout(location = 0)
|
||||
in uint _S5;
|
||||
|
||||
|
||||
#line 5
|
||||
layout(location = 1)
|
||||
in vec2 _S6;
|
||||
|
||||
|
||||
#line 5
|
||||
layout(location = 2)
|
||||
in float _S7;
|
||||
|
||||
|
||||
#line 20
|
||||
struct VertexStageInput_0
|
||||
{
|
||||
uint glyphIndex_0;
|
||||
vec2 position_0;
|
||||
float scale_0;
|
||||
uint vertexId_0;
|
||||
};
|
||||
|
||||
struct VertexStageOutput_0
|
||||
{
|
||||
vec4 position_1;
|
||||
vec2 uvCoords_0;
|
||||
uint glyphIndex_1;
|
||||
};
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
#line 36
|
||||
VertexStageInput_0 _S8 = VertexStageInput_0(_S5, _S6, _S7, uint(gl_VertexIndex));
|
||||
|
||||
GlyphData_0 glyph_0 = ((glyphData_0)._data[(_S8.glyphIndex_0)]);
|
||||
|
||||
float xpos_0 = _S8.position_0.x + glyph_0.bearing_0.x * _S8.scale_0;
|
||||
float ypos_0 = _S8.position_0.y - (glyph_0.size_0.y - glyph_0.bearing_0.y) * _S8.scale_0;
|
||||
|
||||
float w_0 = glyph_0.size_0.x * _S8.scale_0;
|
||||
|
||||
|
||||
vec4 coordinates_0[4] = { vec4(xpos_0, ypos_0 + glyph_0.size_0.y * _S8.scale_0, float(0), float(0)), vec4(xpos_0, ypos_0, float(0), float(1)), vec4(xpos_0 + w_0, ypos_0, float(1), float(0)), vec4(xpos_0 + w_0, ypos_0 + w_0, float(1), float(1)) };
|
||||
|
||||
#line 46
|
||||
vec4 vertex_0 = coordinates_0[_S8.vertexId_0];
|
||||
|
||||
#line 53
|
||||
VertexStageOutput_0 output_0;
|
||||
output_0.uvCoords_0 = vertex_0.zw;
|
||||
vec4 _S9 = (((vec4(vertex_0.xy, float(0), float(1))) * (gViewParams_0._data.projectionMatrix_0)));
|
||||
|
||||
#line 55
|
||||
output_0.position_1 = _S9;
|
||||
output_0.glyphIndex_1 = _S8.glyphIndex_0;
|
||||
VertexStageOutput_0 _S10 = output_0;
|
||||
|
||||
#line 57
|
||||
gl_Position = _S10.position_1;
|
||||
|
||||
#line 57
|
||||
_S3 = _S10.uvCoords_0;
|
||||
|
||||
#line 57
|
||||
_S4 = _S10.glyphIndex_1;
|
||||
|
||||
#line 57
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user