Skip to content

Commit

Permalink
vsm: epipolar fog in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Nov 4, 2024
1 parent 32bc730 commit 869292f
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 75 deletions.
22 changes: 14 additions & 8 deletions game/graphics/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ void Renderer::resetSwapchain() {
vsm.pageData = device.zbuffer(shadowFormat, 8192, 8192);
// vsm.pageDataCs = device.image2d(TextureFormat::R32U, 4096, 4096);

vsm.ssTrace = device.image2d(TextureFormat::RGBA8, w, h);
vsm.epTrace = device.image2d(TextureFormat::RGBA8, 1024, 512);
// vsm.ssTrace = device.image2d(TextureFormat::RGBA8, w, h);
vsm.ssTrace = device.image2d(TextureFormat::R32U, w, h);
vsm.epTrace = device.image2d(TextureFormat::R16, 512, 2*1024);
vsm.epipoles = device.ssbo(nullptr, uint32_t(vsm.epTrace.h())*6*sizeof(float));

const int32_t VSM_PAGE_SIZE = 128;
auto pageCount = uint32_t(vsm.pageData.w()/VSM_PAGE_SIZE) * uint32_t(vsm.pageData.h()/VSM_PAGE_SIZE);
Expand Down Expand Up @@ -478,14 +480,16 @@ void Renderer::prepareUniforms() {
vsm.uboEpipole.set(0, vsm.ssTrace);
vsm.uboEpipole.set(1, vsm.epTrace);
vsm.uboEpipole.set(2, wview->sceneGlobals().uboGlobal[SceneGlobals::V_Main]);
vsm.uboEpipole.set(3, zbuffer);
vsm.uboEpipole.set(4, vsm.pageTbl);
vsm.uboEpipole.set(5, vsm.pageData);
vsm.uboEpipole.set(3, vsm.epipoles);
vsm.uboEpipole.set(4, zbuffer);
vsm.uboEpipole.set(5, vsm.pageTbl);
vsm.uboEpipole.set(6, vsm.pageData);

vsm.uboFogShadow.set(0, vsm.ssTrace);
vsm.uboFogShadow.set(1, vsm.epTrace);
vsm.uboFogShadow.set(2, wview->sceneGlobals().uboGlobal[SceneGlobals::V_Main]);
vsm.uboFogShadow.set(3, zbuffer);
vsm.uboFogShadow.set(3, vsm.epipoles);
vsm.uboFogShadow.set(4, zbuffer);

vsm.uboClump.set(0, vsm.pageList);
vsm.uboClump.set(1, vsm.pageTbl);
Expand Down Expand Up @@ -528,6 +532,7 @@ void Renderer::prepareUniforms() {
}
wview->setShadowMaps(sh);
wview->setVirtualShadowMap(vsm.pageData, vsm.pageDataCs, vsm.pageTbl, vsm.pageHiZ, vsm.pageList);
wview->setVsmSkyShadows(vsm.ssTrace);
wview->setSwRenderingImage(swr.outputImage);

wview->setHiZ(textureCast<const Texture2d&>(hiz.hiZ));
Expand Down Expand Up @@ -606,7 +611,8 @@ void Renderer::dbgDraw(Tempest::Painter& p) {
//tex.push_back(&textureCast(hiz.hiZSm1));
//tex.push_back(&textureCast(shadowMap[1]));
//tex.push_back(&textureCast<const Texture2d&>(shadowMap[0]));
tex.push_back(&textureCast<const Texture2d&>(vsm.pageData));
//tex.push_back(&textureCast<const Texture2d&>(vsm.pageData));
tex.push_back(&textureCast<const Texture2d&>(vsm.ssTrace));

static int size = 400;
int left = 10;
Expand Down Expand Up @@ -939,7 +945,7 @@ void Renderer::drawVsm(Tempest::Encoder<Tempest::CommandBuffer>& cmd, uint8_t fI
cmd.setFramebuffer({});
cmd.setDebugMarker("VSM-epipolar");
cmd.setUniforms(shaders.vsmFogEpipolar, vsm.uboEpipole);
cmd.dispatch(uint32_t(vsm.epTrace.w()));
cmd.dispatch(uint32_t(vsm.epTrace.h()));

cmd.setDebugMarker("VSM-epipolar-fog");
cmd.setUniforms(shaders.vsmFogShadow, vsm.uboFogShadow);
Expand Down
1 change: 1 addition & 0 deletions game/graphics/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class Renderer final {

Tempest::StorageImage ssTrace;
Tempest::StorageImage epTrace;
Tempest::StorageBuffer epipoles;
} vsm;

struct {
Expand Down
6 changes: 6 additions & 0 deletions game/graphics/sceneglobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ SceneGlobals::SceneGlobals() {
vsmPageHiZ = &Resources::fallbackImage3d();
vsmDbg = device.image2d(Tempest::TextureFormat::R32U, 64, 64);

skyShadows = &Resources::fallbackImage();

for(uint8_t lay=0; lay<V_Count; ++lay) {
uboGlobal[lay] = device.ssbo(nullptr,sizeof(UboGlobal));
}
Expand Down Expand Up @@ -228,6 +230,10 @@ void SceneGlobals::setVirtualShadowMap(const Tempest::ZBuffer& pageData,
vsmPageList = &pageList;
}

void SceneGlobals::setVsmSkyShadows(const Tempest::StorageImage& sh) {
skyShadows = &sh;
}

void SceneGlobals::setSwRenderingImage(const Tempest::StorageImage& mainView) {
swMainImage = &mainView;
}
Expand Down
7 changes: 5 additions & 2 deletions game/graphics/sceneglobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SceneGlobals final {
const Tempest::StorageImage& pageTbl,
const Tempest::StorageImage& pageHiZ,
const Tempest::StorageBuffer& vsmPageList);
void setVsmSkyShadows(const Tempest::StorageImage& skyShadows);
void setSwRenderingImage(const Tempest::StorageImage& mainView);

const Tempest::Matrix4x4& viewProject() const;
Expand Down Expand Up @@ -82,9 +83,11 @@ class SceneGlobals final {
const Tempest::StorageImage* vsmPageTbl = nullptr;
const Tempest::StorageImage* vsmPageHiZ = nullptr;
const Tempest::StorageBuffer* vsmPageList = nullptr;
Tempest::StorageImage vsmDbg;
Tempest::StorageImage vsmDbg;

const Tempest::StorageImage* swMainImage = nullptr;
const Tempest::StorageImage* skyShadows = nullptr;

const Tempest::StorageImage* swMainImage = nullptr;

struct UboGlobal final {
Tempest::Matrix4x4 viewProject;
Expand Down
19 changes: 15 additions & 4 deletions game/graphics/sky/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void Sky::updateLight(const int64_t now) {
float ax = 360-360*std::fmod(k+0.25f,1.f);
ax = ax*float(M_PI/180.0);
sun.setDir(-std::sin(ax)*shadowLength, pulse, std::cos(ax)*shadowLength);
//sun.setDir(0, 1, 0); //debug
}

static float sunMul = 1;
Expand Down Expand Up @@ -384,7 +385,12 @@ void Sky::prepareUniforms() {
uboFog3d.set(0, fogLut3D, smpB);
uboFog3d.set(1, *scene.zbuffer, Sampler::nearest());
uboFog3d.set(2, scene.uboGlobal[SceneGlobals::V_Main]);
uboFog3d.set(3, occlusionLut);
if(quality==VolumetricHQVsm) {
// uboFog3d.set(3, occlusionLut);
uboFog3d.set(3, *scene.skyShadows);
} else {
uboFog3d.set(3, occlusionLut);
}
}

if(quality==PathTrace) {
Expand Down Expand Up @@ -461,15 +467,20 @@ void Sky::prepareFog(Tempest::Encoder<Tempest::CommandBuffer>& cmd, uint32_t fra
cmd.dispatchThreads(uint32_t(fogLut3D.w()),uint32_t(fogLut3D.h()));
break;
}
case VolumetricHQ:
case VolumetricHQVsm: {
const bool vsm = (quality==VolumetricHQVsm);
case VolumetricHQ:{
const bool vsm = (quality==VolumetricHQVsm); //TODO: make vsm dedicated path
auto& fogOcclusion = vsm ? Shaders::inst().fogOcclusionVsm : Shaders::inst().fogOcclusion;

cmd.setFramebuffer({});
cmd.setUniforms(fogOcclusion, uboOcclusion, &ubo, sizeof(ubo));
cmd.dispatchThreads(occlusionLut.size());

cmd.setUniforms(Shaders::inst().fogViewLut3d, uboFogViewLut3d, &ubo, sizeof(ubo));
cmd.dispatchThreads(uint32_t(fogLut3D.w()),uint32_t(fogLut3D.h()));
break;
}
case VolumetricHQVsm: {
// shadows filled extenally
cmd.setUniforms(Shaders::inst().fogViewLut3d, uboFogViewLut3d, &ubo, sizeof(ubo));
cmd.dispatchThreads(uint32_t(fogLut3D.w()),uint32_t(fogLut3D.h()));
break;
Expand Down
4 changes: 4 additions & 0 deletions game/graphics/worldview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void WorldView::setVirtualShadowMap(const Tempest::ZBuffer& pageData,
sGlobal.setVirtualShadowMap(pageData, pageDataCs, pageTbl, pageHiZ, pageList);
}

void WorldView::setVsmSkyShadows(const Tempest::StorageImage& skyShadows) {
sGlobal.setVsmSkyShadows(skyShadows);
}

void WorldView::setSwRenderingImage(const Tempest::StorageImage& mainView) {
sGlobal.setSwRenderingImage(mainView);
}
Expand Down
1 change: 1 addition & 0 deletions game/graphics/worldview.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WorldView {
const Tempest::StorageImage& pageTbl,
const Tempest::StorageImage& pageHiZ,
const Tempest::StorageBuffer& pageList);
void setVsmSkyShadows(const Tempest::StorageImage& skyShadows);
void setSwRenderingImage(const Tempest::StorageImage& mainView);
void setHiZ(const Tempest::Texture2d& hiZ);
void setSceneImages(const Tempest::Texture2d& clr, const Tempest::Texture2d& depthAux, const Tempest::ZBuffer& depthNative);
Expand Down
Loading

0 comments on commit 869292f

Please sign in to comment.