Redot-Engine / redot-engine

Redot Engine – Multi-platform 2D and 3D game engine
https://redotengine.org/
MIT License
4.8k stars 216 forks source link

Add Nearest Neighbor Scaling to 3D Viewport Options #859

Open therabug opened 1 week ago

therabug commented 1 week ago

This PR adds a "nearest neighbor" scaling mode to the 3D viewport, expanding the available scaling options alongside bilinear and FSR. Nearest neighbor scaling offers a simple and efficient way to scale without interpolation, ideal for pixelated or retro-styled visuals. Unlike bilinear or FSR scaling, this method preserves hard edges and pixelation, which can be useful for both performance optimization and specific aesthetic effects.

Changes Made

  1. Added Nearest Option to ViewportScaling3DMode Enum:

    • Introduced a new VIEWPORT_SCALING_3D_MODE_NEAREST option within the RS::ViewportScaling3DMode enum, allowing users to select nearest neighbor scaling for 3D viewports.
  2. Updated _configure_3d_render_buffers to Support Nearest Scaling:

    • Modified the _configure_3d_render_buffers function in renderer_viewport.cpp to support nearest scaling. When the VIEWPORT_SCALING_3D_MODE_NEAREST mode is active, the target render resolution is set based on the desired scale, and the texture storage filter is set to nearest neighbor, applying a non-interpolated scaling approach.
  3. Enabled Nearest Mode Selection in viewport_set_scaling_3d_mode:

    • Updated the viewport_set_scaling_3d_mode function to handle the new nearest scaling mode, allowing users to select it and trigger the appropriate configuration changes through _configure_3d_render_buffers.
  4. Added BIND_ENUM_CONSTANT to viewport.cpp for Nearest Scaling.

  5. Added Nearest Scaling Enum to viewport.h.

Additional Note

This new scaling mode is ideal for projects needing a retro, pixelated aesthetic or seeking optimized performance by reducing the overhead of more complex scaling methods. It provides greater flexibility and control over the appearance and performance of 3D viewport scaling.

therabug commented 1 week ago

I can't find a way to disable bilinear. Nearest now exists but doesn't change anything? There is some "Bilinear overlay (?)" on top that I can't disable.

SkogiB commented 1 week ago

Marked this as a draft until you have it ironed out, just for clarity on our end. Appreciate looking into this

therabug commented 1 week ago

Marked this as a draft until you have it ironed out, just for clarity on our end. Appreciate looking into this

thank you!