Skip to content

Commit

Permalink
rg16f motion vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 22, 2023
1 parent bef985d commit 9297d8d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions data/pipelines/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,7 @@ float rand(vec3 seed)
vec2 computeStaticObjectMotionVector(vec3 wpos) {
vec4 p = Global.view_projection_no_jitter * vec4(wpos, 1);
vec4 pos_projected = Global.prev_view_projection_no_jitter * vec4(wpos + Global.to_prev_frame_camera_translation.xyz, 1);
vec2 r = (pos_projected.xy / pos_projected.w * 0.5 + 0.5 - (p.xy / p.w * 0.5 + 0.5));
r = r * 0.5 + 0.5;
return r;
return pos_projected.xy / pos_projected.w - p.xy / p.w;
}

vec2 cameraReproject(vec2 uv, float depth) {
Expand Down
2 changes: 1 addition & 1 deletion data/pipelines/field_debug.shd
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fragment_shader [[

void main() {
vec2 uv = toScreenUV(v_uv);
vec4 t = textureLod(u_texture, uv, 0) * 2 - 1;
vec4 t = textureLod(u_texture, uv, 0);
float tt = arrow(gl_FragCoord.xy, (t.xy) * 10000);

o_color = vec4(t.rg * 100, 1 - tt, 1);
Expand Down
6 changes: 4 additions & 2 deletions data/pipelines/main.pln
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type GBuffer = {
local gbuffer_A_desc = createRenderbufferDesc { format = "srgba", debug_name = "gbuffer.A" }
local gbuffer_B_desc = createRenderbufferDesc { compute_write = true, format = "rgba16", debug_name = "gbuffer.B" }
local gbuffer_C_desc = createRenderbufferDesc { compute_write = true, format = "rgba8", debug_name = "gbuffer.C" }
local gbuffer_D_desc = createRenderbufferDesc { compute_write = true, format = "rg16", debug_name = "gbuffer.D" }
local gbuffer_D_desc = createRenderbufferDesc { compute_write = true, format = "rg16f", debug_name = "gbuffer.D" }
local gbuffer_DS_desc = createRenderbufferDesc { format = "depth24stencil8", debug_name = "gbuffer_ds" }

local function createGBuffer() : GBuffer
Expand Down Expand Up @@ -201,7 +201,9 @@ end
local function geomPass(view_params : CameraParams, entities) : GBuffer
beginBlock("geom_pass")
local gbuffer = createGBuffer()

setRenderTargets(gbuffer.D)
clear(CLEAR_ALL, 0.0, 0.0, 0.0, 1, 0)

setRenderTargetsDS(gbuffer.A, gbuffer.B, gbuffer.C, gbuffer.D, gbuffer.DS)
clear(CLEAR_ALL, 0.0, 0.0, 0.0, 1, 0)
pass(view_params)
Expand Down
2 changes: 1 addition & 1 deletion data/pipelines/surface_base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function surface_shader_ex(args)
vec4 p = Global.view_projection_no_jitter * v_wpos;
#if defined DYNAMIC || defined SKINNED
vec2 prev_pos_projected = v_prev_ndcpos_no_jitter.xy / v_prev_ndcpos_no_jitter.w;
data.motion = (prev_pos_projected.xy * 0.5 + 0.5 - (p.xy / p.w * 0.5 + 0.5)) * 0.5 + 0.5;
data.motion = prev_pos_projected.xy - p.xy / p.w;
#else
data.motion = computeStaticObjectMotionVector(v_wpos.xyz);
#endif
Expand Down
7 changes: 6 additions & 1 deletion data/pipelines/taa.shd
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ compute_shader [[
if (any(greaterThanEqual(ij, ivec2(u_size.xy)))) return;

vec2 uv = (vec2(ij) + 0.5) / u_size.xy;
vec2 motionvec = toScreenUV(textureLod(u_motion_vectors, uv, 0).xy) * 2 - 1;
vec2 motionvec = textureLod(u_motion_vectors, uv, 0).xy;
#ifdef _ORIGIN_BOTTOM_LEFT
motionvec *= vec2(0.5);
#else
motionvec *= vec2(0.5, -0.5);
#endif

vec2 uv_prev = uv + motionvec;

Expand Down
3 changes: 1 addition & 2 deletions data/pipelines/textured_quad.shd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ vertex_shader [[
void main() {
vec4 pos = fullscreenQuad(gl_VertexID, v_uv);
pos.xy = pos.xy * u_offset_scale.zw + u_offset_scale.xy;
pos.y = -pos.y;
gl_Position = pos;
}
]]
Expand All @@ -27,7 +26,7 @@ fragment_shader [[
layout (location = 0) in vec2 v_uv;
layout (location = 0) out vec4 o_color;
void main() {
vec4 t = textureLod(u_texture, toScreenUV(v_uv), 0);
vec4 t = textureLod(u_texture, v_uv, 0);
o_color.r = dot(t, u_r_mask) + u_offsets.r;
o_color.g = dot(t, u_g_mask) + u_offsets.g;
o_color.b = dot(t, u_b_mask) + u_offsets.b;
Expand Down

0 comments on commit 9297d8d

Please sign in to comment.