-
Notifications
You must be signed in to change notification settings - Fork 13
Mesh loaders kevin #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Mesh loaders kevin #199
Changes from all commits
161733f
f66d952
0bc0557
01c2b69
0b30462
83394e4
822af13
5287dab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,9 @@ struct SGeomInfo | |
{ | ||
uint64_t vertexBufferAddress; | ||
uint64_t indexBufferAddress; | ||
uint64_t normalBufferAddress; | ||
|
||
uint32_t vertexStride : 29; | ||
uint32_t objType : 29; | ||
uint32_t indexType : 2; // 16 bit, 32 bit or none | ||
uint32_t smoothNormals : 1; // flat for cube, rectangle, disk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be inferred from |
||
uint32_t padding; | ||
|
@@ -35,8 +36,6 @@ enum ObjectType : uint32_t // matches c++ | |
OT_SPHERE, | ||
OT_CYLINDER, | ||
OT_RECTANGLE, | ||
OT_DISK, | ||
OT_ARROW, | ||
OT_CONE, | ||
OT_ICOSPHERE, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ float3 unpackNormals3x10(uint32_t v) | |
float3 calculateSmoothNormals(int instID, int primID, SGeomInfo geom, float2 bary) | ||
{ | ||
const uint indexType = geom.indexType; | ||
const uint vertexStride = geom.vertexStride; | ||
const uint objType = geom.objType; | ||
|
||
const uint64_t vertexBufferAddress = geom.vertexBufferAddress; | ||
const uint64_t indexBufferAddress = geom.indexBufferAddress; | ||
const uint64_t normalBufferAddress = geom.normalBufferAddress; | ||
Comment on lines
33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are you handling calculating smooth vertex normals vs cross product from positions |
||
|
||
uint32_t3 indices; | ||
switch (indexType) | ||
|
@@ -51,42 +52,30 @@ float3 calculateSmoothNormals(int instID, int primID, SGeomInfo geom, float2 bar | |
} | ||
|
||
float3 n0, n1, n2; | ||
switch (instID) | ||
switch (objType) | ||
{ | ||
case OT_CUBE: | ||
{ | ||
// TODO: document why the alignment is 2 here and nowhere else? isnt the `vertexStride` aligned to more than 2 anyway? | ||
uint32_t v0 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[0] * vertexStride, 2u); | ||
uint32_t v1 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[1] * vertexStride, 2u); | ||
uint32_t v2 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[2] * vertexStride, 2u); | ||
|
||
n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz); | ||
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz); | ||
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz); | ||
} | ||
break; | ||
case OT_SPHERE: | ||
case OT_RECTANGLE: | ||
case OT_CYLINDER: | ||
case OT_ARROW: | ||
//case OT_ARROW: | ||
case OT_CONE: | ||
{ | ||
uint32_t v0 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[0] * vertexStride); | ||
uint32_t v1 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[1] * vertexStride); | ||
uint32_t v2 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[2] * vertexStride); | ||
uint32_t v0 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[0] * 4); | ||
uint32_t v1 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[1] * 4); | ||
uint32_t v2 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[2] * 4); | ||
|
||
n0 = normalize(unpackNormals3x10(v0)); | ||
n1 = normalize(unpackNormals3x10(v1)); | ||
n2 = normalize(unpackNormals3x10(v2)); | ||
n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz); | ||
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz); | ||
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz); | ||
} | ||
break; | ||
case OT_RECTANGLE: | ||
case OT_DISK: | ||
case OT_ICOSPHERE: | ||
default: | ||
{ | ||
n0 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[0] * vertexStride)); | ||
n1 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[1] * vertexStride)); | ||
n2 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[2] * vertexStride)); | ||
n0 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[0] * 12)); | ||
n1 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[1] * 12)); | ||
n2 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[2] * 12)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,70 @@ using namespace nbl::examples; | |
|
||
#include "app_resources/common.hlsl" | ||
|
||
namespace nbl::scene | ||
{ | ||
enum ObjectType : uint8_t | ||
{ | ||
OT_CUBE, | ||
OT_SPHERE, | ||
OT_CYLINDER, | ||
OT_RECTANGLE, | ||
OT_CONE, | ||
OT_ICOSPHERE, | ||
|
||
OT_COUNT, | ||
OT_UNKNOWN = std::numeric_limits<uint8_t>::max() | ||
}; | ||
|
||
static constexpr uint32_t s_smoothNormals[OT_COUNT] = { 0, 1, 1, 0, 1, 1 }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can deduce from the |
||
|
||
struct ObjectMeta | ||
{ | ||
ObjectType type = OT_UNKNOWN; | ||
std::string_view name = "Unknown"; | ||
}; | ||
|
||
struct ObjectDrawHookCpu | ||
{ | ||
nbl::core::matrix3x4SIMD model; | ||
ObjectMeta meta; | ||
}; | ||
|
||
enum GeometryShader | ||
{ | ||
GP_BASIC = 0, | ||
GP_CONE, | ||
GP_ICO, | ||
|
||
GP_COUNT | ||
}; | ||
|
||
struct ReferenceObjectCpu | ||
{ | ||
ObjectMeta meta; | ||
core::matrix3x4SIMD transform; | ||
core::smart_refctd_ptr<ICPUPolygonGeometry> data; | ||
}; | ||
Comment on lines
+35
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clean this up, there's no geometry shader, the |
||
|
||
struct ReferenceObjectGpu | ||
{ | ||
struct Bindings | ||
{ | ||
nbl::asset::SBufferBinding<IGPUBuffer> vertex, index; | ||
}; | ||
|
||
ObjectMeta meta; | ||
Bindings bindings; | ||
uint32_t vertexStride; | ||
nbl::asset::E_INDEX_TYPE indexType = nbl::asset::E_INDEX_TYPE::EIT_UNKNOWN; | ||
uint32_t indexCount = {}; | ||
|
||
const bool useIndex() const | ||
{ | ||
return bindings.index.buffer && (indexType != E_INDEX_TYPE::EIT_UNKNOWN); | ||
} | ||
Comment on lines
+65
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lots unused stuff, or things which can be deduces from IGPUPolygonGeometry |
||
}; | ||
} | ||
|
||
|
||
#endif // _NBL_THIS_EXAMPLE_COMMON_H_INCLUDED_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none
should be inferred fromindexBufferAddress==0
so you only need 1 bit