From 6f846eb5c5ea86388824479f065e3cd9cbd0440e Mon Sep 17 00:00:00 2001 From: "maxime.chambefort" Date: Sun, 17 Mar 2024 20:44:47 +0100 Subject: [PATCH] Added external camera feed from external plugin on Android --- doc/classes/CameraFeed.xml | 18 +++ doc/classes/RenderingServer.xml | 8 ++ drivers/gles3/effects/feed_effects.cpp | 128 ++++++++++++++++++ drivers/gles3/effects/feed_effects.h | 68 ++++++++++ drivers/gles3/rasterizer_gles3.cpp | 2 + drivers/gles3/rasterizer_gles3.h | 2 + drivers/gles3/rasterizer_scene_gles3.cpp | 32 ++++- drivers/gles3/shaders/SCsub | 1 + drivers/gles3/shaders/feed.glsl | 39 ++++++ scene/resources/environment.cpp | 5 +- servers/camera/camera_feed.cpp | 20 +++ servers/camera/camera_feed.h | 5 +- servers/rendering/renderer_scene_cull.h | 1 + servers/rendering/renderer_scene_render.cpp | 8 ++ servers/rendering/renderer_scene_render.h | 4 +- servers/rendering/rendering_method.h | 1 + servers/rendering/rendering_server_default.h | 4 +- .../rendering/storage/environment_storage.cpp | 12 ++ .../rendering/storage/environment_storage.h | 5 +- servers/rendering_server.cpp | 1 + servers/rendering_server.h | 1 + 21 files changed, 350 insertions(+), 15 deletions(-) create mode 100644 drivers/gles3/effects/feed_effects.cpp create mode 100644 drivers/gles3/effects/feed_effects.h create mode 100644 drivers/gles3/shaders/feed.glsl diff --git a/doc/classes/CameraFeed.xml b/doc/classes/CameraFeed.xml index 2b6db13906c..6748fdb95bd 100644 --- a/doc/classes/CameraFeed.xml +++ b/doc/classes/CameraFeed.xml @@ -34,6 +34,21 @@ Returns the position of camera on the device. + + + + + Returns the texture backend ID (usable by some external libraries that need a handle to a texture to write data). + + + + + + + + Sets the feed as external feed provided by another library. + + @@ -110,6 +125,9 @@ Feed supplies separate Y and CbCr images that need to be combined and converted to RGB. + + Feed supplies external image. + Unspecified position. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index b73315219b6..2e0eb8ae874 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -1278,6 +1278,14 @@ Sets the intensity of the background color. + + + + + + Sets the camera ID to be used as environment background. + + diff --git a/drivers/gles3/effects/feed_effects.cpp b/drivers/gles3/effects/feed_effects.cpp new file mode 100644 index 00000000000..8ca88da6623 --- /dev/null +++ b/drivers/gles3/effects/feed_effects.cpp @@ -0,0 +1,128 @@ +/**************************************************************************/ +/* feed_effects.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifdef GLES3_ENABLED + +#include "feed_effects.h" + +#ifdef ANDROID_ENABLED +#include +#endif + +#define GL_PROGRAM_POINT_SIZE 0x8642 + +using namespace GLES3; + +FeedEffects *FeedEffects::singleton = nullptr; + +FeedEffects *FeedEffects::get_singleton() { + return singleton; +} + +FeedEffects::FeedEffects() { + singleton = this; + + feed.shader.initialize(); + feed.shader_version = feed.shader.version_create(); + feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT); + + { // Screen Triangle. + glGenBuffers(1, &screen_triangle); + glBindBuffer(GL_ARRAY_BUFFER, screen_triangle); + + const float qv[6] = { + -1.0f, + -1.0f, + 3.0f, + -1.0f, + -1.0f, + 3.0f, + }; + + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind + + glGenVertexArrays(1, &screen_triangle_array); + glBindVertexArray(screen_triangle_array); + glBindBuffer(GL_ARRAY_BUFFER, screen_triangle); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind + } +} + +FeedEffects::~FeedEffects() { + singleton = nullptr; + glDeleteBuffers(1, &screen_triangle); + glDeleteVertexArrays(1, &screen_triangle_array); + feed.shader.version_free(feed.shader_version); +} + +Transform3D transform3D_from_mat4(const float *p_mat4) { + Transform3D res; + + res.basis.rows[0][0] = p_mat4[0]; + res.basis.rows[1][0] = p_mat4[1]; + res.basis.rows[2][0] = p_mat4[2]; + // p_mat4[3] = 0; + res.basis.rows[0][1] = p_mat4[4]; + res.basis.rows[1][1] = p_mat4[5]; + res.basis.rows[2][1] = p_mat4[6]; + // p_mat4[7] = 0; + res.basis.rows[0][2] = p_mat4[8]; + res.basis.rows[1][2] = p_mat4[9]; + res.basis.rows[2][2] = p_mat4[10]; + // p_mat4[11] = 0; + res.origin.x = p_mat4[12]; + res.origin.y = p_mat4[13]; + res.origin.z = p_mat4[14]; + // p_mat4[15] = 1; + + return res; +} + +void FeedEffects::draw() { + bool success = feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT, FeedShaderGLES3::USE_EXTERNAL_SAMPLER); + if (!success) { + OS::get_singleton()->print("Godot : FeedShaderGLES3 Could not bind version_bind_shader USE_EXTERNAL_SAMPLER"); + return; + } + + draw_screen_triangle(); +} + +void FeedEffects::draw_screen_triangle() { + glBindVertexArray(screen_triangle_array); + glDrawArrays(GL_TRIANGLES, 0, 3); + glBindVertexArray(0); +} + +#endif // GLES3_ENABLED diff --git a/drivers/gles3/effects/feed_effects.h b/drivers/gles3/effects/feed_effects.h new file mode 100644 index 00000000000..5856a3e04b6 --- /dev/null +++ b/drivers/gles3/effects/feed_effects.h @@ -0,0 +1,68 @@ +/**************************************************************************/ +/* feed_effects.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef FEED_EFFECTS_GLES3_H +#define FEED_EFFECTS_GLES3_H + +#ifdef GLES3_ENABLED + +#include "drivers/gles3/shaders/feed.glsl.gen.h" + +namespace GLES3 { + +class FeedEffects { +private: + struct Feed { + FeedShaderGLES3 shader; + RID shader_version; + } feed; + + static FeedEffects *singleton; + + GLuint screen_triangle = 0; + GLuint screen_triangle_array = 0; + +public: + static FeedEffects *get_singleton(); + + FeedEffects(); + ~FeedEffects(); + + void draw(); + +private: + void draw_screen_triangle(); +}; + +} // namespace GLES3 + +#endif // GLES3_ENABLED + +#endif // FEED_EFFECTS_GLES3_H diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index e79f1db08de..2e01b11b51d 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -213,6 +213,7 @@ void RasterizerGLES3::finalize() { memdelete(glow); memdelete(cubemap_filter); memdelete(copy_effects); + memdelete(feed_effects); memdelete(light_storage); memdelete(particles_storage); memdelete(mesh_storage); @@ -361,6 +362,7 @@ RasterizerGLES3::RasterizerGLES3() { cubemap_filter = memnew(GLES3::CubemapFilter); glow = memnew(GLES3::Glow); post_effects = memnew(GLES3::PostEffects); + feed_effects = memnew(GLES3::FeedEffects); gi = memnew(GLES3::GI); fog = memnew(GLES3::Fog); canvas = memnew(RasterizerCanvasGLES3()); diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h index 92454e014ed..660ec8e8007 100644 --- a/drivers/gles3/rasterizer_gles3.h +++ b/drivers/gles3/rasterizer_gles3.h @@ -35,6 +35,7 @@ #include "effects/copy_effects.h" #include "effects/cubemap_filter.h" +#include "effects/feed_effects.h" #include "effects/glow.h" #include "effects/post_effects.h" #include "environment/fog.h" @@ -74,6 +75,7 @@ protected: GLES3::CubemapFilter *cubemap_filter = nullptr; GLES3::Glow *glow = nullptr; GLES3::PostEffects *post_effects = nullptr; + GLES3::FeedEffects *feed_effects = nullptr; RasterizerCanvasGLES3 *canvas = nullptr; RasterizerSceneGLES3 *scene = nullptr; static RasterizerGLES3 *singleton; diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index c2d17849580..baf8ef1d494 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -31,6 +31,7 @@ #include "rasterizer_scene_gles3.h" #include "drivers/gles3/effects/copy_effects.h" +#include "drivers/gles3/effects/feed_effects.h" #include "rasterizer_gles3.h" #include "storage/config.h" #include "storage/mesh_storage.h" @@ -39,6 +40,8 @@ #include "core/config/project_settings.h" #include "core/templates/sort_array.h" +#include "servers/camera/camera_feed.h" +#include "servers/camera_server.h" #include "servers/rendering/rendering_server_default.h" #include "servers/rendering/rendering_server_globals.h" @@ -2382,7 +2385,9 @@ void RasterizerSceneGLES3::render_scene(const Ref &p_render_ bool draw_sky = false; bool draw_sky_fog_only = false; bool keep_color = false; + bool draw_feed = false; float sky_energy_multiplier = 1.0; + int camera_feed_id = -1; if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { clear_color = Color(0, 0, 0, 1); //in overdraw mode, BG should always be black @@ -2427,6 +2432,8 @@ void RasterizerSceneGLES3::render_scene(const Ref &p_render_ keep_color = true; } break; case RS::ENV_BG_CAMERA_FEED: { + camera_feed_id = environment_get_camera_feed_id(render_data.environment); + draw_feed = true; } break; default: { } @@ -2538,7 +2545,7 @@ void RasterizerSceneGLES3::render_scene(const Ref &p_render_ glClear(GL_DEPTH_BUFFER_BIT); } - if (!keep_color) { + if (!keep_color && !draw_feed) { clear_color.a = render_data.transparent_bg ? 0.0f : 1.0f; glClearBufferfv(GL_COLOR, 0, clear_color.components); } else if (fbo != rt->fbo) { @@ -2578,6 +2585,29 @@ void RasterizerSceneGLES3::render_scene(const Ref &p_render_ spec_constant_base_flags |= SceneShaderGLES3::APPLY_TONEMAPPING; } } + + if (draw_feed && camera_feed_id > -1) { + RENDER_TIMESTAMP("Render Camera feed"); + + scene_state.enable_gl_depth_draw(false); + scene_state.enable_gl_depth_test(false); + scene_state.enable_gl_blend(false); + scene_state.set_gl_cull_mode(GLES3::SceneShaderData::CULL_BACK); + + Ref feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id); + + if (feed.is_valid()) { + RID camera_YCBCR = feed->get_texture(CameraServer::FEED_YCBCR_IMAGE); + GLES3::TextureStorage::get_singleton()->texture_bind(camera_YCBCR, 0); + + GLES3::FeedEffects *feed_effects = GLES3::FeedEffects::get_singleton(); + feed_effects->draw(); + } + scene_state.enable_gl_depth_draw(true); + scene_state.enable_gl_depth_test(true); + scene_state.enable_gl_blend(true); + } + // Render Opaque Objects. RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptr(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, spec_constant_base_flags, use_wireframe); diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub index df2c5150350..0207ba12b75 100644 --- a/drivers/gles3/shaders/SCsub +++ b/drivers/gles3/shaders/SCsub @@ -17,6 +17,7 @@ if "GLES3_GLSL" in env["BUILDERS"]: # as we have a few, not yet, converted files we name the ones we want to include: env.GLES3_GLSL("canvas.glsl") + env.GLES3_GLSL("feed.glsl") env.GLES3_GLSL("scene.glsl") env.GLES3_GLSL("sky.glsl") env.GLES3_GLSL("canvas_occlusion.glsl") diff --git a/drivers/gles3/shaders/feed.glsl b/drivers/gles3/shaders/feed.glsl new file mode 100644 index 00000000000..9d89fc699d7 --- /dev/null +++ b/drivers/gles3/shaders/feed.glsl @@ -0,0 +1,39 @@ +/* clang-format off */ +#[modes] + +mode_default = + +#[specializations] + +USE_EXTERNAL_SAMPLER = false + +#[vertex] + +layout(location = 0) in vec2 vertex_attrib; + +out vec2 uv_interp; + + +void main() { + uv_interp = vertex_attrib * 0.5 + 0.5; + gl_Position = vec4(vertex_attrib, 1.0, 1.0); +} + +/* clang-format off */ +#[fragment] + +layout(location = 0) out vec4 frag_color; +in vec2 uv_interp; + +/* clang-format on */ +#ifdef USE_EXTERNAL_SAMPLER +uniform samplerExternalOES sourceFeed; // texunit:0 +#else +uniform sampler2D sourceFeed; // texunit:0 +#endif + +void main() { + vec4 color = texture(sourceFeed, uv_interp); + + frag_color = color; +} diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index f8c70c3002a..b5e23e98321 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -130,10 +130,7 @@ int Environment::get_canvas_max_layer() const { void Environment::set_camera_feed_id(int p_id) { bg_camera_feed_id = p_id; -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 - RS::get_singleton()->environment_set_camera_feed_id(environment, camera_feed_id); -#endif + RS::get_singleton()->environment_set_camera_feed_id(environment, bg_camera_feed_id); } int Environment::get_camera_feed_id() const { diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp index 4021d9564bf..e93ab3a5442 100644 --- a/servers/camera/camera_feed.cpp +++ b/servers/camera/camera_feed.cpp @@ -50,6 +50,8 @@ void CameraFeed::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rgb_image", "rgb_image"), &CameraFeed::set_rgb_image); ClassDB::bind_method(D_METHOD("set_ycbcr_image", "ycbcr_image"), &CameraFeed::set_ycbcr_image); + ClassDB::bind_method(D_METHOD("set_external", "width", "height"), &CameraFeed::set_external); + ClassDB::bind_method(D_METHOD("get_texture_tex_id", "feed_image_type"), &CameraFeed::get_texture_tex_id); ClassDB::bind_method(D_METHOD("get_datatype"), &CameraFeed::get_datatype); @@ -68,6 +70,7 @@ void CameraFeed::_bind_methods() { BIND_ENUM_CONSTANT(FEED_RGB); BIND_ENUM_CONSTANT(FEED_YCBCR); BIND_ENUM_CONSTANT(FEED_YCBCR_SEP); + BIND_ENUM_CONSTANT(FEED_EXTERNAL); BIND_ENUM_CONSTANT(FEED_UNSPECIFIED); BIND_ENUM_CONSTANT(FEED_FRONT); @@ -137,6 +140,10 @@ RID CameraFeed::get_texture(CameraServer::FeedImage p_which) { return texture[p_which]; } +uint64_t CameraFeed::get_texture_tex_id(CameraServer::FeedImage p_which) { + return RenderingServer::get_singleton()->texture_get_native_handle(texture[p_which]); +} + CameraFeed::CameraFeed() { // initialize our feed id = CameraServer::get_singleton()->get_free_id(); @@ -252,6 +259,19 @@ void CameraFeed::set_ycbcr_images(const Ref &p_y_img, const Ref &p } } +void CameraFeed::set_external(int p_width, int p_height) { + if ((base_width != p_width) || (base_height != p_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = p_width; + base_height = p_height; + + auto new_texture = RenderingServer::get_singleton()->texture_external_create(p_width, p_height, 0); + RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_YCBCR_IMAGE], new_texture); + } + + datatype = CameraFeed::FEED_EXTERNAL; +} + bool CameraFeed::activate_feed() { // nothing to do here return true; diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h index 492a909239e..365ed7c6357 100644 --- a/servers/camera/camera_feed.h +++ b/servers/camera/camera_feed.h @@ -49,7 +49,8 @@ public: FEED_NOIMAGE, // we don't have an image yet FEED_RGB, // our texture will contain a normal RGB texture that can be used directly FEED_YCBCR, // our texture will contain a YCbCr texture that needs to be converted to RGB before output - FEED_YCBCR_SEP // our camera is split into two textures, first plane contains Y data, second plane contains CbCr data + FEED_YCBCR_SEP, // our camera is split into two textures, first plane contains Y data, second plane contains CbCr data + FEED_EXTERNAL, // specific for android atm, camera feed is managed externally, assumed RGB for now }; enum FeedPosition { @@ -104,6 +105,7 @@ public: void set_transform(const Transform2D &p_transform); RID get_texture(CameraServer::FeedImage p_which); + uint64_t get_texture_tex_id(CameraServer::FeedImage p_which); CameraFeed(); CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED); @@ -113,6 +115,7 @@ public: void set_rgb_image(const Ref &p_rgb_img); void set_ycbcr_image(const Ref &p_ycbcr_img); void set_ycbcr_images(const Ref &p_y_img, const Ref &p_cbcr_img); + void set_external(int p_width, int p_height); virtual bool set_format(int p_index, const Dictionary &p_parameters); virtual Array get_formats() const; diff --git a/servers/rendering/renderer_scene_cull.h b/servers/rendering/renderer_scene_cull.h index 5aae59eb51d..8f85ebded67 100644 --- a/servers/rendering/renderer_scene_cull.h +++ b/servers/rendering/renderer_scene_cull.h @@ -1255,6 +1255,7 @@ public: PASS3(environment_set_bg_energy, RID, float, float) PASS2(environment_set_canvas_max_layer, RID, int) PASS6(environment_set_ambient_light, RID, const Color &, RS::EnvironmentAmbientSource, float, float, RS::EnvironmentReflectionSource) + PASS2(environment_set_camera_feed_id, RID, int) PASS1RC(RS::EnvironmentBG, environment_get_background, RID) PASS1RC(RID, environment_get_sky, RID) diff --git a/servers/rendering/renderer_scene_render.cpp b/servers/rendering/renderer_scene_render.cpp index 797ba7eaf74..e3df6a1d7e3 100644 --- a/servers/rendering/renderer_scene_render.cpp +++ b/servers/rendering/renderer_scene_render.cpp @@ -349,6 +349,14 @@ RS::EnvironmentReflectionSource RendererSceneRender::environment_get_reflection_ return environment_storage.environment_get_reflection_source(p_env); } +void RendererSceneRender::environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) { + environment_storage.environment_set_camera_feed_id(p_env, p_camera_feed_id); +} + +int RendererSceneRender::environment_get_camera_feed_id(RID p_env) const { + return environment_storage.environment_get_camera_feed_id(p_env); +} + // Tonemap void RendererSceneRender::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) { diff --git a/servers/rendering/renderer_scene_render.h b/servers/rendering/renderer_scene_render.h index 4d81a9b6a31..2a32738e58c 100644 --- a/servers/rendering/renderer_scene_render.h +++ b/servers/rendering/renderer_scene_render.h @@ -118,10 +118,7 @@ public: void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value); void environment_set_canvas_max_layer(RID p_env, int p_max_layer); void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG); -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id); -#endif RS::EnvironmentBG environment_get_background(RID p_env) const; RID environment_get_sky(RID p_env) const; @@ -136,6 +133,7 @@ public: float environment_get_ambient_light_energy(RID p_env) const; float environment_get_ambient_sky_contribution(RID p_env) const; RS::EnvironmentReflectionSource environment_get_reflection_source(RID p_env) const; + int environment_get_camera_feed_id(RID p_env) const; // Tonemap void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white); diff --git a/servers/rendering/rendering_method.h b/servers/rendering/rendering_method.h index 4c277ac2152..34f11924ceb 100644 --- a/servers/rendering/rendering_method.h +++ b/servers/rendering/rendering_method.h @@ -168,6 +168,7 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG) = 0; + virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; virtual RS::EnvironmentBG environment_get_background(RID p_Env) const = 0; virtual RID environment_get_sky(RID p_env) const = 0; diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 225a67fb525..59479750cbe 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -785,10 +785,8 @@ public: FUNC2(environment_set_canvas_max_layer, RID, int) FUNC6(environment_set_ambient_light, RID, const Color &, EnvironmentAmbientSource, float, float, EnvironmentReflectionSource) -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 FUNC2(environment_set_camera_feed_id, RID, int) -#endif + FUNC6(environment_set_ssr, RID, bool, int, float, float, float) FUNC1(environment_set_ssr_roughness_quality, EnvironmentSSRRoughnessQuality) diff --git a/servers/rendering/storage/environment_storage.cpp b/servers/rendering/storage/environment_storage.cpp index 1bbb5da6bb9..e7556f90008 100644 --- a/servers/rendering/storage/environment_storage.cpp +++ b/servers/rendering/storage/environment_storage.cpp @@ -189,6 +189,18 @@ RS::EnvironmentReflectionSource RendererEnvironmentStorage::environment_get_refl return env->reflection_source; } +void RendererEnvironmentStorage::environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) { + Environment *env = environment_owner.get_or_null(p_env); + ERR_FAIL_NULL(env); + env->camera_feed_id = p_camera_feed_id; +} + +int RendererEnvironmentStorage::environment_get_camera_feed_id(RID p_env) const { + Environment *env = environment_owner.get_or_null(p_env); + ERR_FAIL_NULL_V(env, -1); + return env->camera_feed_id; +} + // Tonemap void RendererEnvironmentStorage::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) { diff --git a/servers/rendering/storage/environment_storage.h b/servers/rendering/storage/environment_storage.h index 9f78808ff75..6fdc047ba28 100644 --- a/servers/rendering/storage/environment_storage.h +++ b/servers/rendering/storage/environment_storage.h @@ -57,6 +57,7 @@ private: float ambient_light_energy = 1.0; float ambient_sky_contribution = 1.0; RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG; + int camera_feed_id = 0; // Tonemap RS::EnvironmentToneMapper tone_mapper; @@ -181,10 +182,8 @@ public: void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value); void environment_set_canvas_max_layer(RID p_env, int p_max_layer); void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG); -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id); -#endif + int environment_get_camera_feed_id(RID p_env) const; RS::EnvironmentBG environment_get_background(RID p_env) const; RID environment_get_sky(RID p_env) const; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 32ef5261f31..5573c642f19 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2979,6 +2979,7 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("environment_create"), &RenderingServer::environment_create); ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &RenderingServer::environment_set_background); + ClassDB::bind_method(D_METHOD("environment_set_camera_id", "env", "id"), &RenderingServer::environment_set_camera_feed_id); ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &RenderingServer::environment_set_sky); ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &RenderingServer::environment_set_sky_custom_fov); ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &RenderingServer::environment_set_sky_orientation); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 0208a640a52..3831b484204 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -1179,6 +1179,7 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, EnvironmentAmbientSource p_ambient = ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, EnvironmentReflectionSource p_reflection_source = ENV_REFLECTION_SOURCE_BG) = 0; + virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; enum EnvironmentGlowBlendMode { ENV_GLOW_BLEND_MODE_ADDITIVE,