Skip to content
Snippets Groups Projects
Commit 176812fa authored by Susanne Dötsch's avatar Susanne Dötsch
Browse files

[#92] updated cube vertices, started integrating hit shader

parent 53b41f0b
Branches
Tags
1 merge request!75Resolve "RTX-Module"
Pipeline #27298 passed
......@@ -78,21 +78,15 @@ namespace vkcv::rtx {
tlasWrite.setDescriptorCount(1);
tlasWrite.setDescriptorType(vk::DescriptorType::eAccelerationStructureKHR);
m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr);
vk::WriteDescriptorSet tlasWrite2;
tlasWrite2.setPNext(&AccelerationDescriptor);
tlasWrite2.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[1]).vulkanHandle);
tlasWrite2.setDstBinding(5);
tlasWrite2.setDstArrayElement(0);
tlasWrite2.setDescriptorCount(1);
tlasWrite2.setDescriptorType(vk::DescriptorType::eAccelerationStructureKHR);
m_core->getContext().getDevice().updateDescriptorSets(tlasWrite2, nullptr);
tlasWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[1]).vulkanHandle);
m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr);
tlasWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[2]).vulkanHandle);
m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr);
//INDEX & VERTEX BUFFER
BottomLevelAccelerationStructure blas = m_asManager->getBLAS(0);//HARD CODED
//VERTEX BUFFER
vk::DescriptorBufferInfo vertexInfo = {};
vertexInfo.setBuffer(blas.vertexBuffer.vulkanHandle);
vertexInfo.setOffset(0);
......
#version 460
#extension GL_EXT_ray_tracing : require
#extension GL_EXT_nonuniform_qualifier : enable
#define M_PI 3.1415926535897932384626433832795
//Mat struct
/*struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 emission;
};*/
//hitAttributeEXT vec2 hitCoordinate;
layout(location = 0) rayPayloadInEXT Payload {
vec3 rayOrigin;
......@@ -13,17 +26,69 @@ layout(location = 0) rayPayloadInEXT Payload {
int rayActive;
} payload;
layout(location = 1) rayPayloadEXT bool isShadow;
layout(location = 2, binding = 1, set = 0) uniform accelerationStructureEXT tlas; // top level acceleration structure (for the noobs here (you!))
/*
layout( push_constant ) uniform constants {
vec4 camera_position; // as origin for ray generation
vec4 camera_right; // for computing ray direction
vec4 camera_up; // for computing ray direction
vec4 camera_forward; // for computing ray direction
uint frameCount; // what is this? the actual frame?
}camera;
*/
layout(binding = 3, set = 0) buffer rtxVertices
{
vec3 vertices[];
};
float vertices[];
} rtxVertexBuffer;
layout(binding = 4, set = 0) buffer rtxIndices
{
uint indices[];
};
} rtxIndexBuffer;
/*
layout(binding = 0, set = 1) buffer MaterialIndexBuffer { uint data[]; } materialIndexBuffer;
layout(binding = 1, set = 1) buffer MaterialBuffer { Material data[]; } materialBuffer;
*/
float random(vec2 uv, float seed) {
return fract(sin(mod(dot(uv, vec2(12.9898, 78.233)) + 1113.1 * seed, M_PI)) * 43758.5453);;
}
vec3 uniformSampleHemisphere(vec2 uv) {
float z = uv.x;
float r = sqrt(max(0, 1.0 - z * z));
float phi = 2.0 * M_PI * uv.y;
return vec3(r * cos(phi), z, r * sin(phi));
}
vec3 alignHemisphereWithCoordinateSystem(vec3 hemisphere, vec3 up) {
vec3 right = normalize(cross(up, vec3(0.0072f, 1.0f, 0.0034f)));
vec3 forward = cross(right, up);
return hemisphere.x * right + hemisphere.y * up + hemisphere.z * forward;
}
void main() {/*
if (payload.rayActive == 0) {
return;
}*/
//ivec3 rtindices = ivec3(rtxIndexBuffer.indices[3 * gl_PrimitiveID + 0], rtxIndexBuffer.indices[3 * gl_PrimitiveID + 1], rtxIndexBuffer.indices[3 * gl_PrimitiveID + 2]);
/*
vec3 barycentric = vec3(1.0 - hitCoordinate.x - hitCoordinate.y, hitCoordinate.x, hitCoordinate.y);
vec3 vertexA = vec3(rtxVertexBuffer.vertices[3 * rtindices.x + 0], rtxVertexBuffer.vertices[3 * rtindices.x + 1], rtxVertexBuffer.vertices[3 * rtindices.x + 2]);
vec3 vertexB = vec3(rtxVertexBuffer.vertices[3 * rtindices.y + 0], rtxVertexBuffer.vertices[3 * rtindices.y + 1], rtxVertexBuffer.vertices[3 * rtindices.y + 2]);
vec3 vertexC = vec3(rtxVertexBuffer.vertices[3 * rtindices.z + 0], rtxVertexBuffer.vertices[3 * rtindices.z + 1], rtxVertexBuffer.vertices[3 * rtindices.z + 2]);
vec3 position = vertexA * barycentric.x + vertexB * barycentric.y + vertexC * barycentric.z;
vec3 geometricNormal = normalize(cross(vertexB - vertexA, vertexC - vertexA));*/
void main() {
payload.directColor=vec3(1,0,0);
}
......@@ -36,7 +36,7 @@ void main(){
uv = (uv * 2.0f - 1.0f) * vec2(1.0f, -1.0f);
payload.rayOrigin = camera.camera_position.xyz;
payload.rayDirection = normalize(uv.x * camera.camera_right + uv.y * camera.camera_up + camera.camera_forward).xyz;
payload.rayDirection = normalize(uv.x * camera.camera_right * (-1) + uv.y * camera.camera_up * (-1) + camera.camera_forward).xyz ;
payload.previousNormal = vec3(0.0, 0.0, 0.0);
payload.directColor = vec3(0.0, 0.0, 0.0);
......
......@@ -13,7 +13,7 @@ layout(location = 0) rayPayloadInEXT Payload {
int rayActive;
} payload;
layout(binding = 5, set = 0) uniform accelerationStructureEXT tlas; //not neccesary in shader but for compiling ->bug
layout(location = 1, binding = 1, set = 0) uniform accelerationStructureEXT tlas; //not neccesary in shader but for compiling ->bug
void main() {
payload.rayActive = 0;
......
......@@ -68,14 +68,14 @@ int main(int argc, const char** argv) {
// TODO: replace by bigger scene
float cubeVertices[8*3] =
{
0.f,0.f,0.f,
2.f,0.f,0.f,
2.f,2.f,0.f,
0.f,2.f,0.f,
0.f,0.f,2.f,
2.f,0.f,2.f,
2.f,2.f,2.f,
0.f,2.f,2.f
-1.f,-1.f,-1.f,
1.f,-1.f,-1.f,
1.f,1.f,-1.f,
-1.f,1.f,-1.f,
-1.f,-1.f,1.f,
1.f,-1.f,1.f,
1.f,1.f,1.f,
-1.f,1.f,1.f
};
uint32_t cubeIndices[6 * 6] =
......@@ -192,7 +192,7 @@ int main(int argc, const char** argv) {
cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
RaytracingPushConstantData raytracingPushData;
raytracingPushData.camera_position = glm::vec4(cameraManager.getActiveCamera().getPosition(),0);
raytracingPushData.camera_right = glm::vec4(glm::cross(cameraManager.getActiveCamera().getFront(), cameraManager.getActiveCamera().getUp()), 0);
......@@ -215,16 +215,16 @@ int main(int argc, const char** argv) {
core.prepareImageForStorage(cmdStream, swapchainInput);
core.recordRayGenerationToCmdStream(
cmdStream,
rtxPipeline,
rtxPipelineLayout,
cmdStream,
rtxPipeline,
rtxPipelineLayout,
rtxModule.getShaderBindingBuffer(),
rtxModule.getShaderGroupBaseAlignment(),
{ vkcv::DescriptorSetUsage(0, core.getDescriptorSet(rayGenShaderDescriptorSet).vulkanHandle),
vkcv::DescriptorSetUsage(1, core.getDescriptorSet(rayMissShaderDescriptorSet).vulkanHandle),
vkcv::DescriptorSetUsage(2, core.getDescriptorSet(rayCHITShaderDescriptorSet).vulkanHandle)
},
pushConstantsRTX,
pushConstantsRTX,
windowHandle);
core.prepareSwapchainImageForPresent(cmdStream);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment