@@ -29,11 +29,19 @@ namespace nbl::asset
29
29
30
30
constexpr auto snorm_all_ones = hlsl::vector<int8_t , 4 >(snorm_one, snorm_one, snorm_one, snorm_one);
31
31
32
- }
32
+ template <typename ElementT>
33
+ requires (std::is_same_v<ElementT, uint8_t > || std::is_same_v<ElementT, uint16_t >)
34
+ constexpr E_FORMAT get_uv_format()
35
+ {
36
+ if constexpr (std::is_same_v<ElementT, uint8_t >)
37
+ {
38
+ return EF_R8G8_UNORM;
39
+ } else
40
+ {
41
+ return EF_R16G16_UNORM;
42
+ }
43
+ }
33
44
34
- static uint8_t packSnorm (float val)
35
- {
36
- return round (hlsl::clamp (val, -1 .0f , 1 .0f ) * 127 );
37
45
}
38
46
39
47
template <typename ElementT>
@@ -61,13 +69,13 @@ static ICPUPolygonGeometry::SDataView createUvView(size_t vertexCount)
61
69
if constexpr (std::is_same_v<ElementT, uint8_t >)
62
70
{
63
71
retval.composed .encodedDataRange .u8 = aabb;
64
- retval.composed .format = EF_R8G8_UNORM ;
72
+ retval.composed .format = get_uv_format<ElementT>() ;
65
73
retval.composed .rangeFormat = IGeometryBase::EAABBFormat::U8_NORM;
66
74
}
67
75
else if constexpr (std::is_same_v<ElementT, uint16_t >)
68
76
{
69
77
retval.composed .encodedDataRange .u16 = aabb;
70
- retval.composed .format = EF_R16G16_UNORM ;
78
+ retval.composed .format = get_uv_format<ElementT>() ;
71
79
retval.composed .rangeFormat = IGeometryBase::EAABBFormat::U16_NORM;
72
80
}
73
81
@@ -458,7 +466,8 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createSphere(float
458
466
// tu = ((float*)(tmpMem+(i-polyCountXPitch)*vertexSize))[4];
459
467
460
468
positions[vertex_i] = pos;
461
- uvs[vertex_i] = { packSnorm (tu), packSnorm (static_cast <float >(ay * numbers::inv_pi<float32_t >())) };
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 );
462
471
memcpy (normals + vertex_i, &quantizedNormal, sizeof (quantizedNormal));
463
472
464
473
vertex_i++;
@@ -537,6 +546,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCylinder(
537
546
snorm_normal_t * normals;
538
547
539
548
using uv_element_t = uint16_t ;
549
+ constexpr auto UnityUV = std::numeric_limits<uv_element_t >::max ();
540
550
hlsl::vector<uv_element_t , 2 >* uvs;
541
551
{
542
552
{
@@ -573,11 +583,12 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCylinder(
573
583
574
584
positions[i] = { p.x , p.y , p.z };
575
585
memcpy (normals + i, &n, sizeof (n));
576
- uvs[i] = { packSnorm (f_i * tesselationRec), packSnorm (0.0 ) };
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 );
577
588
578
589
positions[i + halfIx] = { p.x , p.y , length };
579
590
normals[i + halfIx] = normals[i];
580
- uvs[i + halfIx] = { packSnorm ( 1 . 0f ), packSnorm ( 0 . 0f ) };
591
+ uvs[i + halfIx] = { UnityUV, 0 };
581
592
}
582
593
583
594
CPolygonGeometryManipulator::recomputeContentHashes (retval.get ());
0 commit comments