mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-22 03:51:26 +00:00
Trace the sun
This commit is contained in:
parent
1d51bc17de
commit
6e8757649c
2 changed files with 38 additions and 0 deletions
|
@ -74,6 +74,30 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 incoming = vec3(0.0);
|
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++)
|
for (uint j = LightStart; j < LightEnd; j++)
|
||||||
{
|
{
|
||||||
LightInfo light = lights[j];
|
LightInfo light = lights[j];
|
||||||
|
|
|
@ -44,6 +44,20 @@ void GPURaytracer2::Raytrace(LevelMesh* level)
|
||||||
|
|
||||||
BeginCommands();
|
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;
|
std::vector<LightmapImage> surfaceImages;
|
||||||
|
|
||||||
for (size_t i = 0; i < mesh->surfaces.size(); i++)
|
for (size_t i = 0; i < mesh->surfaces.size(); i++)
|
||||||
|
|
Loading…
Reference in a new issue