You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Improve visual feedback when using the motion vectors debug view option.
Replaces the current method of showing the raw values of the motion vectors buffer to display a grid of lines instead with a new shader.
This commit is contained in:
@@ -51,6 +51,17 @@ DebugEffects::DebugEffects() {
|
||||
raster_state.wireframe = true;
|
||||
shadow_frustum.pipelines[SFP_WIREFRAME].setup(shadow_frustum.shader.version_get_shader(shadow_frustum.shader_version, 0), RD::RENDER_PRIMITIVE_LINES, raster_state, RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
// Motion Vectors debug shader.
|
||||
Vector<String> modes;
|
||||
modes.push_back("");
|
||||
|
||||
motion_vectors.shader.initialize(modes);
|
||||
motion_vectors.shader_version = motion_vectors.shader.version_create();
|
||||
|
||||
motion_vectors.pipeline.setup(motion_vectors.shader.version_get_shader(motion_vectors.shader_version, 0), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_blend(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugEffects::_create_frustum_arrays() {
|
||||
@@ -163,6 +174,8 @@ DebugEffects::~DebugEffects() {
|
||||
if (frustum.lines_buffer.is_valid()) {
|
||||
RD::get_singleton()->free(frustum.lines_buffer); // Array gets freed as dependency.
|
||||
}
|
||||
|
||||
motion_vectors.shader.version_free(motion_vectors.shader_version);
|
||||
}
|
||||
|
||||
void DebugEffects::draw_shadow_frustum(RID p_light, const Projection &p_cam_projection, const Transform3D &p_cam_transform, RID p_dest_fb, const Rect2 p_rect) {
|
||||
@@ -326,3 +339,26 @@ void DebugEffects::draw_shadow_frustum(RID p_light, const Projection &p_cam_proj
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebugEffects::draw_motion_vectors(RID p_velocity, RID p_dest_fb, Size2i p_velocity_size) {
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
|
||||
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
RD::Uniform u_source_velocity(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_velocity }));
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, motion_vectors.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_fb), false, RD::get_singleton()->draw_list_get_current_pass()));
|
||||
|
||||
motion_vectors.push_constant.velocity_resolution[0] = p_velocity_size.width;
|
||||
motion_vectors.push_constant.velocity_resolution[1] = p_velocity_size.height;
|
||||
|
||||
RID shader = motion_vectors.shader.version_get_shader(motion_vectors.shader_version, 0);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_velocity), 0);
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &motion_vectors.push_constant, sizeof(MotionVectorsPushConstant));
|
||||
RD::get_singleton()->draw_list_draw(draw_list, false, 1u, 3u);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#define DEBUG_EFFECTS_RD_H
|
||||
|
||||
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/motion_vectors.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/shadow_frustum.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
|
||||
@@ -70,6 +71,18 @@ private:
|
||||
PipelineCacheRD pipelines[SFP_MAX];
|
||||
} shadow_frustum;
|
||||
|
||||
struct MotionVectorsPushConstant {
|
||||
float velocity_resolution[2];
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct {
|
||||
MotionVectorsShaderRD shader;
|
||||
RID shader_version;
|
||||
PipelineCacheRD pipeline;
|
||||
MotionVectorsPushConstant push_constant;
|
||||
} motion_vectors;
|
||||
|
||||
void _create_frustum_arrays();
|
||||
|
||||
protected:
|
||||
@@ -78,6 +91,7 @@ public:
|
||||
~DebugEffects();
|
||||
|
||||
void draw_shadow_frustum(RID p_light, const Projection &p_cam_projection, const Transform3D &p_cam_transform, RID p_dest_fb, const Rect2 p_rect);
|
||||
void draw_motion_vectors(RID p_velocity, RID p_dest_fb, Size2i p_velocity_size);
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
||||
Reference in New Issue
Block a user