Merge pull request #46657 from lawnjelly/revert_snapping

Revert backport of 2D transform and camera snapping options
This commit is contained in:
Rémi Verschelde 2021-03-08 14:49:41 +01:00 committed by GitHub
commit 118567ca28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 4 additions and 37 deletions

View file

@ -228,7 +228,6 @@ Engine::Engine() {
_target_fps = 0; _target_fps = 0;
_time_scale = 1.0; _time_scale = 1.0;
_gpu_pixel_snap = false; _gpu_pixel_snap = false;
_snap_2d_transforms = false;
_physics_frames = 0; _physics_frames = 0;
_idle_frames = 0; _idle_frames = 0;
_in_physics = false; _in_physics = false;

View file

@ -59,8 +59,6 @@ private:
int _target_fps; int _target_fps;
float _time_scale; float _time_scale;
bool _gpu_pixel_snap; bool _gpu_pixel_snap;
bool _snap_2d_transforms;
bool _snap_2d_viewports;
uint64_t _physics_frames; uint64_t _physics_frames;
float _physics_interpolation_fraction; float _physics_interpolation_fraction;
@ -109,8 +107,6 @@ public:
Object *get_singleton_object(const String &p_name) const; Object *get_singleton_object(const String &p_name) const;
_FORCE_INLINE_ bool get_use_gpu_pixel_snap() const { return _gpu_pixel_snap; } _FORCE_INLINE_ bool get_use_gpu_pixel_snap() const { return _gpu_pixel_snap; }
bool get_snap_2d_transforms() const { return _snap_2d_transforms; }
bool get_snap_2d_viewports() const { return _snap_2d_viewports; }
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; } _FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }

View file

@ -1046,19 +1046,11 @@
Currently only available when [member rendering/batching/options/use_batching] is active. Currently only available when [member rendering/batching/options/use_batching] is active.
[b]Note:[/b] Antialiased software skinned polys are not supported, and will be rendered without antialiasing. [b]Note:[/b] Antialiased software skinned polys are not supported, and will be rendered without antialiasing.
</member> </member>
<member name="rendering/2d/snapping/use_camera_snap" type="bool" setter="" getter="" default="false">
If [code]true[/code], forces snapping of 2D viewports to the nearest whole coordinate.
Can reduce unwanted camera relative movement in pixel art styles.
</member>
<member name="rendering/2d/snapping/use_gpu_pixel_snap" type="bool" setter="" getter="" default="false"> <member name="rendering/2d/snapping/use_gpu_pixel_snap" type="bool" setter="" getter="" default="false">
If [code]true[/code], forces snapping of vertices to pixels in 2D rendering. May help in some pixel art styles. If [code]true[/code], forces snapping of vertices to pixels in 2D rendering. May help in some pixel art styles.
This snapping is performed on the GPU in the vertex shader. This snapping is performed on the GPU in the vertex shader.
Consider using the project setting [member rendering/batching/precision/uv_contract] to prevent artifacts. Consider using the project setting [member rendering/batching/precision/uv_contract] to prevent artifacts.
</member> </member>
<member name="rendering/2d/snapping/use_transform_snap" type="bool" setter="" getter="" default="false">
If [code]true[/code], forces snapping of 2D object transforms to the nearest whole coordinate.
Can help prevent unwanted relative movement in pixel art styles.
</member>
<member name="rendering/batching/debug/diagnose_frame" type="bool" setter="" getter="" default="false"> <member name="rendering/batching/debug/diagnose_frame" type="bool" setter="" getter="" default="false">
When batching is on, this regularly prints a frame diagnosis log. Note that this will degrade performance. When batching is on, this regularly prints a frame diagnosis log. Note that this will degrade performance.
</member> </member>

View file

@ -1127,8 +1127,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} }
Engine::get_singleton()->_gpu_pixel_snap = GLOBAL_DEF("rendering/2d/snapping/use_gpu_pixel_snap", false); Engine::get_singleton()->_gpu_pixel_snap = GLOBAL_DEF("rendering/2d/snapping/use_gpu_pixel_snap", false);
Engine::get_singleton()->_snap_2d_transforms = GLOBAL_DEF("rendering/2d/snapping/use_transform_snap", false);
Engine::get_singleton()->_snap_2d_viewports = GLOBAL_DEF("rendering/2d/snapping/use_camera_snap", false);
OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true); OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
if (rtm == -1) { if (rtm == -1) {
rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE); rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE);

View file

@ -452,9 +452,7 @@ void AnimatedSprite::_notification(int p_what) {
if (centered) if (centered)
ofs -= s / 2; ofs -= s / 2;
if (Engine::get_singleton()->get_snap_2d_transforms()) { if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
ofs = ofs.floor(); ofs = ofs.floor();
} }
Rect2 dst_rect(ofs, s); Rect2 dst_rect(ofs, s);

View file

@ -100,9 +100,7 @@ void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_cli
if (centered) if (centered)
dest_offset -= frame_size / 2; dest_offset -= frame_size / 2;
if (Engine::get_singleton()->get_snap_2d_transforms()) { if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
dest_offset = dest_offset.round();
} else if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
dest_offset = dest_offset.floor(); dest_offset = dest_offset.floor();
} }
@ -381,9 +379,7 @@ Rect2 Sprite::get_rect() const {
Point2 ofs = offset; Point2 ofs = offset;
if (centered) if (centered)
ofs -= Size2(s) / 2; ofs -= Size2(s) / 2;
if (Engine::get_singleton()->get_snap_2d_transforms()) { if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_gpu_pixel_snap()) {
ofs = ofs.floor(); ofs = ofs.floor();
} }

View file

@ -99,9 +99,6 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
Rect2 rect = ci->get_rect(); Rect2 rect = ci->get_rect();
Transform2D xform = ci->xform; Transform2D xform = ci->xform;
if (snap_2d_transforms) {
xform.elements[2] = xform.elements[2].round();
}
xform = p_transform * xform; xform = p_transform * xform;
Rect2 global_rect = xform.xform(rect); Rect2 global_rect = xform.xform(rect);
@ -1484,7 +1481,6 @@ VisualServerCanvas::VisualServerCanvas() {
z_last_list = (RasterizerCanvas::Item **)memalloc(z_range * sizeof(RasterizerCanvas::Item *)); z_last_list = (RasterizerCanvas::Item **)memalloc(z_range * sizeof(RasterizerCanvas::Item *));
disable_scale = false; disable_scale = false;
snap_2d_transforms = Engine::get_singleton()->get_snap_2d_transforms();
} }
VisualServerCanvas::~VisualServerCanvas() { VisualServerCanvas::~VisualServerCanvas() {

View file

@ -158,7 +158,6 @@ public:
RID_Owner<RasterizerCanvas::Light> canvas_light_owner; RID_Owner<RasterizerCanvas::Light> canvas_light_owner;
bool disable_scale; bool disable_scale;
bool snap_2d_transforms;
private: private:
void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights); void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights);

View file

@ -41,22 +41,14 @@ static Transform2D _canvas_get_transform(VisualServerViewport::Viewport *p_viewp
float scale = 1.0; float scale = 1.0;
bool snap = Engine::get_singleton()->get_snap_2d_viewports();
if (p_viewport->canvas_map.has(p_canvas->parent)) { if (p_viewport->canvas_map.has(p_canvas->parent)) {
Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform; Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform; xf = xf * c_xform;
scale = p_canvas->parent_scale; scale = p_canvas->parent_scale;
} }
Transform2D c_xform = p_canvas_data->transform; Transform2D c_xform = p_canvas_data->transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform; xf = xf * c_xform;
if (scale != 1.0 && !VSG::canvas->disable_scale) { if (scale != 1.0 && !VSG::canvas->disable_scale) {