mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-05 00:33:51 +00:00
feat(rendering): GPU architecture + visual quality fixes
M2 GPU instancing - M2InstanceGPU SSBO (96 B/entry, double-buffered, 16384 max) - Group opaque instances by (modelId, LOD); single vkCmdDrawIndexed per group - boneBase field indexes into mega bone SSBO via gl_InstanceIndex Indirect terrain drawing - 24 MB mega index buffer (6M uint32) + 64 MB mega vertex buffer - CPU builds VkDrawIndexedIndirectCommand per visible chunk - Single VB/IB bind per frame; shadow pass reuses mega buffers - Replaced vkCmdDrawIndexedIndirect with direct vkCmdDrawIndexed to fix host-mapped buffer race condition that caused terrain flickering GPU frustum culling (compute shader) - m2_cull.comp.glsl: 64-thread workgroups, sphere-vs-6-planes + distance cull - CullInstanceGPU SSBO input, uint visibility[] output, double-buffered - dispatchCullCompute() runs before main pass via render graph node Consolidated bone matrix SSBOs - 16 MB double-buffered mega bone SSBO (2048 instances × 128 bones) - Eliminated per-instance descriptor sets; one megaBoneSet_ per frame - prepareRender() packs bone matrices consecutively into current frame slot Render graph / frame graph - RenderGraph: RGResource handles, RGPass nodes, Kahn topological sort - Automatic VkImageMemoryBarrier/VkBufferMemoryBarrier between passes - Passes: minimap_composite, worldmap_composite, preview_composite, shadow_pass, reflection_pass, compute_cull - beginFrame() uses buildFrameGraph() + renderGraph_->execute(cmd) Pipeline derivatives - PipelineBuilder::setFlags/setBasePipeline for VK_PIPELINE_CREATE_DERIVATIVE_BIT - M2 opaque = base; alphaTest/alpha/additive are derivatives - Applied to terrain (wireframe) and WMO (alpha-test) renderers Rendering bug fixes: - fix(shadow): compute lightSpaceMatrix before updatePerFrameUBO to eliminate one-frame lag that caused shadow trails and flicker on moving objects - fix(shadow): scale depth bias with shadowDistance_ instead of hardcoded 0.8f to prevent acne at close range and gaps at far range - fix(visibility): WMO group distance threshold 500u → 1200u to match terrain view distance; buildings were disappearing on the horizon - fix(precision): camera near plane 0.05 → 0.5 (ratio 600K:1 → 60K:1), eliminating Z-fighting and improving frustum plane extraction stability - fix(streaming): terrain load radius 4 → 6 tiles (~2133u → ~3200u) to exceed M2 render distance (2800u) and eliminate pop-in when camera turns; unload radius 7 → 9; spawn radius 3 → 4 - fix(visibility): ground-detail M2 distance multiplier 0.75 → 0.9 to reduce early pop of grass and debris
This commit is contained in:
parent
ca3cea078b
commit
d54e262048
22 changed files with 1579 additions and 494 deletions
|
|
@ -169,7 +169,7 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
vertexAttribs[4] = { 4, 0, VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
static_cast<uint32_t>(offsetof(WMOVertexData, tangent)) };
|
||||
|
||||
// --- Build opaque pipeline ---
|
||||
// --- Build opaque pipeline (base for derivatives — shared state optimization) ---
|
||||
VkRenderPass mainPass = vkCtx_->getImGuiRenderPass();
|
||||
|
||||
opaquePipeline_ = PipelineBuilder()
|
||||
|
|
@ -184,6 +184,7 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
if (!opaquePipeline_) {
|
||||
|
|
@ -193,7 +194,7 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
return false;
|
||||
}
|
||||
|
||||
// --- Build transparent pipeline ---
|
||||
// --- Build transparent pipeline (derivative of opaque) ---
|
||||
transparentPipeline_ = PipelineBuilder()
|
||||
.setShaders(vertShader.stageInfo(VK_SHADER_STAGE_VERTEX_BIT),
|
||||
fragShader.stageInfo(VK_SHADER_STAGE_FRAGMENT_BIT))
|
||||
|
|
@ -206,13 +207,15 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
if (!transparentPipeline_) {
|
||||
core::Logger::getInstance().warning("WMORenderer: transparent pipeline not available");
|
||||
}
|
||||
|
||||
// --- Build glass pipeline (alpha blend WITH depth write for windows) ---
|
||||
// --- Build glass pipeline (derivative — alpha blend WITH depth write for windows) ---
|
||||
glassPipeline_ = PipelineBuilder()
|
||||
.setShaders(vertShader.stageInfo(VK_SHADER_STAGE_VERTEX_BIT),
|
||||
fragShader.stageInfo(VK_SHADER_STAGE_FRAGMENT_BIT))
|
||||
|
|
@ -225,9 +228,11 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
// --- Build wireframe pipeline ---
|
||||
// --- Build wireframe pipeline (derivative of opaque) ---
|
||||
wireframePipeline_ = PipelineBuilder()
|
||||
.setShaders(vertShader.stageInfo(VK_SHADER_STAGE_VERTEX_BIT),
|
||||
fragShader.stageInfo(VK_SHADER_STAGE_FRAGMENT_BIT))
|
||||
|
|
@ -240,6 +245,8 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
if (!wireframePipeline_) {
|
||||
|
|
@ -1434,7 +1441,7 @@ void WMORenderer::render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const
|
|||
if (doDistanceCull) {
|
||||
glm::vec3 closestPoint = glm::clamp(camPos, gMin, gMax);
|
||||
float distSq = glm::dot(closestPoint - camPos, closestPoint - camPos);
|
||||
if (distSq > 250000.0f) {
|
||||
if (distSq > 1440000.0f) { // 1200 units — matches terrain view distance
|
||||
result.distanceCulled++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -3733,6 +3740,7 @@ void WMORenderer::recreatePipelines() {
|
|||
|
||||
VkRenderPass mainPass = vkCtx_->getImGuiRenderPass();
|
||||
|
||||
// Pipeline derivatives — opaque is the base, others derive for shared state optimization
|
||||
opaquePipeline_ = PipelineBuilder()
|
||||
.setShaders(vertShader.stageInfo(VK_SHADER_STAGE_VERTEX_BIT),
|
||||
fragShader.stageInfo(VK_SHADER_STAGE_FRAGMENT_BIT))
|
||||
|
|
@ -3745,6 +3753,7 @@ void WMORenderer::recreatePipelines() {
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
transparentPipeline_ = PipelineBuilder()
|
||||
|
|
@ -3759,6 +3768,8 @@ void WMORenderer::recreatePipelines() {
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
glassPipeline_ = PipelineBuilder()
|
||||
|
|
@ -3773,6 +3784,8 @@ void WMORenderer::recreatePipelines() {
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
wireframePipeline_ = PipelineBuilder()
|
||||
|
|
@ -3787,6 +3800,8 @@ void WMORenderer::recreatePipelines() {
|
|||
.setLayout(pipelineLayout_)
|
||||
.setRenderPass(mainPass)
|
||||
.setDynamicStates({ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR })
|
||||
.setFlags(VK_PIPELINE_CREATE_DERIVATIVE_BIT)
|
||||
.setBasePipeline(opaquePipeline_)
|
||||
.build(device, vkCtx_->getPipelineCache());
|
||||
|
||||
vertShader.destroy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue