Merge pull request #37819 from reduz/implement-fxaa
Add screen space AA option, with FXAA implementation.
This commit is contained in:
commit
d160644c88
|
@ -2480,6 +2480,8 @@ void Node3DEditorViewport::_notification(int p_what) {
|
||||||
|
|
||||||
int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/filters/msaa");
|
int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/filters/msaa");
|
||||||
viewport->set_msaa(Viewport::MSAA(msaa_mode));
|
viewport->set_msaa(Viewport::MSAA(msaa_mode));
|
||||||
|
int ssaa_mode = GLOBAL_GET("rendering/quality/filters/screen_space_aa");
|
||||||
|
viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode));
|
||||||
|
|
||||||
bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION));
|
bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION));
|
||||||
if (show_info != info_label->is_visible()) {
|
if (show_info != info_label->is_visible()) {
|
||||||
|
|
|
@ -1425,6 +1425,10 @@ SceneTree::SceneTree() {
|
||||||
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"));
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"));
|
||||||
root->set_msaa(Viewport::MSAA(msaa_mode));
|
root->set_msaa(Viewport::MSAA(msaa_mode));
|
||||||
|
|
||||||
|
int ssaa_mode = GLOBAL_DEF("rendering/quality/filters/screen_space_aa", 0);
|
||||||
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/screen_space_aa", PropertyInfo(Variant::INT, "rendering/quality/filters/screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA"));
|
||||||
|
root->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode));
|
||||||
|
|
||||||
{ //load default fallback environment
|
{ //load default fallback environment
|
||||||
//get possible extensions
|
//get possible extensions
|
||||||
List<String> exts;
|
List<String> exts;
|
||||||
|
|
|
@ -3173,7 +3173,7 @@ int Viewport::gui_get_canvas_sort_index() {
|
||||||
|
|
||||||
void Viewport::set_msaa(MSAA p_msaa) {
|
void Viewport::set_msaa(MSAA p_msaa) {
|
||||||
|
|
||||||
ERR_FAIL_INDEX(p_msaa, 7);
|
ERR_FAIL_INDEX(p_msaa, MSAA_MAX);
|
||||||
if (msaa == p_msaa)
|
if (msaa == p_msaa)
|
||||||
return;
|
return;
|
||||||
msaa = p_msaa;
|
msaa = p_msaa;
|
||||||
|
@ -3185,6 +3185,19 @@ Viewport::MSAA Viewport::get_msaa() const {
|
||||||
return msaa;
|
return msaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewport::set_screen_space_aa(ScreenSpaceAA p_screen_space_aa) {
|
||||||
|
|
||||||
|
ERR_FAIL_INDEX(p_screen_space_aa, SCREEN_SPACE_AA_MAX);
|
||||||
|
if (screen_space_aa == p_screen_space_aa)
|
||||||
|
return;
|
||||||
|
screen_space_aa = p_screen_space_aa;
|
||||||
|
RS::get_singleton()->viewport_set_screen_space_aa(viewport, RS::ViewportScreenSpaceAA(p_screen_space_aa));
|
||||||
|
}
|
||||||
|
|
||||||
|
Viewport::ScreenSpaceAA Viewport::get_screen_space_aa() const {
|
||||||
|
|
||||||
|
return screen_space_aa;
|
||||||
|
}
|
||||||
void Viewport::set_debug_draw(DebugDraw p_debug_draw) {
|
void Viewport::set_debug_draw(DebugDraw p_debug_draw) {
|
||||||
|
|
||||||
debug_draw = p_debug_draw;
|
debug_draw = p_debug_draw;
|
||||||
|
@ -3371,6 +3384,9 @@ void Viewport::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa);
|
ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa);
|
||||||
ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa);
|
ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_screen_space_aa", "screen_space_aa"), &Viewport::set_screen_space_aa);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_screen_space_aa"), &Viewport::get_screen_space_aa);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw);
|
ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw);
|
||||||
ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw);
|
ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw);
|
||||||
|
|
||||||
|
@ -3444,6 +3460,7 @@ void Viewport::_bind_methods() {
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally");
|
||||||
ADD_GROUP("Rendering", "");
|
ADD_GROUP("Rendering", "");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA"), "set_screen_space_aa", "get_screen_space_aa");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw");
|
||||||
ADD_GROUP("Canvas Items", "canvas_item_");
|
ADD_GROUP("Canvas Items", "canvas_item_");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,MipmapLinear,MipmapNearest"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,MipmapLinear,MipmapNearest"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter");
|
||||||
|
@ -3586,7 +3603,7 @@ Viewport::Viewport() {
|
||||||
gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
|
gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
|
||||||
|
|
||||||
msaa = MSAA_DISABLED;
|
msaa = MSAA_DISABLED;
|
||||||
|
screen_space_aa = SCREEN_SPACE_AA_DISABLED;
|
||||||
debug_draw = DEBUG_DRAW_DISABLED;
|
debug_draw = DEBUG_DRAW_DISABLED;
|
||||||
|
|
||||||
snap_controls_to_pixels = true;
|
snap_controls_to_pixels = true;
|
||||||
|
|
|
@ -106,6 +106,13 @@ public:
|
||||||
MSAA_4X,
|
MSAA_4X,
|
||||||
MSAA_8X,
|
MSAA_8X,
|
||||||
MSAA_16X,
|
MSAA_16X,
|
||||||
|
MSAA_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ScreenSpaceAA {
|
||||||
|
SCREEN_SPACE_AA_DISABLED,
|
||||||
|
SCREEN_SPACE_AA_FXAA,
|
||||||
|
SCREEN_SPACE_AA_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RenderInfo {
|
enum RenderInfo {
|
||||||
|
@ -272,6 +279,7 @@ private:
|
||||||
ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4];
|
ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4];
|
||||||
|
|
||||||
MSAA msaa;
|
MSAA msaa;
|
||||||
|
ScreenSpaceAA screen_space_aa;
|
||||||
Ref<ViewportTexture> default_texture;
|
Ref<ViewportTexture> default_texture;
|
||||||
Set<ViewportTexture *> viewport_textures;
|
Set<ViewportTexture *> viewport_textures;
|
||||||
|
|
||||||
|
@ -505,6 +513,9 @@ public:
|
||||||
void set_msaa(MSAA p_msaa);
|
void set_msaa(MSAA p_msaa);
|
||||||
MSAA get_msaa() const;
|
MSAA get_msaa() const;
|
||||||
|
|
||||||
|
void set_screen_space_aa(ScreenSpaceAA p_screen_space_aa);
|
||||||
|
ScreenSpaceAA get_screen_space_aa() const;
|
||||||
|
|
||||||
Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const;
|
Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const;
|
||||||
Vector2 get_camera_rect_size() const;
|
Vector2 get_camera_rect_size() const;
|
||||||
|
|
||||||
|
@ -624,6 +635,7 @@ public:
|
||||||
VARIANT_ENUM_CAST(SubViewport::UpdateMode);
|
VARIANT_ENUM_CAST(SubViewport::UpdateMode);
|
||||||
VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv);
|
VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv);
|
||||||
VARIANT_ENUM_CAST(Viewport::MSAA);
|
VARIANT_ENUM_CAST(Viewport::MSAA);
|
||||||
|
VARIANT_ENUM_CAST(Viewport::ScreenSpaceAA);
|
||||||
VARIANT_ENUM_CAST(Viewport::DebugDraw);
|
VARIANT_ENUM_CAST(Viewport::DebugDraw);
|
||||||
VARIANT_ENUM_CAST(SubViewport::ClearMode);
|
VARIANT_ENUM_CAST(SubViewport::ClearMode);
|
||||||
VARIANT_ENUM_CAST(Viewport::RenderInfo);
|
VARIANT_ENUM_CAST(Viewport::RenderInfo);
|
||||||
|
|
|
@ -263,7 +263,7 @@ public:
|
||||||
virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) = 0;
|
virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) = 0;
|
||||||
|
|
||||||
virtual RID render_buffers_create() = 0;
|
virtual RID render_buffers_create() = 0;
|
||||||
virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa) = 0;
|
virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa) = 0;
|
||||||
|
|
||||||
virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) = 0;
|
virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) = 0;
|
||||||
virtual bool screen_space_roughness_limiter_is_active() const = 0;
|
virtual bool screen_space_roughness_limiter_is_active() const = 0;
|
||||||
|
|
|
@ -676,6 +676,10 @@ void RasterizerEffectsRD::tonemapper(RID p_source_color, RID p_dst_framebuffer,
|
||||||
|
|
||||||
tonemap.push_constant.use_color_correction = p_settings.use_color_correction;
|
tonemap.push_constant.use_color_correction = p_settings.use_color_correction;
|
||||||
|
|
||||||
|
tonemap.push_constant.use_fxaa = p_settings.use_fxaa;
|
||||||
|
tonemap.push_constant.pixel_size[0] = 1.0 / p_settings.texture_size.x;
|
||||||
|
tonemap.push_constant.pixel_size[1] = 1.0 / p_settings.texture_size.y;
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD);
|
||||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, tonemap.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_framebuffer)));
|
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, tonemap.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_framebuffer)));
|
||||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_color), 0);
|
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_color), 0);
|
||||||
|
|
|
@ -170,6 +170,10 @@ class RasterizerEffectsRD {
|
||||||
float exposure;
|
float exposure;
|
||||||
float white;
|
float white;
|
||||||
float auto_exposure_grey;
|
float auto_exposure_grey;
|
||||||
|
|
||||||
|
float pixel_size[2];
|
||||||
|
uint32_t use_fxaa;
|
||||||
|
uint32_t pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* tonemap actually writes to a framebuffer, which is
|
/* tonemap actually writes to a framebuffer, which is
|
||||||
|
@ -595,6 +599,9 @@ public:
|
||||||
|
|
||||||
bool use_color_correction = false;
|
bool use_color_correction = false;
|
||||||
RID color_correction_texture;
|
RID color_correction_texture;
|
||||||
|
|
||||||
|
bool use_fxaa = false;
|
||||||
|
Vector2i texture_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
|
void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
|
||||||
|
|
|
@ -3439,6 +3439,12 @@ void RasterizerSceneRD::_render_buffers_post_process_and_tonemap(RID p_render_bu
|
||||||
tonemap.glow_texture = storage->texture_rd_get_default(RasterizerStorageRD::DEFAULT_RD_TEXTURE_BLACK);
|
tonemap.glow_texture = storage->texture_rd_get_default(RasterizerStorageRD::DEFAULT_RD_TEXTURE_BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rb->screen_space_aa == RS::VIEWPORT_SCREEN_SPACE_AA_FXAA) {
|
||||||
|
tonemap.use_fxaa = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tonemap.texture_size = Vector2i(rb->width, rb->height);
|
||||||
|
|
||||||
if (env) {
|
if (env) {
|
||||||
tonemap.tonemap_mode = env->tone_mapper;
|
tonemap.tonemap_mode = env->tone_mapper;
|
||||||
tonemap.white = env->white;
|
tonemap.white = env->white;
|
||||||
|
@ -3517,13 +3523,14 @@ RID RasterizerSceneRD::render_buffers_get_ao_texture(RID p_render_buffers) {
|
||||||
return rb->ssao.ao_full.is_valid() ? rb->ssao.ao_full : rb->ssao.ao[0];
|
return rb->ssao.ao_full.is_valid() ? rb->ssao.ao_full : rb->ssao.ao[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerSceneRD::render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa) {
|
void RasterizerSceneRD::render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa) {
|
||||||
|
|
||||||
RenderBuffers *rb = render_buffers_owner.getornull(p_render_buffers);
|
RenderBuffers *rb = render_buffers_owner.getornull(p_render_buffers);
|
||||||
rb->width = p_width;
|
rb->width = p_width;
|
||||||
rb->height = p_height;
|
rb->height = p_height;
|
||||||
rb->render_target = p_render_target;
|
rb->render_target = p_render_target;
|
||||||
rb->msaa = p_msaa;
|
rb->msaa = p_msaa;
|
||||||
|
rb->screen_space_aa = p_screen_space_aa;
|
||||||
_free_render_buffer_data(rb);
|
_free_render_buffer_data(rb);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -716,6 +716,8 @@ private:
|
||||||
RenderBufferData *data = nullptr;
|
RenderBufferData *data = nullptr;
|
||||||
int width = 0, height = 0;
|
int width = 0, height = 0;
|
||||||
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
|
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
|
||||||
|
RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
|
||||||
|
|
||||||
RID render_target;
|
RID render_target;
|
||||||
|
|
||||||
uint64_t auto_exposure_version = 1;
|
uint64_t auto_exposure_version = 1;
|
||||||
|
@ -1149,7 +1151,7 @@ public:
|
||||||
GIProbeQuality gi_probe_get_quality() const;
|
GIProbeQuality gi_probe_get_quality() const;
|
||||||
|
|
||||||
RID render_buffers_create();
|
RID render_buffers_create();
|
||||||
void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa);
|
void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa);
|
||||||
|
|
||||||
RID render_buffers_get_ao_texture(RID p_render_buffers);
|
RID render_buffers_get_ao_texture(RID p_render_buffers);
|
||||||
RID render_buffers_get_back_buffer_texture(RID p_render_buffers);
|
RID render_buffers_get_back_buffer_texture(RID p_render_buffers);
|
||||||
|
|
|
@ -48,6 +48,10 @@ layout(push_constant, binding = 1, std430) uniform Params {
|
||||||
float exposure;
|
float exposure;
|
||||||
float white;
|
float white;
|
||||||
float auto_exposure_grey;
|
float auto_exposure_grey;
|
||||||
|
|
||||||
|
vec2 pixel_size;
|
||||||
|
bool use_fxaa;
|
||||||
|
uint pad;
|
||||||
}
|
}
|
||||||
params;
|
params;
|
||||||
|
|
||||||
|
@ -255,16 +259,63 @@ vec3 apply_color_correction(vec3 color, sampler3D correction_tex) {
|
||||||
return texture(correction_tex, color).rgb;
|
return texture(correction_tex, color).rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 do_fxaa(vec3 color, float exposure, vec2 uv_interp) {
|
||||||
|
|
||||||
|
const float FXAA_REDUCE_MIN = (1.0 / 128.0);
|
||||||
|
const float FXAA_REDUCE_MUL = (1.0 / 8.0);
|
||||||
|
const float FXAA_SPAN_MAX = 8.0;
|
||||||
|
|
||||||
|
vec3 rgbNW = textureLod(source_color, uv_interp + vec2(-1.0, -1.0) * params.pixel_size, 0.0).xyz * exposure;
|
||||||
|
vec3 rgbNE = textureLod(source_color, uv_interp + vec2(1.0, -1.0) * params.pixel_size, 0.0).xyz * exposure;
|
||||||
|
vec3 rgbSW = textureLod(source_color, uv_interp + vec2(-1.0, 1.0) * params.pixel_size, 0.0).xyz * exposure;
|
||||||
|
vec3 rgbSE = textureLod(source_color, uv_interp + vec2(1.0, 1.0) * params.pixel_size, 0.0).xyz * exposure;
|
||||||
|
vec3 rgbM = color;
|
||||||
|
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||||
|
float lumaNW = dot(rgbNW, luma);
|
||||||
|
float lumaNE = dot(rgbNE, luma);
|
||||||
|
float lumaSW = dot(rgbSW, luma);
|
||||||
|
float lumaSE = dot(rgbSE, luma);
|
||||||
|
float lumaM = dot(rgbM, luma);
|
||||||
|
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
||||||
|
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
||||||
|
|
||||||
|
vec2 dir;
|
||||||
|
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||||||
|
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||||||
|
|
||||||
|
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
|
||||||
|
(0.25 * FXAA_REDUCE_MUL),
|
||||||
|
FXAA_REDUCE_MIN);
|
||||||
|
|
||||||
|
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||||
|
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
||||||
|
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
||||||
|
dir * rcpDirMin)) *
|
||||||
|
params.pixel_size;
|
||||||
|
|
||||||
|
vec3 rgbA = 0.5 * (textureLod(source_color, uv_interp + dir * (1.0 / 3.0 - 0.5), 0.0).xyz * exposure + textureLod(source_color, uv_interp + dir * (2.0 / 3.0 - 0.5), 0.0).xyz) * exposure;
|
||||||
|
vec3 rgbB = rgbA * 0.5 + 0.25 * (textureLod(source_color, uv_interp + dir * -0.5, 0.0).xyz * exposure +
|
||||||
|
textureLod(source_color, uv_interp + dir * 0.5, 0.0).xyz * exposure);
|
||||||
|
|
||||||
|
float lumaB = dot(rgbB, luma);
|
||||||
|
if ((lumaB < lumaMin) || (lumaB > lumaMax))
|
||||||
|
return rgbA;
|
||||||
|
else
|
||||||
|
return rgbB;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color = textureLod(source_color, uv_interp, 0.0f).rgb;
|
vec3 color = textureLod(source_color, uv_interp, 0.0f).rgb;
|
||||||
|
|
||||||
// Exposure
|
// Exposure
|
||||||
|
|
||||||
|
float exposure = params.exposure;
|
||||||
|
|
||||||
if (params.use_auto_exposure) {
|
if (params.use_auto_exposure) {
|
||||||
color /= texelFetch(source_auto_exposure, ivec2(0, 0), 0).r / params.auto_exposure_grey;
|
exposure *= 1.0 / (texelFetch(source_auto_exposure, ivec2(0, 0), 0).r / params.auto_exposure_grey);
|
||||||
}
|
}
|
||||||
|
|
||||||
color *= params.exposure;
|
color *= exposure;
|
||||||
|
|
||||||
// Early Tonemap & SRGB Conversion
|
// Early Tonemap & SRGB Conversion
|
||||||
|
|
||||||
|
@ -274,6 +325,9 @@ void main() {
|
||||||
color.rgb = mix(color.rgb, glow, params.glow_intensity);
|
color.rgb = mix(color.rgb, glow, params.glow_intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.use_fxaa) {
|
||||||
|
color = do_fxaa(color, exposure, uv_interp);
|
||||||
|
}
|
||||||
color = apply_tonemapping(color, params.white);
|
color = apply_tonemapping(color, params.white);
|
||||||
|
|
||||||
color = linear_to_srgb(color); // regular linear -> SRGB conversion
|
color = linear_to_srgb(color); // regular linear -> SRGB conversion
|
||||||
|
|
|
@ -489,6 +489,7 @@ public:
|
||||||
BIND2(viewport_set_shadow_atlas_size, RID, int)
|
BIND2(viewport_set_shadow_atlas_size, RID, int)
|
||||||
BIND3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int)
|
BIND3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int)
|
||||||
BIND2(viewport_set_msaa, RID, ViewportMSAA)
|
BIND2(viewport_set_msaa, RID, ViewportMSAA)
|
||||||
|
BIND2(viewport_set_screen_space_aa, RID, ViewportScreenSpaceAA)
|
||||||
|
|
||||||
BIND2R(int, viewport_get_render_info, RID, ViewportRenderInfo)
|
BIND2R(int, viewport_get_render_info, RID, ViewportRenderInfo)
|
||||||
BIND2(viewport_set_debug_draw, RID, ViewportDebugDraw)
|
BIND2(viewport_set_debug_draw, RID, ViewportDebugDraw)
|
||||||
|
|
|
@ -119,7 +119,7 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, XRInterface::
|
||||||
if ((scenario_draw_canvas_bg || can_draw_3d) && !p_viewport->render_buffers.is_valid()) {
|
if ((scenario_draw_canvas_bg || can_draw_3d) && !p_viewport->render_buffers.is_valid()) {
|
||||||
//wants to draw 3D but there is no render buffer, create
|
//wants to draw 3D but there is no render buffer, create
|
||||||
p_viewport->render_buffers = RSG::scene_render->render_buffers_create();
|
p_viewport->render_buffers = RSG::scene_render->render_buffers_create();
|
||||||
RSG::scene_render->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, p_viewport->size.width, p_viewport->size.height, p_viewport->msaa);
|
RSG::scene_render->render_buffers_configure(p_viewport->render_buffers, p_viewport->render_target, p_viewport->size.width, p_viewport->size.height, p_viewport->msaa, p_viewport->screen_space_aa);
|
||||||
}
|
}
|
||||||
|
|
||||||
RSG::storage->render_target_request_clear(p_viewport->render_target, bgcolor);
|
RSG::storage->render_target_request_clear(p_viewport->render_target, bgcolor);
|
||||||
|
@ -506,7 +506,7 @@ void RenderingServerViewport::viewport_set_size(RID p_viewport, int p_width, int
|
||||||
RSG::scene_render->free(viewport->render_buffers);
|
RSG::scene_render->free(viewport->render_buffers);
|
||||||
viewport->render_buffers = RID();
|
viewport->render_buffers = RID();
|
||||||
} else {
|
} else {
|
||||||
RSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, viewport->msaa);
|
RSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, viewport->msaa, viewport->screen_space_aa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,7 +736,20 @@ void RenderingServerViewport::viewport_set_msaa(RID p_viewport, RS::ViewportMSAA
|
||||||
}
|
}
|
||||||
viewport->msaa = p_msaa;
|
viewport->msaa = p_msaa;
|
||||||
if (viewport->render_buffers.is_valid()) {
|
if (viewport->render_buffers.is_valid()) {
|
||||||
RSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, p_msaa);
|
RSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, p_msaa, viewport->screen_space_aa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderingServerViewport::viewport_set_screen_space_aa(RID p_viewport, RS::ViewportScreenSpaceAA p_mode) {
|
||||||
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
||||||
|
ERR_FAIL_COND(!viewport);
|
||||||
|
|
||||||
|
if (viewport->screen_space_aa == p_mode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
viewport->screen_space_aa = p_mode;
|
||||||
|
if (viewport->render_buffers.is_valid()) {
|
||||||
|
RSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, viewport->msaa, p_mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ public:
|
||||||
RID render_buffers;
|
RID render_buffers;
|
||||||
|
|
||||||
RS::ViewportMSAA msaa;
|
RS::ViewportMSAA msaa;
|
||||||
|
RS::ViewportScreenSpaceAA screen_space_aa;
|
||||||
|
|
||||||
DisplayServer::WindowID viewport_to_screen;
|
DisplayServer::WindowID viewport_to_screen;
|
||||||
Rect2 viewport_to_screen_rect;
|
Rect2 viewport_to_screen_rect;
|
||||||
|
@ -130,6 +131,8 @@ public:
|
||||||
|
|
||||||
debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
|
debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
|
||||||
msaa = RS::VIEWPORT_MSAA_DISABLED;
|
msaa = RS::VIEWPORT_MSAA_DISABLED;
|
||||||
|
screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
|
||||||
|
|
||||||
for (int i = 0; i < RS::VIEWPORT_RENDER_INFO_MAX; i++) {
|
for (int i = 0; i < RS::VIEWPORT_RENDER_INFO_MAX; i++) {
|
||||||
render_info[i] = 0;
|
render_info[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -206,6 +209,7 @@ public:
|
||||||
void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv);
|
void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv);
|
||||||
|
|
||||||
void viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa);
|
void viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa);
|
||||||
|
void viewport_set_screen_space_aa(RID p_viewport, RS::ViewportScreenSpaceAA p_mode);
|
||||||
|
|
||||||
virtual int viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info);
|
virtual int viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info);
|
||||||
virtual void viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw);
|
virtual void viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw);
|
||||||
|
|
|
@ -403,6 +403,7 @@ public:
|
||||||
FUNC2(viewport_set_shadow_atlas_size, RID, int)
|
FUNC2(viewport_set_shadow_atlas_size, RID, int)
|
||||||
FUNC3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int)
|
FUNC3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int)
|
||||||
FUNC2(viewport_set_msaa, RID, ViewportMSAA)
|
FUNC2(viewport_set_msaa, RID, ViewportMSAA)
|
||||||
|
FUNC2(viewport_set_screen_space_aa, RID, ViewportScreenSpaceAA)
|
||||||
|
|
||||||
//this passes directly to avoid stalling, but it's pretty dangerous, so don't call after freeing a viewport
|
//this passes directly to avoid stalling, but it's pretty dangerous, so don't call after freeing a viewport
|
||||||
virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfo p_info) {
|
virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfo p_info) {
|
||||||
|
|
|
@ -639,6 +639,12 @@ public:
|
||||||
|
|
||||||
virtual void viewport_set_msaa(RID p_viewport, ViewportMSAA p_msaa) = 0;
|
virtual void viewport_set_msaa(RID p_viewport, ViewportMSAA p_msaa) = 0;
|
||||||
|
|
||||||
|
enum ViewportScreenSpaceAA {
|
||||||
|
VIEWPORT_SCREEN_SPACE_AA_DISABLED,
|
||||||
|
VIEWPORT_SCREEN_SPACE_AA_FXAA,
|
||||||
|
};
|
||||||
|
virtual void viewport_set_screen_space_aa(RID p_viewport, ViewportScreenSpaceAA p_mode) = 0;
|
||||||
|
|
||||||
enum ViewportRenderInfo {
|
enum ViewportRenderInfo {
|
||||||
|
|
||||||
VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME,
|
VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME,
|
||||||
|
|
Loading…
Reference in New Issue