Skip to content

Commit 734b887

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-Examples-and-Tests into autoexposure_ex
2 parents 4a11724 + 28f3ea5 commit 734b887

File tree

8 files changed

+567
-539
lines changed

8 files changed

+567
-539
lines changed

35_GeometryCreator/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ foreach(NBL_INPUT_SHADER IN LISTS NBL_THIS_EXAMPLE_INPUT_SHADERS)
3434

3535
if(NBL_SHADER_TYPE STREQUAL .vertex)
3636
set(NBL_NSC_COMPILE_OPTIONS -T vs_6_7 -E VSMain)
37+
elseif(NBL_SHADER_TYPE STREQUAL .geometry)
38+
set(NBL_NSC_COMPILE_OPTIONS -T gs_6_7 -E GSMain)
3739
elseif(NBL_SHADER_TYPE STREQUAL .fragment)
3840
set(NBL_NSC_COMPILE_OPTIONS -T ps_6_7 -E PSMain)
3941
else()
@@ -66,4 +68,4 @@ foreach(NBL_INPUT_SHADER IN LISTS NBL_THIS_EXAMPLE_INPUT_SHADERS)
6668
endforeach()
6769

6870
ADD_CUSTOM_BUILTIN_RESOURCES(extGizmoSpirvBuiltinResourceData IMGUI_EXT_SPIRV_RESOURCES_TO_EMBED "${_THIS_EXAMPLE_SPIRV_BR_BUNDLE_SEARCH_DIRECTORY_}" "nbl" "this_example::spirv::builtin" "${_THIS_EXAMPLE_SPIRV_BR_OUTPUT_DIRECTORY_HEADER_}" "${_THIS_EXAMPLE_SPIRV_BR_OUTPUT_DIRECTORY_SOURCE_}" "STATIC" "INTERNAL")
69-
LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} extGizmoSpirvBuiltinResourceData)
71+
LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} extGizmoSpirvBuiltinResourceData)

35_GeometryCreator/main.cpp

Lines changed: 521 additions & 514 deletions
Large diffs are not rendered by default.

62_CAD/Hatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using namespace nbl;
1919

2020
enum class HatchFillPattern: uint32_t
2121
{
22-
SOLID_FILL,
22+
SOLID_FILL = 0,
2323
CHECKERED,
2424
DIAMONDS,
2525
CROSS_HATCH,

62_CAD/SingleLineText.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
SingleLineText::SingleLineText(core::smart_refctd_ptr<nbl::ext::TextRendering::FontFace>&& face, const std::string& text)
44
{
55
m_face = std::move(face);
6-
glyphBoxes.reserve(text.length());
6+
m_glyphBoxes.reserve(text.length());
7+
8+
m_boundingBox.min = float64_t2(0.0, 0.0);
9+
m_boundingBox.max = float64_t2(0.0, 0.0);
710

811
// Position transform
912
float64_t2 currentPos = float32_t2(0.0, 0.0);
1013
for (uint32_t i = 0; i < text.length(); i++)
1114
{
1215
const auto glyphIndex = m_face->getGlyphIndex(wchar_t(text.at(i)));
13-
const auto glyphMetrics = m_face->getGlyphMetricss(glyphIndex);
16+
const auto glyphMetrics = m_face->getGlyphMetrics(glyphIndex);
1417
const bool skipGenerateGlyph = (glyphIndex == 0 || (glyphMetrics.size.x == 0.0 && glyphMetrics.size.y == 0.0));
1518

1619
if (!skipGenerateGlyph)
@@ -25,7 +28,13 @@ SingleLineText::SingleLineText(core::smart_refctd_ptr<nbl::ext::TextRendering::F
2528
.size = glyphMetrics.size,
2629
.glyphIdx = glyphIndex,
2730
};
28-
glyphBoxes.push_back(glyphBbox);
31+
32+
m_boundingBox.min.x = nbl::core::min(m_boundingBox.min.x, glyphBbox.topLeft.x);
33+
m_boundingBox.min.y = nbl::core::min(m_boundingBox.min.y, glyphBbox.topLeft.y - glyphBbox.size.y);
34+
m_boundingBox.max.x = nbl::core::max(m_boundingBox.max.x, glyphBbox.topLeft.x + glyphBbox.size.x);
35+
m_boundingBox.max.y = nbl::core::max(m_boundingBox.max.y, glyphBbox.topLeft.y);
36+
37+
m_glyphBoxes.push_back(glyphBbox);
2938
}
3039
currentPos += glyphMetrics.advance;
3140
}
@@ -36,7 +45,8 @@ void SingleLineText::Draw(
3645
SIntendedSubmitInfo& intendedNextSubmit,
3746
const float64_t2& baselineStart,
3847
const float32_t2& scale,
39-
const float32_t& rotateAngle)
48+
const float32_t& rotateAngle,
49+
const float32_t4& color) const
4050
{
4151
float32_t2 vec(cos(rotateAngle), sin(rotateAngle));
4252
float64_t3x3 rotationMulScaleMat =
@@ -54,11 +64,11 @@ void SingleLineText::Draw(
5464
float64_t3x3 transformation = mul(translationMat, rotationMulScaleMat);
5565

5666
LineStyleInfo lineStyle = {};
57-
lineStyle.color = float32_t4(1.0, 1.0, 1.0, 1.0);
67+
lineStyle.color = color;
5868
const uint32_t styleIdx = drawResourcesFiller.addLineStyle_SubmitIfNeeded(lineStyle, intendedNextSubmit);
5969
auto glyphObjectIdx = drawResourcesFiller.addMainObject_SubmitIfNeeded(styleIdx, intendedNextSubmit);
6070

61-
for (const auto& glyphBox : glyphBoxes)
71+
for (const auto& glyphBox : m_glyphBoxes)
6272
{
6373
const float64_t2 topLeft = mul(transformation, float64_t3(glyphBox.topLeft, 1.0)).xy;
6474
const float64_t2 dirU = mul(transformation, float64_t3(glyphBox.size.x, 0.0, 0.0)).xy;
@@ -70,5 +80,4 @@ void SingleLineText::Draw(
7080
drawResourcesFiller.drawFontGlyph(m_face.get(), glyphBox.glyphIdx, topLeft, dirU, aspectRatio, minUV, glyphObjectIdx, intendedNextSubmit);
7181
}
7282

73-
}
74-
83+
}

62_CAD/SingleLineText.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ class SingleLineText
1212
public:
1313
// constructs and fills the `glyphBoxes`
1414
SingleLineText(core::smart_refctd_ptr<nbl::ext::TextRendering::FontFace>&& face, const std::string& text);
15+
16+
struct BoundingBox
17+
{
18+
float64_t2 min;
19+
float64_t2 max;
20+
};
21+
22+
BoundingBox GetAABB() const { return m_boundingBox; }
1523

1624
// iterates over `glyphBoxes` generates textures msdfs if failed to add to cache (through that lambda you put)
1725
// void Draw(DrawResourcesFiller& drawResourcesFiller, SIntendedSubmitInfo& intendedNextSubmit);
1826
void Draw(
1927
DrawResourcesFiller& drawResourcesFiller,
2028
SIntendedSubmitInfo& intendedNextSubmit,
2129
const float64_t2& baselineStart = float64_t2(0.0,0.0),
22-
const float32_t2& scale = float64_t2(1.0, 1.0),
23-
const float32_t& rotateAngle = 0);
30+
const float32_t2& scale = float64_t2(1.0f, 1.0f),
31+
const float32_t& rotateAngle = 0.0f,
32+
const float32_t4& color = float32_t4(1.0f,1.0f,1.0f,1.0f)) const;
2433

2534
protected:
2635

@@ -31,8 +40,8 @@ class SingleLineText
3140
uint32_t glyphIdx;
3241
uint32_t pad;
3342
};
34-
35-
std::vector<GlyphBox> glyphBoxes;
43+
44+
BoundingBox m_boundingBox = {};
45+
std::vector<GlyphBox> m_glyphBoxes;
3646
core::smart_refctd_ptr<nbl::ext::TextRendering::FontFace> m_face;
37-
};
38-
47+
};

62_CAD/fragment_shader.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ float4 main(PSInput input) : SV_TARGET
567567
{
568568
float3 msdfSample = msdfTextures.Sample(msdfSampler, float3(frac(input.position.xy / HatchFillMSDFSceenSpaceSize), float(textureId))).xyz;
569569
float msdf = nbl::hlsl::text::msdfDistance(msdfSample, MSDFPixelRange, HatchFillMSDFSceenSpaceSize / MSDFSize);
570-
localAlpha = smoothstep(+globals.antiAliasingFactor / 2.0, -globals.antiAliasingFactor / 2.0f, msdf);
570+
localAlpha *= smoothstep(+globals.antiAliasingFactor / 2.0, -globals.antiAliasingFactor / 2.0f, msdf);
571571
}
572572
}
573573
else if (objType == ObjectType::FONT_GLYPH)

62_CAD/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ constexpr std::array<float, (uint32_t)ExampleMode::CASE_COUNT> cameraExtents =
6868
600.0, // CASE_8
6969
};
7070

71-
constexpr ExampleMode mode = ExampleMode::CASE_3;
71+
constexpr ExampleMode mode = ExampleMode::CASE_8;
7272

7373
class Camera2D
7474
{
@@ -2922,7 +2922,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
29222922
{
29232923
char k = TestString[i];
29242924
auto glyphIndex = m_arialFont->getGlyphIndex(wchar_t(k));
2925-
const auto glyphMetrics = m_arialFont->getGlyphMetricss(glyphIndex);
2925+
const auto glyphMetrics = m_arialFont->getGlyphMetrics(glyphIndex);
29262926
const float64_t2 baselineStart = currentBaselineStart;
29272927

29282928
currentBaselineStart += glyphMetrics.advance;

62_CAD/vertex_shader.hlsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,14 @@ PSInput main(uint vertexID : SV_VertexID)
506506
const float2 offsetVec = vx * undilatedCornerNDC.x + vy * undilatedCornerNDC.y;
507507
const float2 coord = screenTopLeft + corner.x * screenDirU + corner.y * screenDirV + offsetVec;
508508

509-
// If aspect ratio of the dimensions and glyph inside the texture are the same -->
510-
// it doesn't matter which component (x or y) to use to compute screenPxRange.
509+
// If aspect ratio of the dimensions and glyph inside the texture are the same then screenPxRangeX === screenPxRangeY
511510
// but if the glyph box is stretched in any way then we won't get correct msdf
512-
// We compute this value using the ration of our screenspace extent to the texel space our glyph takes inside the texture
511+
// in that case we need to take the max(screenPxRangeX, screenPxRangeY) to avoid blur due to underexaggerated distances
512+
// We compute screenPxRange using the ratio of our screenspace extent to the texel space our glyph takes inside the texture
513513
// Our glyph is centered inside the texture, so `maxUV = 1.0 - minUV` and `glyphTexelSize = (1.0-2.0*minUV) * MSDFSize
514-
const float screenPxRange = max(screenSpaceAabbExtents.x / ((1.0 - 2.0 * minUV.x) * MSDFSize), 1.0);
514+
const float screenPxRangeX = screenSpaceAabbExtents.x / ((1.0 - 2.0 * minUV.x) * MSDFSize);
515+
const float screenPxRangeY = screenSpaceAabbExtents.y / ((1.0 - 2.0 * minUV.y) * MSDFSize);
516+
const float screenPxRange = max(max(screenPxRangeX, screenPxRangeY), 1.0);
515517

516518
// In order to keep the shape scale constant with any dilation values:
517519
// We compute the new dilated minUV that gets us minUV when interpolated on the previous undilated top left
@@ -524,8 +526,7 @@ PSInput main(uint vertexID : SV_VertexID)
524526
outV.position = float4(coord, 0.f, 1.f);
525527
outV.setFontGlyphUV(uv);
526528
outV.setFontGlyphTextureId(textureID);
527-
outV.setFontGlyphScreenPxRange(screenPxRange);
528-
}
529+
outV.setFontGlyphScreenPxRange(screenPxRange); }
529530
else if (objType == ObjectType::IMAGE)
530531
{
531532
float64_t2 topLeft = vk::RawBufferLoad<double2>(drawObj.geometryAddress, 8u);

0 commit comments

Comments
 (0)