Skip to content

Commit a001472

Browse files
author
kevyuu
committed
Remove unused include
1 parent 4afd072 commit a001472

File tree

1 file changed

+32
-76
lines changed

1 file changed

+32
-76
lines changed

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 32 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55

66
#include "nbl/asset/utils/CGeometryCreator.h"
77
#include "nbl/builtin/hlsl/tgmath.hlsl"
8+
#include "nbl/builtin/hlsl/math/linalg/transform.hlsl"
89

9-
#include <iostream>
10-
#include <iomanip>
1110
#include <cmath>
1211
#include <cstdint>
1312

14-
1513
namespace nbl::asset
1614
{
1715

@@ -159,6 +157,12 @@ static ICPUPolygonGeometry::SDataView createSnormNormalView(size_t normalCount,
159157
};
160158
}
161159

160+
static void encodeUv(hlsl::vector<uint16_t, 2>* uvDst, hlsl::float32_t2 uvSrc)
161+
{
162+
uint32_t u32_uv = hlsl::packUnorm2x16(uvSrc);
163+
memcpy(uvDst, &u32_uv, sizeof(uint16_t) * 2);
164+
}
165+
162166
core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCube(const hlsl::float32_t3 size) const
163167
{
164168
using namespace hlsl;
@@ -458,16 +462,15 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createSphere(float
458462
//if (y==0)
459463
//{
460464
if (normal.y != -1.0f && normal.y != 1.0f)
461-
tu = static_cast<float>(acos(core::clamp(normal.x / sinay, -1.0, 1.0)) * 0.5 * numbers::inv_pi<float32_t>());
465+
tu = static_cast<float>(acos(core::clamp(normal.x / sinay, -1.0, 1.0)) * 0.5 * numbers::inv_pi<float32_t>);
462466
if (normal.z < 0.0f)
463467
tu = 1 - tu;
464468
//}
465469
//else
466470
//tu = ((float*)(tmpMem+(i-polyCountXPitch)*vertexSize))[4];
467471

468472
positions[vertex_i] = pos;
469-
float32_t2 f32_uv = { tu, static_cast<float>(ay * numbers::inv_pi<float32_t>()) };
470-
encodePixels<get_uv_format<uv_element_t>(), float>(uvs + vertex_i, f32_uv.data.data);
473+
encodeUv(uvs + vertex_i, float32_t2(tu, static_cast<float>(ay* numbers::inv_pi<float32_t>)));
471474
memcpy(normals + vertex_i, &quantizedNormal, sizeof(quantizedNormal));
472475

473476
vertex_i++;
@@ -476,7 +479,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createSphere(float
476479
// This is the doubled vertex on the initial position
477480

478481
positions[vertex_i] = positions[old_vertex_i];
479-
uvs[vertex_i] = { 127, uvs[old_vertex_i].y };
482+
uvs[vertex_i] = { UnityUV, uvs[old_vertex_i].y };
480483
normals[vertex_i] = normals[old_vertex_i];
481484

482485
vertex_i++;
@@ -583,12 +586,11 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCylinder(
583586

584587
positions[i] = { p.x, p.y, p.z };
585588
memcpy(normals + i, &n, sizeof(n));
586-
float32_t2 f32_uv = { f_i * tesselationRec, 0.f };
587-
encodePixels<get_uv_format<uv_element_t>(), float>(uvs + i, f32_uv.data.data);
589+
encodeUv(uvs + i, float32_t2(f_i * tesselationRec, 0.f));
588590

589591
positions[i + halfIx] = { p.x, p.y, length };
590592
normals[i + halfIx] = normals[i];
591-
uvs[i + halfIx] = { UnityUV, 0 };
593+
uvs[i + halfIx] = { 1.f * tesselationRec, UnityUV };
592594
}
593595

594596
CPolygonGeometryManipulator::recomputeContentHashes(retval.get());
@@ -602,9 +604,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
602604

603605
using namespace hlsl;
604606

605-
CQuantNormalCache* const quantNormalCache = quantNormalCacheOverride == nullptr ? m_params.normalCache.get() : quantNormalCacheOverride;
606-
607-
const uint32_t u32_vertexCount = 2 * tesselation;
607+
const uint32_t u32_vertexCount = tesselation + 1;
608608
if (u32_vertexCount > std::numeric_limits<uint16_t>::max())
609609
return nullptr;
610610
const auto vertexCount = static_cast<uint16_t>(u32_vertexCount);
@@ -615,31 +615,25 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
615615
// Create indices
616616
using index_t = uint16_t;
617617
{
618-
constexpr uint32_t RowCount = 2u;
619618
const auto IndexCount = 3 * tesselation;
620619

621620
auto indexView = createIndexView<index_t>(IndexCount, vertexCount - 1);
622621
auto u = reinterpret_cast<index_t*>(indexView.src.buffer->getPointer());
623622

624-
const uint32_t firstIndexOfBaseVertices = 0;
625-
const uint32_t firstIndexOfApexVertices = tesselation;
623+
const uint32_t apexVertexIndex = tesselation;
626624

627625
for (uint32_t i = 0; i < tesselation; i++)
628626
{
629-
u[i * 3] = firstIndexOfApexVertices + i;
630-
u[(i * 3) + 1] = firstIndexOfBaseVertices + i;
631-
u[(i * 3) + 2] = i == (tesselation - 1) ? firstIndexOfBaseVertices : firstIndexOfBaseVertices + i + 1;
627+
u[i * 3] = apexVertexIndex;
628+
u[(i * 3) + 1] = i;
629+
u[(i * 3) + 2] = i == (tesselation - 1) ? 0 : i + 1;
632630
}
633631

634632
retval->setIndexView(std::move(indexView));
635633
}
636634

637-
constexpr auto NormalCacheFormat = EF_R8G8B8_SNORM;
638-
constexpr auto NormalFormat = EF_R8G8B8A8_SNORM;
639-
640635
// Create vertex attributes with NONE usage because we have no clue how they'll be used
641636
hlsl::float32_t3* positions;
642-
snorm_normal_t* normals;
643637
{
644638
{
645639
shapes::AABB<4, float32_t> aabb;
@@ -649,14 +643,6 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
649643
positions = reinterpret_cast<decltype(positions)>(positionView.src.buffer->getPointer());
650644
retval->setPositionView(std::move(positionView));
651645
}
652-
{
653-
shapes::AABB<4, int8_t> aabb;
654-
aabb.maxVx = snorm_all_ones;
655-
aabb.minVx = -aabb.maxVx;
656-
auto normalView = createSnormNormalView(vertexCount, aabb);
657-
normals = reinterpret_cast<decltype(normals)>(normalView.src.buffer->getPointer());
658-
retval->setNormalView(std::move(normalView));
659-
}
660646
}
661647

662648
const float step = (2.f*core::PI<float>()) / tesselation;
@@ -669,38 +655,15 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
669655
{
670656
hlsl::float32_t3 v(std::cos(i * step), 0.0f, std::sin(i * step));
671657
v *= radius;
672-
673-
positions[i] = { v.x, v.y, v.z };
674-
positions[apexVertexBase_i + i] = { apexVertexCoords.x, apexVertexCoords.y, apexVertexCoords.z };
675-
676-
const auto simdPosition = hlsl::float32_t3(positions[i].x, positions[i].y, positions[i].z);
677-
const hlsl::float32_t3 v0ToApex = apexVertexCoords - simdPosition;
678-
679-
uint32_t nextVertexIndex = i == (tesselation - 1) ? 0 : i + 1;
680-
hlsl::float32_t3 u1 = hlsl::float32_t3(positions[nextVertexIndex].x, positions[nextVertexIndex].y, positions[nextVertexIndex].z);
681-
u1 -= simdPosition;
682-
float angleWeight = std::acos(hlsl::dot(hlsl::normalize(apexVertexCoords), hlsl::normalize(u1)));
683-
u1 = hlsl::normalize(hlsl::cross(v0ToApex, u1)) * angleWeight;
684-
685-
uint32_t prevVertexIndex = i == 0 ? (tesselation - 1) : i - 1;
686-
hlsl::float32_t3 u2 = hlsl::float32_t3(positions[prevVertexIndex].x, positions[prevVertexIndex].y, positions[prevVertexIndex].z);
687-
u2 -= simdPosition;
688-
angleWeight = std::acos(hlsl::dot(hlsl::normalize(apexVertexCoords), hlsl::normalize(u2)));
689-
u2 = hlsl::normalize(hlsl::cross(u2, v0ToApex)) * angleWeight;
690-
691-
692-
const auto baseNormal = quantNormalCache->quantize<NormalCacheFormat>(hlsl::normalize(u1 + u2));
693-
memcpy(normals + i, &baseNormal, sizeof(baseNormal));
694-
695-
const auto apexNormal = quantNormalCache->quantize<NormalCacheFormat>(hlsl::normalize(u1));
696-
memcpy(normals + apexVertexBase_i + i, &apexNormal, sizeof(apexNormal));
658+
positions[i] = v;
697659
}
660+
positions[apexVertexBase_i] = apexVertexCoords;
698661

699662
CPolygonGeometryManipulator::recomputeContentHashes(retval.get());
700663
return retval;
701664
}
702665

703-
core::vector<core::smart_refctd_ptr<ICPUPolygonGeometry>> CGeometryCreator::createArrow(
666+
core::smart_refctd_ptr<ICPUGeometryCollection> CGeometryCreator::createArrow(
704667
const uint16_t tesselationCylinder,
705668
const uint16_t tesselationCone,
706669
const float height,
@@ -711,25 +674,20 @@ core::vector<core::smart_refctd_ptr<ICPUPolygonGeometry>> CGeometryCreator::crea
711674
{
712675
assert(height > cylinderHeight);
713676

714-
using position_t = hlsl::float32_t3;
715-
716677
auto cylinder = createCylinder(width0, cylinderHeight, tesselationCylinder);
717678
auto cone = createCone(width1, height-cylinderHeight, tesselationCone);
718679

719-
auto conePositions = reinterpret_cast<position_t*>(cone->getPositionView().src.buffer->getPointer());
720-
721-
const auto coneVertexCount = cone->getPositionView().getElementCount();
722-
723-
for (auto i = 0ull; i < coneVertexCount; ++i)
724-
{
725-
auto& conePosition = conePositions[i];
726-
core::vector3df_SIMD newPos(conePosition.x, conePosition.y, conePosition.z);
727-
newPos.rotateYZByRAD(-1.5707963268);
728-
729-
conePosition = {newPos.x, newPos.y, newPos.z};
730-
}
731-
732-
return {cylinder, cone};
680+
auto collection = core::make_smart_refctd_ptr<ICPUGeometryCollection>();
681+
auto* geometries = collection->getGeometries();
682+
geometries->push_back({
683+
.geometry = cylinder
684+
});
685+
const auto coneTransform = hlsl::math::linalg::rotation_mat(-1.5707963268f, hlsl::float32_t3(1.f, 0.f, 0.f));
686+
geometries->push_back({
687+
.transform = hlsl::float32_t3x4(coneTransform),
688+
.geometry = cone
689+
});
690+
return collection;
733691

734692
}
735693

@@ -1855,9 +1813,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createIcoSphere(fl
18551813
for (auto uv_i = 0u; uv_i < icosphere.getVertexCount(); uv_i++)
18561814
{
18571815
const auto texCoords = icosphere.getTexCoords();
1858-
const auto f32_uv = float32_t2{ texCoords[2 * uv_i], texCoords[(2 * uv_i) + 1] };
1859-
const auto u32_uv = packUnorm2x16(f32_uv);
1860-
memcpy(uvs + uv_i, &u32_uv, sizeof(u32_uv));
1816+
encodeUv(uvs + uv_i, float32_t2(texCoords[2 * uv_i], texCoords[(2 * uv_i) + 1]));
18611817
}
18621818

18631819
retval->getAuxAttributeViews()->push_back(std::move(uvView));

0 commit comments

Comments
 (0)