gameknife / gkNextRenderer

A Modern gkRenderer
15 stars 2 forks source link

trying to implement accumulation + reprojection mix #11

Closed tigrazone closed 1 week ago

tigrazone commented 2 weeks ago

When I rewrite https://github.com/tigrazone/gkNextRenderer/blob/89874c0fb3af386ed685cc2985ca2c040cebd073/assets/shaders/RayTracing.rgen#L202 imageStore(AccumulationImage, ipos, vec4(pixelColor, 0)); like this

    uint TemporalFrames = max(1, Camera.TemporalFrames);
    if(Camera.frameNum > TemporalFrames/10+1) {
    precise vec4 prevPixelColor = imageLoad(AccumulationImage, ipos);
    prevPixelColor += vec4(pixelColor, 0);
    imageStore(AccumulationImage, ipos, prevPixelColor);
    } else {
    imageStore(AccumulationImage, ipos, vec4(pixelColor, 0) * (Camera.frameNum + 1));
    }

and https://github.com/tigrazone/gkNextRenderer/blob/89874c0fb3af386ed685cc2985ca2c040cebd073/assets/shaders/Accumulate.comp#L24 vec4 src = imageLoad(NewSourceImage, ipos); with vec4 src = imageLoad(NewSourceImage, ipos) / float(Camera.frameNum + 1);

Then image in time darker and grayed... Something works wrong. Take a look https://www.youtube.com/watch?v=o7QfF9HBkxI Maybe you know how to implement it better

Originally posted by @tigrazone in https://github.com/gameknife/gkNextRenderer/issues/10#issuecomment-2183774798

gameknife commented 1 week ago

it may be the half float precise issue? the accumulation value will increase to a very big number, try change the RenderImage Format to R32G32B32A32?

tigrazone commented 1 week ago

Thank you. It helps Changes:

        rtAccumulation_.reset(new RenderImage(Device(), extent, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_TILING_OPTIMAL,  VK_IMAGE_USAGE_STORAGE_BIT));
        rtOutput_.reset(new RenderImage(Device(), extent, format, VK_IMAGE_TILING_OPTIMAL,VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT));
        rtPingPong0.reset(new RenderImage(Device(), extent, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_STORAGE_BIT));
        rtPingPong1.reset(new RenderImage(Device(), extent, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_STORAGE_BIT));

https://github.com/tigrazone/gkNextRenderer/blob/89874c0fb3af386ed685cc2985ca2c040cebd073/src/Vulkan/RayTrace/RayTracingRenderer.cpp#L340-L344 and

layout(binding = 0, rgba32f) uniform image2D NewSourceImage;
layout(binding = 1, rgba32f) uniform image2D AccumulateImage;
layout(binding = 2, rgba32f) uniform image2D Accumulate1Image;

https://github.com/tigrazone/gkNextRenderer/blob/89874c0fb3af386ed685cc2985ca2c040cebd073/assets/shaders/Accumulate.comp#L7C1-L9C63 and

if(Camera.TotalFrames == 0 || Camera.frameNum > TemporalFrames) https://github.com/tigrazone/gkNextRenderer/blob/89874c0fb3af386ed685cc2985ca2c040cebd073/assets/shaders/Accumulate.comp#L87

tigrazone commented 1 week ago

my result is https://www.youtube.com/watch?v=0pF5xQCOzdA no denoiser but quality of picture is good. and convolve without blinking noise now