Merge SurfaceVertex with FFlatVertex and draw the lightmaps
This commit is contained in:
parent
e9620e64a4
commit
240d68d7ae
29 changed files with 263 additions and 276 deletions
|
|
@ -201,9 +201,9 @@ void VkLightmap::Render()
|
|||
pc.TextureSize = (float)bakeImageSize;
|
||||
pc.TileWidth = (float)targetSurface->AtlasTile.Width;
|
||||
pc.TileHeight = (float)targetSurface->AtlasTile.Height;
|
||||
pc.WorldToLocal = targetSurface->translateWorldToLocal;
|
||||
pc.ProjLocalToU = targetSurface->projLocalToU;
|
||||
pc.ProjLocalToV = targetSurface->projLocalToV;
|
||||
pc.WorldToLocal = SwapYZ(targetSurface->translateWorldToLocal);
|
||||
pc.ProjLocalToU = SwapYZ(targetSurface->projLocalToU);
|
||||
pc.ProjLocalToV = SwapYZ(targetSurface->projLocalToV);
|
||||
|
||||
bool buffersFull = false;
|
||||
|
||||
|
|
@ -229,13 +229,13 @@ void VkLightmap::Render()
|
|||
for (int i = 0; i < lightCount; i++)
|
||||
{
|
||||
const LevelMeshLight* light = &templightlist[i];
|
||||
lightinfo->Origin = light->Origin;
|
||||
lightinfo->RelativeOrigin = light->RelativeOrigin;
|
||||
lightinfo->Origin = SwapYZ(light->Origin);
|
||||
lightinfo->RelativeOrigin = SwapYZ(light->RelativeOrigin);
|
||||
lightinfo->Radius = light->Radius;
|
||||
lightinfo->Intensity = light->Intensity;
|
||||
lightinfo->InnerAngleCos = light->InnerAngleCos;
|
||||
lightinfo->OuterAngleCos = light->OuterAngleCos;
|
||||
lightinfo->SpotDir = light->SpotDir;
|
||||
lightinfo->SpotDir = SwapYZ(light->SpotDir);
|
||||
lightinfo->Color = light->Color;
|
||||
lightinfo++;
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ void VkLightmap::Render()
|
|||
void VkLightmap::UploadUniforms()
|
||||
{
|
||||
Uniforms values = {};
|
||||
values.SunDir = mesh->SunDirection;
|
||||
values.SunDir = SwapYZ(mesh->SunDirection);
|
||||
values.SunColor = mesh->SunColor;
|
||||
values.SunIntensity = 1.0f;
|
||||
|
||||
|
|
@ -760,7 +760,7 @@ void VkLightmap::CreateRaytracePipeline()
|
|||
.RenderPass(raytrace.renderPass.get())
|
||||
.AddVertexShader(shaders.vertRaytrace.get())
|
||||
.AddFragmentShader(shaders.fragRaytrace[i].get())
|
||||
.AddVertexBufferBinding(0, sizeof(SurfaceVertex))
|
||||
.AddVertexBufferBinding(0, sizeof(FFlatVertex))
|
||||
.AddVertexAttribute(0, 0, VK_FORMAT_R32G32B32A32_SFLOAT, 0)
|
||||
.Topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
|
||||
.AddDynamicState(VK_DYNAMIC_STATE_VIEWPORT)
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ private:
|
|||
static FString LoadPublicShaderLump(const char* lumpname);
|
||||
static ShaderIncludeResult OnInclude(FString headerName, FString includerName, size_t depth, bool system);
|
||||
|
||||
FVector3 SwapYZ(const FVector3& v) { return FVector3(v.X, v.Z, v.Y); }
|
||||
|
||||
VulkanRenderDevice* fb = nullptr;
|
||||
LevelMesh* mesh = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ void VkRaytrace::UploadMeshes(bool dynamicOnly)
|
|||
for (unsigned int i = start; i < end; i++)
|
||||
{
|
||||
const SubmeshBufferLocation& cur = locations[i];
|
||||
transferBufferSize += cur.Submesh->MeshVertices.Size() * sizeof(SurfaceVertex);
|
||||
transferBufferSize += cur.Submesh->MeshVertices.Size() * sizeof(FFlatVertex);
|
||||
transferBufferSize += cur.Submesh->MeshElements.Size() * sizeof(uint32_t);
|
||||
transferBufferSize += cur.Submesh->Collision->get_nodes().size() * sizeof(CollisionNode);
|
||||
transferBufferSize += cur.Submesh->MeshSurfaceIndexes.Size() * sizeof(int);
|
||||
|
|
@ -205,13 +205,10 @@ void VkRaytrace::UploadMeshes(bool dynamicOnly)
|
|||
const SubmeshBufferLocation& cur = locations[i];
|
||||
auto submesh = cur.Submesh;
|
||||
|
||||
SurfaceVertex* vertices = (SurfaceVertex*)(data + datapos);
|
||||
for (int j = 0, count = submesh->MeshVertices.Size(); j < count; ++j)
|
||||
*(vertices++) = { { submesh->MeshVertices[j], 1.0f }, submesh->MeshVertexUVs[j], float(j), j + 10000.0f, FVector3(0.0f, 0.0f, -1.0f), 0.0f};
|
||||
|
||||
size_t copysize = submesh->MeshVertices.Size() * sizeof(SurfaceVertex);
|
||||
size_t copysize = submesh->MeshVertices.Size() * sizeof(FFlatVertex);
|
||||
memcpy(data + datapos, submesh->MeshVertices.Data(), copysize);
|
||||
if (copysize > 0)
|
||||
cmdbuffer->copyBuffer(transferBuffer.get(), VertexBuffer.get(), datapos, cur.VertexOffset * sizeof(SurfaceVertex), copysize);
|
||||
cmdbuffer->copyBuffer(transferBuffer.get(), VertexBuffer.get(), datapos, cur.VertexOffset * sizeof(FFlatVertex), copysize);
|
||||
datapos += copysize;
|
||||
}
|
||||
|
||||
|
|
@ -283,7 +280,7 @@ void VkRaytrace::UploadMeshes(bool dynamicOnly)
|
|||
LevelMeshSurface* surface = submesh->GetSurface(j);
|
||||
|
||||
SurfaceInfo info;
|
||||
info.Normal = surface->plane.XYZ();
|
||||
info.Normal = FVector3(surface->plane.X, surface->plane.Z, surface->plane.Y);
|
||||
info.PortalIndex = surface->portalIndex;
|
||||
info.SamplingDistance = (float)surface->sampleDimension;
|
||||
info.Sky = surface->bSky;
|
||||
|
|
@ -371,7 +368,7 @@ void VkRaytrace::CreateBuffers()
|
|||
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
|
||||
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR : 0) |
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)
|
||||
.Size(GetMaxVertexBufferSize() * sizeof(SurfaceVertex))
|
||||
.Size(GetMaxVertexBufferSize() * sizeof(FFlatVertex))
|
||||
.DebugName("VertexBuffer")
|
||||
.Create(fb->GetDevice());
|
||||
|
||||
|
|
@ -425,7 +422,7 @@ VkRaytrace::BLAS VkRaytrace::CreateBLAS(LevelSubmesh* submesh, bool preferFastBu
|
|||
accelStructBLDesc.geometry.triangles = { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR };
|
||||
accelStructBLDesc.geometry.triangles.vertexFormat = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
accelStructBLDesc.geometry.triangles.vertexData.deviceAddress = VertexBuffer->GetDeviceAddress();
|
||||
accelStructBLDesc.geometry.triangles.vertexStride = sizeof(SurfaceVertex);
|
||||
accelStructBLDesc.geometry.triangles.vertexStride = sizeof(FFlatVertex);
|
||||
accelStructBLDesc.geometry.triangles.indexType = VK_INDEX_TYPE_UINT32;
|
||||
accelStructBLDesc.geometry.triangles.indexData.deviceAddress = IndexBuffer->GetDeviceAddress() + indexOffset * sizeof(uint32_t);
|
||||
accelStructBLDesc.geometry.triangles.maxVertex = vertexOffset + submesh->MeshVertices.Size() - 1;
|
||||
|
|
|
|||
|
|
@ -37,15 +37,6 @@ struct SurfaceInfo
|
|||
float Alpha;
|
||||
};
|
||||
|
||||
struct SurfaceVertex
|
||||
{
|
||||
FVector4 pos;
|
||||
FVector2 uv;
|
||||
float Padding1, Padding2;
|
||||
FVector3 lightmap;
|
||||
float Padding3;
|
||||
};
|
||||
|
||||
struct PortalInfo
|
||||
{
|
||||
VSMatrix transformation;
|
||||
|
|
@ -125,7 +116,7 @@ private:
|
|||
|
||||
std::unique_ptr<VulkanBuffer> NodeBuffer;
|
||||
|
||||
TArray<SurfaceVertex> Vertices;
|
||||
TArray<FFlatVertex> Vertices;
|
||||
static const int MaxDynamicVertices = 100'000;
|
||||
static const int MaxDynamicIndexes = 100'000;
|
||||
static const int MaxDynamicSurfaces = 100'000;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb)
|
|||
{
|
||||
static const FVertexBufferAttribute format[] =
|
||||
{
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_VERTEX, VFmt_Float4, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) },
|
||||
{ 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) },
|
||||
{ 0, VATTR_LIGHTMAP, VFmt_Float2, (int)myoffsetof(FFlatVertex, lu) },
|
||||
};
|
||||
|
||||
Flatbuffer.VertexFormat = fb->GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format);
|
||||
|
|
|
|||
|
|
@ -657,11 +657,11 @@ void VulkanRenderDevice::DrawLevelMesh(const HWViewpointUniforms& viewpoint)
|
|||
|
||||
static const FVertexBufferAttribute format[] =
|
||||
{
|
||||
{ 0, VATTR_VERTEX, VFmt_Float4, (int)myoffsetof(SurfaceVertex, pos.X) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(SurfaceVertex, uv.X) },
|
||||
{ 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(SurfaceVertex, lightmap.X) },
|
||||
{ 0, VATTR_VERTEX, VFmt_Float4, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) },
|
||||
{ 0, VATTR_LIGHTMAP, VFmt_Float2, (int)myoffsetof(FFlatVertex, lu) },
|
||||
};
|
||||
int vertexFormatIndex = GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(SurfaceVertex), format);
|
||||
int vertexFormatIndex = GetRenderPassManager()->GetVertexFormat(1, 3, sizeof(FFlatVertex), format);
|
||||
VkBuffer vertexBuffers[2] = { GetRaytrace()->GetVertexBuffer()->buffer, GetRaytrace()->GetVertexBuffer()->buffer };
|
||||
VkDeviceSize vertexBufferOffsets[] = { 0, 0 };
|
||||
cmdbuffer->bindVertexBuffers(0, 2, vertexBuffers, vertexBufferOffsets);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue