Trace the sun

This commit is contained in:
Magnus Norddahl 2022-07-03 02:57:05 +02:00
parent 1d51bc17de
commit 6e8757649c
2 changed files with 38 additions and 0 deletions

View file

@ -74,6 +74,30 @@ void main()
}
vec3 incoming = vec3(0.0);
// Sun light
{
const float dist = 32768.0;
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, acc, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, origin, minDistance, SunDir, dist);
while(rayQueryProceedEXT(rayQuery))
{
if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCommittedIntersectionTriangleEXT)
{
rayQueryConfirmIntersectionEXT(rayQuery);
}
}
if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionTriangleEXT)
{
int primitiveID = rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true);
SurfaceInfo surface = surfaces[surfaceIndices[primitiveID]];
incoming.rgb += SunColor * SunIntensity * surface.Sky;
}
}
for (uint j = LightStart; j < LightEnd; j++)
{
LightInfo light = lights[j];

View file

@ -44,6 +44,20 @@ void GPURaytracer2::Raytrace(LevelMesh* level)
BeginCommands();
Uniforms2 uniforms = {};
uniforms.SunDir = mesh->map->GetSunDirection();
uniforms.SunColor = mesh->map->GetSunColor();
uniforms.SunIntensity = 1.0f;
mappedUniforms = (uint8_t*)uniformTransferBuffer->Map(0, uniformStructs * uniformStructStride);
*reinterpret_cast<Uniforms2*>(mappedUniforms + uniformStructStride * uniformsIndex) = uniforms;
uniformTransferBuffer->Unmap();
cmdbuffer->copyBuffer(uniformTransferBuffer.get(), uniformBuffer.get());
PipelineBarrier()
.AddBuffer(uniformBuffer.get(), VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT)
.Execute(cmdbuffer.get(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
std::vector<LightmapImage> surfaceImages;
for (size_t i = 0; i < mesh->surfaces.size(); i++)