-
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
Merged
Merged
Mesh loaders kevin #199
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
161733f
Fix example 71
f66d952
Add more geometry to geometry creator demo
0bc0557
Fix example 67
01c2b69
Fix example 67 indentation to use tabs
0b30462
Fix example 71 normal computation for more geometry
83394e4
Fix normal computation for icosphere example 67
822af13
Merge branch 'master' into mesh_loaders_kevin
5287dab
Add arrow geometry to example 67
1bbfd09
Fix example 67
25f1cd4
Fix example 71
30a5a19
Remore normal type unknown from demo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,69 +25,64 @@ float3 unpackNormals3x10(uint32_t v) | |
return clamp(float3(pn) / 511.0, -1.0, 1.0); | ||
} | ||
|
||
float3 calculateSmoothNormals(int instID, int primID, SGeomInfo geom, float2 bary) | ||
float3 calculateNormals(int primID, SGeomInfo geom, float2 bary) | ||
{ | ||
const uint indexType = geom.indexType; | ||
const uint vertexStride = geom.vertexStride; | ||
const uint normalType = geom.normalType; | ||
|
||
const uint64_t vertexBufferAddress = geom.vertexBufferAddress; | ||
const uint64_t indexBufferAddress = geom.indexBufferAddress; | ||
const uint64_t normalBufferAddress = geom.normalBufferAddress; | ||
devshgraphicsprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
uint32_t3 indices; | ||
switch (indexType) | ||
if (indexBufferAddress == 0) | ||
{ | ||
case 0: // EIT_16BIT | ||
indices = uint32_t3((nbl::hlsl::bda::__ptr<uint16_t3>::create(indexBufferAddress)+primID).deref().load()); | ||
break; | ||
case 1: // EIT_32BIT | ||
indices = uint32_t3((nbl::hlsl::bda::__ptr<uint32_t3>::create(indexBufferAddress)+primID).deref().load()); | ||
break; | ||
default: // EIT_NONE | ||
indices[0] = primID * 3; | ||
indices[1] = indices[0] + 1; | ||
indices[2] = indices[0] + 2; | ||
} | ||
else { | ||
switch (indexType) | ||
{ | ||
indices[0] = primID * 3; | ||
indices[1] = indices[0] + 1; | ||
indices[2] = indices[0] + 2; | ||
case 0: // EIT_16BIT | ||
indices = uint32_t3((nbl::hlsl::bda::__ptr<uint16_t3>::create(indexBufferAddress)+primID).deref().load()); | ||
break; | ||
case 1: // EIT_32BIT | ||
indices = uint32_t3((nbl::hlsl::bda::__ptr<uint32_t3>::create(indexBufferAddress)+primID).deref().load()); | ||
break; | ||
} | ||
} | ||
|
||
if (normalBufferAddress == 0 || normalType == NT_UNKNOWN) | ||
{ | ||
float3 v0 = vk::RawBufferLoad<float3>(vertexBufferAddress + indices[0] * 12); | ||
float3 v1 = vk::RawBufferLoad<float3>(vertexBufferAddress + indices[1] * 12); | ||
float3 v2 = vk::RawBufferLoad<float3>(vertexBufferAddress + indices[2] * 12); | ||
|
||
return normalize(cross(v2 - v0, v1 - v0)); | ||
} | ||
|
||
float3 n0, n1, n2; | ||
switch (instID) | ||
switch (normalType) | ||
{ | ||
case OT_CUBE: | ||
case NT_R8G8B8A8_SNORM: | ||
{ | ||
// 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); | ||
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(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_CYLINDER: | ||
case OT_ARROW: | ||
case OT_CONE: | ||
case NT_R32G32B32_SFLOAT: | ||
{ | ||
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); | ||
|
||
n0 = normalize(unpackNormals3x10(v0)); | ||
n1 = normalize(unpackNormals3x10(v1)); | ||
n2 = normalize(unpackNormals3x10(v2)); | ||
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)); | ||
Comment on lines
74
to
+83
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. normalization could have been hosted outside the switch to happen later, but oh well |
||
} | ||
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)); | ||
} | ||
} | ||
|
||
float3 barycentrics = float3(0.0, bary); | ||
|
@@ -124,15 +119,16 @@ void main(uint32_t3 threadID : SV_DispatchThreadID) | |
|
||
if (spirv::rayQueryGetIntersectionTypeKHR(query, true) == spv::RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionTriangleKHR) | ||
{ | ||
const int instID = spirv::rayQueryGetIntersectionInstanceIdKHR(query, true); | ||
const int instanceCustomIndex = spirv::rayQueryGetIntersectionInstanceCustomIndexKHR(query, true); | ||
const int geometryIndex = spirv::rayQueryGetIntersectionGeometryIndexKHR(query, true); | ||
const int primID = spirv::rayQueryGetIntersectionPrimitiveIndexKHR(query, true); | ||
|
||
// TODO: candidate for `bda::__ptr<SGeomInfo>` | ||
const SGeomInfo geom = vk::RawBufferLoad<SGeomInfo>(pc.geometryInfoBuffer + instID * sizeof(SGeomInfo),8); | ||
const SGeomInfo geom = vk::RawBufferLoad<SGeomInfo>(pc.geometryInfoBuffer + (instanceCustomIndex + geometryIndex) * sizeof(SGeomInfo), 8); | ||
|
||
float3 normals; | ||
float2 barycentrics = spirv::rayQueryGetIntersectionBarycentricsKHR(query, true); | ||
normals = calculateSmoothNormals(instID, primID, geom, barycentrics); | ||
normals = calculateNormals(primID, geom, barycentrics); | ||
|
||
normals = normalize(normals) * 0.5 + 0.5; | ||
color = float4(normals, 1.0); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.