Skip to content

Commit

Permalink
only update tdao texture when camera moves
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 17, 2024
1 parent eeffad9 commit 4683303
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/renderer/postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ struct TDAO : public RenderPlugin {
float m_y_range = 200;
float m_intensity = 0.3f;
bool m_enabled = true;
DVec3 m_last_camera_pos = DVec3(DBL_MAX);

struct PipelineInstanceData {
RenderBufferHandle rb = INVALID_RENDERBUFFER;
Expand Down Expand Up @@ -827,6 +828,7 @@ struct TDAO : public RenderPlugin {
auto* inst_data = pipeline.getData<PipelineInstanceData>();

if (!m_enabled) {
m_last_camera_pos = DVec3(DBL_MAX);
inst_data->rb = INVALID_RENDERBUFFER;
return;
}
Expand All @@ -843,15 +845,16 @@ struct TDAO : public RenderPlugin {
pipeline.keepRenderbufferAlive(inst_data->rb);
DrawStream& stream = pipeline.getRenderer().getDrawStream();

// TODO
bool camera_moved = true;
const Viewport& vp = pipeline.getViewport();
const bool camera_moved = fabs(vp.pos.x - m_last_camera_pos.x) > 3 || fabs(vp.pos.y - m_last_camera_pos.y) > 3 || fabs(vp.pos.z - m_last_camera_pos.z) > 3;
if (camera_moved) {
m_last_camera_pos = vp.pos;
pipeline.setRenderTargets({}, inst_data->rb);
pipeline.clear(gpu::ClearFlags::ALL, 0, 0, 0, 1, 0);

CameraParams cp;
const Quat rot(-0.707106769f, 0, 0, 0.707106769f);
cp.pos = pipeline.getViewport().pos;
cp.pos = vp.pos;
ShiftedFrustum frustum;
const float ratio = 1;
frustum.computeOrtho({ 0, 0, 0 },
Expand All @@ -861,7 +864,7 @@ struct TDAO : public RenderPlugin {
m_xz_range,
-0.5f * m_y_range,
0.5f * m_y_range);
frustum.origin = pipeline.getViewport().pos;
frustum.origin = vp.pos;
cp.frustum = frustum;
cp.lod_multiplier = 1;
cp.is_shadow = false;
Expand All @@ -885,7 +888,6 @@ struct TDAO : public RenderPlugin {
pipeline.renderBucket(view_id, 1);
}

const Viewport& vp = pipeline.getViewport();
struct {
Vec4 offset;
Vec2 size;
Expand All @@ -898,7 +900,7 @@ struct TDAO : public RenderPlugin {
gpu::RWBindlessHandle u_gbufferB;
gpu::BindlessHandle u_topdown_depthmap;
} ubdata = {
Vec4(0, 0, 0, 0),
Vec4(Vec3(vp.pos - m_last_camera_pos), 0),
Vec2((float)vp.w, (float)vp.h),
m_intensity,
m_xz_range,
Expand Down

0 comments on commit 4683303

Please sign in to comment.