Added external camera feed from external plugin on Android

This commit is contained in:
maxime.chambefort 2024-03-17 20:44:47 +01:00 committed by maxime.chambefort
parent db66bd35af
commit 6f846eb5c5
21 changed files with 350 additions and 15 deletions

View File

@ -34,6 +34,21 @@
Returns the position of camera on the device. Returns the position of camera on the device.
</description> </description>
</method> </method>
<method name="get_texture_tex_id">
<return type="int" />
<param index="0" name="feed_image_type" type="int" enum="CameraServer.FeedImage" />
<description>
Returns the texture backend ID (usable by some external libraries that need a handle to a texture to write data).
</description>
</method>
<method name="set_external">
<return type="void" />
<param index="0" name="width" type="int" />
<param index="1" name="height" type="int" />
<description>
Sets the feed as external feed provided by another library.
</description>
</method>
<method name="set_format"> <method name="set_format">
<return type="bool" /> <return type="bool" />
<param index="0" name="index" type="int" /> <param index="0" name="index" type="int" />
@ -110,6 +125,9 @@
<constant name="FEED_YCBCR_SEP" value="3" enum="FeedDataType"> <constant name="FEED_YCBCR_SEP" value="3" enum="FeedDataType">
Feed supplies separate Y and CbCr images that need to be combined and converted to RGB. Feed supplies separate Y and CbCr images that need to be combined and converted to RGB.
</constant> </constant>
<constant name="FEED_EXTERNAL" value="4" enum="FeedDataType">
Feed supplies external image.
</constant>
<constant name="FEED_UNSPECIFIED" value="0" enum="FeedPosition"> <constant name="FEED_UNSPECIFIED" value="0" enum="FeedPosition">
Unspecified position. Unspecified position.
</constant> </constant>

View File

@ -1278,6 +1278,14 @@
Sets the intensity of the background color. Sets the intensity of the background color.
</description> </description>
</method> </method>
<method name="environment_set_camera_id">
<return type="void" />
<param index="0" name="env" type="RID" />
<param index="1" name="id" type="int" />
<description>
Sets the camera ID to be used as environment background.
</description>
</method>
<method name="environment_set_canvas_max_layer"> <method name="environment_set_canvas_max_layer">
<return type="void" /> <return type="void" />
<param index="0" name="env" type="RID" /> <param index="0" name="env" type="RID" />

View File

@ -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 <GLES3/gl3ext.h>
#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

View File

@ -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

View File

@ -213,6 +213,7 @@ void RasterizerGLES3::finalize() {
memdelete(glow); memdelete(glow);
memdelete(cubemap_filter); memdelete(cubemap_filter);
memdelete(copy_effects); memdelete(copy_effects);
memdelete(feed_effects);
memdelete(light_storage); memdelete(light_storage);
memdelete(particles_storage); memdelete(particles_storage);
memdelete(mesh_storage); memdelete(mesh_storage);
@ -361,6 +362,7 @@ RasterizerGLES3::RasterizerGLES3() {
cubemap_filter = memnew(GLES3::CubemapFilter); cubemap_filter = memnew(GLES3::CubemapFilter);
glow = memnew(GLES3::Glow); glow = memnew(GLES3::Glow);
post_effects = memnew(GLES3::PostEffects); post_effects = memnew(GLES3::PostEffects);
feed_effects = memnew(GLES3::FeedEffects);
gi = memnew(GLES3::GI); gi = memnew(GLES3::GI);
fog = memnew(GLES3::Fog); fog = memnew(GLES3::Fog);
canvas = memnew(RasterizerCanvasGLES3()); canvas = memnew(RasterizerCanvasGLES3());

View File

@ -35,6 +35,7 @@
#include "effects/copy_effects.h" #include "effects/copy_effects.h"
#include "effects/cubemap_filter.h" #include "effects/cubemap_filter.h"
#include "effects/feed_effects.h"
#include "effects/glow.h" #include "effects/glow.h"
#include "effects/post_effects.h" #include "effects/post_effects.h"
#include "environment/fog.h" #include "environment/fog.h"
@ -74,6 +75,7 @@ protected:
GLES3::CubemapFilter *cubemap_filter = nullptr; GLES3::CubemapFilter *cubemap_filter = nullptr;
GLES3::Glow *glow = nullptr; GLES3::Glow *glow = nullptr;
GLES3::PostEffects *post_effects = nullptr; GLES3::PostEffects *post_effects = nullptr;
GLES3::FeedEffects *feed_effects = nullptr;
RasterizerCanvasGLES3 *canvas = nullptr; RasterizerCanvasGLES3 *canvas = nullptr;
RasterizerSceneGLES3 *scene = nullptr; RasterizerSceneGLES3 *scene = nullptr;
static RasterizerGLES3 *singleton; static RasterizerGLES3 *singleton;

View File

@ -31,6 +31,7 @@
#include "rasterizer_scene_gles3.h" #include "rasterizer_scene_gles3.h"
#include "drivers/gles3/effects/copy_effects.h" #include "drivers/gles3/effects/copy_effects.h"
#include "drivers/gles3/effects/feed_effects.h"
#include "rasterizer_gles3.h" #include "rasterizer_gles3.h"
#include "storage/config.h" #include "storage/config.h"
#include "storage/mesh_storage.h" #include "storage/mesh_storage.h"
@ -39,6 +40,8 @@
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/templates/sort_array.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_default.h"
#include "servers/rendering/rendering_server_globals.h" #include "servers/rendering/rendering_server_globals.h"
@ -2382,7 +2385,9 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
bool draw_sky = false; bool draw_sky = false;
bool draw_sky_fog_only = false; bool draw_sky_fog_only = false;
bool keep_color = false; bool keep_color = false;
bool draw_feed = false;
float sky_energy_multiplier = 1.0; float sky_energy_multiplier = 1.0;
int camera_feed_id = -1;
if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { 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 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<RenderSceneBuffers> &p_render_
keep_color = true; keep_color = true;
} break; } break;
case RS::ENV_BG_CAMERA_FEED: { case RS::ENV_BG_CAMERA_FEED: {
camera_feed_id = environment_get_camera_feed_id(render_data.environment);
draw_feed = true;
} break; } break;
default: { default: {
} }
@ -2538,7 +2545,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
} }
if (!keep_color) { if (!keep_color && !draw_feed) {
clear_color.a = render_data.transparent_bg ? 0.0f : 1.0f; clear_color.a = render_data.transparent_bg ? 0.0f : 1.0f;
glClearBufferfv(GL_COLOR, 0, clear_color.components); glClearBufferfv(GL_COLOR, 0, clear_color.components);
} else if (fbo != rt->fbo) { } else if (fbo != rt->fbo) {
@ -2578,6 +2585,29 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
spec_constant_base_flags |= SceneShaderGLES3::APPLY_TONEMAPPING; 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<CameraFeed> 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. // 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); 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);

View File

@ -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: # 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("canvas.glsl")
env.GLES3_GLSL("feed.glsl")
env.GLES3_GLSL("scene.glsl") env.GLES3_GLSL("scene.glsl")
env.GLES3_GLSL("sky.glsl") env.GLES3_GLSL("sky.glsl")
env.GLES3_GLSL("canvas_occlusion.glsl") env.GLES3_GLSL("canvas_occlusion.glsl")

View File

@ -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;
}

View File

@ -130,10 +130,7 @@ int Environment::get_canvas_max_layer() const {
void Environment::set_camera_feed_id(int p_id) { void Environment::set_camera_feed_id(int p_id) {
bg_camera_feed_id = p_id; bg_camera_feed_id = p_id;
// FIXME: Disabled during Vulkan refactoring, should be ported. RS::get_singleton()->environment_set_camera_feed_id(environment, bg_camera_feed_id);
#if 0
RS::get_singleton()->environment_set_camera_feed_id(environment, camera_feed_id);
#endif
} }
int Environment::get_camera_feed_id() const { int Environment::get_camera_feed_id() const {

View File

@ -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_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_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); 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_RGB);
BIND_ENUM_CONSTANT(FEED_YCBCR); BIND_ENUM_CONSTANT(FEED_YCBCR);
BIND_ENUM_CONSTANT(FEED_YCBCR_SEP); BIND_ENUM_CONSTANT(FEED_YCBCR_SEP);
BIND_ENUM_CONSTANT(FEED_EXTERNAL);
BIND_ENUM_CONSTANT(FEED_UNSPECIFIED); BIND_ENUM_CONSTANT(FEED_UNSPECIFIED);
BIND_ENUM_CONSTANT(FEED_FRONT); BIND_ENUM_CONSTANT(FEED_FRONT);
@ -137,6 +140,10 @@ RID CameraFeed::get_texture(CameraServer::FeedImage p_which) {
return texture[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() { CameraFeed::CameraFeed() {
// initialize our feed // initialize our feed
id = CameraServer::get_singleton()->get_free_id(); id = CameraServer::get_singleton()->get_free_id();
@ -252,6 +259,19 @@ void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &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() { bool CameraFeed::activate_feed() {
// nothing to do here // nothing to do here
return true; return true;

View File

@ -49,7 +49,8 @@ public:
FEED_NOIMAGE, // we don't have an image yet 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_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, // 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 { enum FeedPosition {
@ -104,6 +105,7 @@ public:
void set_transform(const Transform2D &p_transform); void set_transform(const Transform2D &p_transform);
RID get_texture(CameraServer::FeedImage p_which); RID get_texture(CameraServer::FeedImage p_which);
uint64_t get_texture_tex_id(CameraServer::FeedImage p_which);
CameraFeed(); CameraFeed();
CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED); CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED);
@ -113,6 +115,7 @@ public:
void set_rgb_image(const Ref<Image> &p_rgb_img); void set_rgb_image(const Ref<Image> &p_rgb_img);
void set_ycbcr_image(const Ref<Image> &p_ycbcr_img); void set_ycbcr_image(const Ref<Image> &p_ycbcr_img);
void set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img); void set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img);
void set_external(int p_width, int p_height);
virtual bool set_format(int p_index, const Dictionary &p_parameters); virtual bool set_format(int p_index, const Dictionary &p_parameters);
virtual Array get_formats() const; virtual Array get_formats() const;

View File

@ -1255,6 +1255,7 @@ public:
PASS3(environment_set_bg_energy, RID, float, float) PASS3(environment_set_bg_energy, RID, float, float)
PASS2(environment_set_canvas_max_layer, RID, int) PASS2(environment_set_canvas_max_layer, RID, int)
PASS6(environment_set_ambient_light, RID, const Color &, RS::EnvironmentAmbientSource, float, float, RS::EnvironmentReflectionSource) 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(RS::EnvironmentBG, environment_get_background, RID)
PASS1RC(RID, environment_get_sky, RID) PASS1RC(RID, environment_get_sky, RID)

View File

@ -349,6 +349,14 @@ RS::EnvironmentReflectionSource RendererSceneRender::environment_get_reflection_
return environment_storage.environment_get_reflection_source(p_env); 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 // Tonemap
void RendererSceneRender::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) { void RendererSceneRender::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) {

View File

@ -118,10 +118,7 @@ public:
void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value); 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_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); 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); void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id);
#endif
RS::EnvironmentBG environment_get_background(RID p_env) const; RS::EnvironmentBG environment_get_background(RID p_env) const;
RID environment_get_sky(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_light_energy(RID p_env) const;
float environment_get_ambient_sky_contribution(RID p_env) const; float environment_get_ambient_sky_contribution(RID p_env) const;
RS::EnvironmentReflectionSource environment_get_reflection_source(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 // Tonemap
void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white); void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white);

View File

@ -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_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_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_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 RS::EnvironmentBG environment_get_background(RID p_Env) const = 0;
virtual RID environment_get_sky(RID p_env) const = 0; virtual RID environment_get_sky(RID p_env) const = 0;

View File

@ -785,10 +785,8 @@ public:
FUNC2(environment_set_canvas_max_layer, RID, int) FUNC2(environment_set_canvas_max_layer, RID, int)
FUNC6(environment_set_ambient_light, RID, const Color &, EnvironmentAmbientSource, float, float, EnvironmentReflectionSource) 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) FUNC2(environment_set_camera_feed_id, RID, int)
#endif
FUNC6(environment_set_ssr, RID, bool, int, float, float, float) FUNC6(environment_set_ssr, RID, bool, int, float, float, float)
FUNC1(environment_set_ssr_roughness_quality, EnvironmentSSRRoughnessQuality) FUNC1(environment_set_ssr_roughness_quality, EnvironmentSSRRoughnessQuality)

View File

@ -189,6 +189,18 @@ RS::EnvironmentReflectionSource RendererEnvironmentStorage::environment_get_refl
return env->reflection_source; 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 // Tonemap
void RendererEnvironmentStorage::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) { void RendererEnvironmentStorage::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) {

View File

@ -57,6 +57,7 @@ private:
float ambient_light_energy = 1.0; float ambient_light_energy = 1.0;
float ambient_sky_contribution = 1.0; float ambient_sky_contribution = 1.0;
RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG; RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG;
int camera_feed_id = 0;
// Tonemap // Tonemap
RS::EnvironmentToneMapper tone_mapper; 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_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_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); 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); 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; RS::EnvironmentBG environment_get_background(RID p_env) const;
RID environment_get_sky(RID p_env) const; RID environment_get_sky(RID p_env) const;

View File

@ -2979,6 +2979,7 @@ void RenderingServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("environment_create"), &RenderingServer::environment_create); 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_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", "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_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); ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &RenderingServer::environment_set_sky_orientation);

View File

@ -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_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_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_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 { enum EnvironmentGlowBlendMode {
ENV_GLOW_BLEND_MODE_ADDITIVE, ENV_GLOW_BLEND_MODE_ADDITIVE,