Removed lightmap captures, and also cleaned up almost all lightmap stuff.

This commit is contained in:
Relintai 2022-03-15 19:57:34 +01:00
parent 03890f9e38
commit 6fac6ba7f7
21 changed files with 6 additions and 991 deletions

View File

@ -552,71 +552,6 @@ public:
void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
/* LIGHTMAP CAPTURE */
struct Instantiable : public RID_Data {
SelfList<RasterizerScene::InstanceBase>::List instance_list;
_FORCE_INLINE_ void instance_change_notify(bool p_aabb = true, bool p_materials = true) {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
while (instances) {
instances->self()->base_changed(p_aabb, p_materials);
instances = instances->next();
}
}
_FORCE_INLINE_ void instance_remove_deps() {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
while (instances) {
SelfList<RasterizerScene::InstanceBase> *next = instances->next();
instances->self()->base_removed();
instances = next;
}
}
Instantiable() {}
virtual ~Instantiable() {
}
};
struct LightmapCapture : public Instantiable {
PoolVector<LightmapCaptureOctree> octree;
AABB bounds;
Transform cell_xform;
int cell_subdiv;
float energy;
LightmapCapture() {
energy = 1.0;
cell_subdiv = 1;
}
};
mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) {}
AABB lightmap_capture_get_bounds(RID p_capture) const { return AABB(); }
void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) {}
RID lightmap_capture_create() {
LightmapCapture *capture = memnew(LightmapCapture);
return lightmap_capture_data_owner.make_rid(capture);
}
PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, PoolVector<uint8_t>());
return PoolVector<uint8_t>();
}
void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) {}
Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const { return Transform(); }
void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) {}
int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const { return 0; }
void lightmap_capture_set_energy(RID p_capture, float p_energy) {}
float lightmap_capture_get_energy(RID p_capture) const { return 0.0; }
void lightmap_capture_set_interior(RID p_capture, bool p_interior) {}
bool lightmap_capture_is_interior(RID p_capture) const { return false; }
const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, NULL);
return &capture->octree;
}
/* PARTICLES */
RID particles_create() { return RID(); }
@ -681,8 +616,6 @@ public:
VS::InstanceType get_base_type(RID p_rid) const {
if (mesh_owner.owns(p_rid)) {
return VS::INSTANCE_MESH;
} else if (lightmap_capture_data_owner.owns(p_rid)) {
return VS::INSTANCE_LIGHTMAP_CAPTURE;
}
return VS::INSTANCE_NONE;
@ -699,11 +632,6 @@ public:
DummyMesh *mesh = mesh_owner.getornull(p_rid);
mesh_owner.free(p_rid);
memdelete(mesh);
} else if (lightmap_capture_data_owner.owns(p_rid)) {
// delete the lightmap
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid);
lightmap_capture_data_owner.free(p_rid);
memdelete(lightmap_capture);
} else {
return false;
}

View File

@ -1215,13 +1215,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
copy = true;
}
if (e->instance->lightmap.is_valid()) {
e->light_mode = LIGHTMODE_LIGHTMAP;
} else if (!e->instance->lightmap_capture_data.empty()) {
e->light_mode = LIGHTMODE_LIGHTMAP_CAPTURE;
} else {
e->light_mode = LIGHTMODE_NORMAL;
}
e->light_mode = LIGHTMODE_NORMAL;
}
}
@ -2292,10 +2286,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
using_fog = true;
}
RasterizerStorageGLES2::Texture *prev_lightmap = nullptr;
float lightmap_energy = 1.0;
bool prev_use_lightmap_capture = false;
storage->info.render.draw_call_count += p_element_count;
for (int i = 0; i < p_element_count; i++) {
@ -2309,11 +2299,8 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
LightInstance *light = nullptr;
ReflectionProbeInstance *refprobe_1 = nullptr;
ReflectionProbeInstance *refprobe_2 = nullptr;
RasterizerStorageGLES2::Texture *lightmap = nullptr;
bool use_lightmap_capture = false;
bool rebind_light = false;
bool rebind_reflection = false;
bool rebind_lightmap = false;
if (!p_shadow && material->shader) {
bool unshaded = material->shader->spatial.unshaded;
@ -2437,34 +2424,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
rebind = true;
rebind_reflection = true;
}
use_lightmap_capture = !unshaded && !accum_pass && !e->instance->lightmap_capture_data.empty();
if (use_lightmap_capture != prev_use_lightmap_capture) {
state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP_CAPTURE, use_lightmap_capture);
rebind = true;
}
if (!unshaded && !accum_pass && e->instance->lightmap.is_valid()) {
lightmap = storage->texture_owner.getornull(e->instance->lightmap);
lightmap_energy = 1.0;
if (lightmap) {
RasterizerStorageGLES2::LightmapCapture *capture = storage->lightmap_capture_data_owner.getornull(e->instance->lightmap_capture->base);
if (capture) {
lightmap_energy = capture->energy;
}
}
}
if (lightmap != prev_lightmap) {
state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, lightmap != nullptr);
if (lightmap != nullptr) {
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
glBindTexture(GL_TEXTURE_2D, lightmap->tex_id);
}
rebind = true;
rebind_lightmap = true;
}
}
bool depth_prepass = false;
@ -2566,7 +2525,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
//rebind all these
rebind_light = true;
rebind_reflection = true;
rebind_lightmap = true;
if (using_fog) {
state.scene_shader.set_uniform(SceneShaderGLES2::FOG_COLOR_BASE, p_env->fog_color);
@ -2613,19 +2571,8 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
_setup_refprobes(refprobe_1, refprobe_2, p_view_transform, p_env);
}
if (rebind_lightmap && lightmap) {
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_ENERGY, lightmap_energy);
if (storage->config.use_lightmap_filter_bicubic) {
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_TEXTURE_SIZE, Vector2(lightmap->width, lightmap->height));
}
}
state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
if (use_lightmap_capture) { //this is per instance, must be set always if present
glUniform4fv(state.scene_shader.get_uniform_location(SceneShaderGLES2::LIGHTMAP_CAPTURES), 12, (const GLfloat *)e->instance->lightmap_capture_data.ptr());
}
_render_geometry(e);
prev_geometry = e->geometry;
@ -2637,8 +2584,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
prev_light = light;
prev_refprobe_1 = refprobe_1;
prev_refprobe_2 = refprobe_2;
prev_lightmap = lightmap;
prev_use_lightmap_capture = use_lightmap_capture;
}
_setup_light_type(nullptr, nullptr); //clear light stuff
@ -2654,8 +2599,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
state.scene_shader.set_conditional(SceneShaderGLES2::USE_VERTEX_LIGHTING, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE1, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE2, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP_CAPTURE, false);
state.scene_shader.set_conditional(SceneShaderGLES2::FOG_DEPTH_ENABLED, false);
state.scene_shader.set_conditional(SceneShaderGLES2::FOG_HEIGHT_ENABLED, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_DEPTH_PREPASS, false);
@ -4076,10 +4019,6 @@ void RasterizerSceneGLES2::initialize() {
directional_shadow_create();
if (storage->config.use_lightmap_filter_bicubic) {
state.scene_shader.add_custom_define("#define USE_LIGHTMAP_FILTER_BICUBIC\n");
}
shadow_filter_mode = SHADOW_FILTER_NEAREST;
glFrontFace(GL_CW);

View File

@ -559,8 +559,6 @@ public:
enum LightMode {
LIGHTMODE_NORMAL,
LIGHTMODE_UNSHADED,
LIGHTMODE_LIGHTMAP,
LIGHTMODE_LIGHTMAP_CAPTURE,
};
struct RenderList {

View File

@ -4557,127 +4557,6 @@ int RasterizerStorageGLES2::reflection_probe_get_resolution(RID p_probe) const {
///////
RID RasterizerStorageGLES2::lightmap_capture_create() {
LightmapCapture *capture = memnew(LightmapCapture);
return lightmap_capture_data_owner.make_rid(capture);
}
void RasterizerStorageGLES2::lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->bounds = p_bounds;
capture->instance_change_notify(true, false);
}
AABB RasterizerStorageGLES2::lightmap_capture_get_bounds(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, AABB());
return capture->bounds;
}
void RasterizerStorageGLES2::lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
ERR_FAIL_COND(p_octree.size() == 0 || (p_octree.size() % sizeof(LightmapCaptureOctree)) != 0);
capture->octree.resize(p_octree.size() / sizeof(LightmapCaptureOctree));
if (p_octree.size()) {
PoolVector<LightmapCaptureOctree>::Write w = capture->octree.write();
PoolVector<uint8_t>::Read r = p_octree.read();
memcpy(w.ptr(), r.ptr(), p_octree.size());
}
capture->instance_change_notify(true, false);
}
PoolVector<uint8_t> RasterizerStorageGLES2::lightmap_capture_get_octree(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, PoolVector<uint8_t>());
if (capture->octree.size() == 0) {
return PoolVector<uint8_t>();
}
PoolVector<uint8_t> ret;
ret.resize(capture->octree.size() * sizeof(LightmapCaptureOctree));
{
PoolVector<LightmapCaptureOctree>::Read r = capture->octree.read();
PoolVector<uint8_t>::Write w = ret.write();
memcpy(w.ptr(), r.ptr(), ret.size());
}
return ret;
}
void RasterizerStorageGLES2::lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->cell_xform = p_xform;
}
Transform RasterizerStorageGLES2::lightmap_capture_get_octree_cell_transform(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, Transform());
return capture->cell_xform;
}
void RasterizerStorageGLES2::lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->cell_subdiv = p_subdiv;
}
int RasterizerStorageGLES2::lightmap_capture_get_octree_cell_subdiv(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, 0);
return capture->cell_subdiv;
}
void RasterizerStorageGLES2::lightmap_capture_set_energy(RID p_capture, float p_energy) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->energy = p_energy;
if (!capture->update_list.in_list()) {
capture_update_list.add(&capture->update_list);
}
}
float RasterizerStorageGLES2::lightmap_capture_get_energy(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, 0);
return capture->energy;
}
void RasterizerStorageGLES2::lightmap_capture_set_interior(RID p_capture, bool p_interior) {
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->interior = p_interior;
if (!capture->update_list.in_list()) {
capture_update_list.add(&capture->update_list);
}
}
bool RasterizerStorageGLES2::lightmap_capture_is_interior(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, false);
return capture->interior;
}
void RasterizerStorageGLES2::update_dirty_captures() {
while (capture_update_list.first()) {
LightmapCapture *capture = capture_update_list.first()->self();
capture->instance_change_notify(false, true);
capture_update_list.remove(capture_update_list.first());
}
}
const PoolVector<RasterizerStorage::LightmapCaptureOctree> *RasterizerStorageGLES2::lightmap_capture_get_octree_ptr(RID p_capture) const {
const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND_V(!capture, nullptr);
return &capture->octree;
}
///////
RID RasterizerStorageGLES2::particles_create() {
return RID();
}
@ -4809,10 +4688,6 @@ void RasterizerStorageGLES2::instance_add_dependency(RID p_base, RasterizerScene
inst = light_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
} break;
case VS::INSTANCE_LIGHTMAP_CAPTURE: {
inst = lightmap_capture_data_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
} break;
default: {
ERR_FAIL();
}
@ -4849,10 +4724,6 @@ void RasterizerStorageGLES2::instance_remove_dependency(RID p_base, RasterizerSc
inst = light_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
} break;
case VS::INSTANCE_LIGHTMAP_CAPTURE: {
inst = lightmap_capture_data_owner.getornull(p_base);
ERR_FAIL_COND(!inst);
} break;
default: {
ERR_FAIL();
}
@ -5757,8 +5628,6 @@ VS::InstanceType RasterizerStorageGLES2::get_base_type(RID p_rid) const {
return VS::INSTANCE_IMMEDIATE;
} else if (reflection_probe_owner.owns(p_rid)) {
return VS::INSTANCE_REFLECTION_PROBE;
} else if (lightmap_capture_data_owner.owns(p_rid)) {
return VS::INSTANCE_LIGHTMAP_CAPTURE;
} else {
return VS::INSTANCE_NONE;
}
@ -5941,15 +5810,6 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
memdelete(reflection_probe);
return true;
} else if (lightmap_capture_data_owner.owns(p_rid)) {
// delete the texture
LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get(p_rid);
lightmap_capture->instance_remove_deps();
lightmap_capture_data_owner.free(p_rid);
memdelete(lightmap_capture);
return true;
} else if (canvas_occluder_owner.owns(p_rid)) {
CanvasOccluder *co = canvas_occluder_owner.get(p_rid);
if (co->index_id) {
@ -6458,7 +6318,6 @@ void RasterizerStorageGLES2::initialize() {
config.use_fast_texture_filter = GLOBAL_GET("rendering/quality/filters/use_nearest_mipmap_filter");
GLOBAL_DEF_RST("rendering/quality/lightmapping/use_bicubic_sampling", true);
GLOBAL_DEF_RST("rendering/quality/lightmapping/use_bicubic_sampling.mobile", false);
config.use_lightmap_filter_bicubic = GLOBAL_GET("rendering/quality/lightmapping/use_bicubic_sampling");
config.use_physical_light_attenuation = GLOBAL_GET("rendering/quality/shading/use_physical_light_attenuation");
@ -6490,7 +6349,6 @@ void RasterizerStorageGLES2::update_dirty_resources() {
update_dirty_blend_shapes();
update_dirty_skeletons();
update_dirty_multimeshes();
update_dirty_captures();
}
RasterizerStorageGLES2::RasterizerStorageGLES2() {

View File

@ -57,7 +57,6 @@ public:
bool use_fast_texture_filter;
bool use_anisotropic_filter;
bool use_skeleton_software;
bool use_lightmap_filter_bicubic;
bool use_physical_light_attenuation;
int max_vertex_texture_image_units;
@ -1042,48 +1041,6 @@ public:
virtual float reflection_probe_get_origin_max_distance(RID p_probe) const;
virtual bool reflection_probe_renders_shadows(RID p_probe) const;
/* LIGHTMAP */
struct LightmapCapture : public Instantiable {
PoolVector<LightmapCaptureOctree> octree;
AABB bounds;
Transform cell_xform;
int cell_subdiv;
float energy;
bool interior;
SelfList<LightmapCapture> update_list;
LightmapCapture() :
update_list(this) {
energy = 1.0;
cell_subdiv = 1;
interior = false;
}
};
SelfList<LightmapCapture>::List capture_update_list;
void update_dirty_captures();
mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
virtual RID lightmap_capture_create();
virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds);
virtual AABB lightmap_capture_get_bounds(RID p_capture) const;
virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree);
virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const;
virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform);
virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const;
virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv);
virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const;
virtual void lightmap_capture_set_energy(RID p_capture, float p_energy);
virtual float lightmap_capture_get_energy(RID p_capture) const;
virtual void lightmap_capture_set_interior(RID p_capture, bool p_interior);
virtual bool lightmap_capture_is_interior(RID p_capture) const;
virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const;
/* PARTICLES */
void update_particles();

View File

@ -53,7 +53,7 @@ attribute vec4 color_attrib; // attrib:3
attribute vec2 uv_attrib; // attrib:4
#endif
#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP)
#if defined(ENABLE_UV2_INTERP)
attribute vec2 uv2_attrib; // attrib:5
#endif
@ -395,7 +395,7 @@ void main() {
uv_interp = uv_attrib;
#endif
#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP)
#if defined(ENABLE_UV2_INTERP)
uv2_interp = uv2_attrib;
#endif
@ -941,78 +941,6 @@ void reflection_process(samplerCube reflection_map,
#endif //use refprobe 1 or 2
#ifdef USE_LIGHTMAP
uniform mediump sampler2D lightmap; //texunit:-4
uniform mediump float lightmap_energy;
#if defined(USE_LIGHTMAP_FILTER_BICUBIC)
uniform mediump vec2 lightmap_texture_size;
// w0, w1, w2, and w3 are the four cubic B-spline basis functions
float w0(float a) {
return (1.0 / 6.0) * (a * (a * (-a + 3.0) - 3.0) + 1.0);
}
float w1(float a) {
return (1.0 / 6.0) * (a * a * (3.0 * a - 6.0) + 4.0);
}
float w2(float a) {
return (1.0 / 6.0) * (a * (a * (-3.0 * a + 3.0) + 3.0) + 1.0);
}
float w3(float a) {
return (1.0 / 6.0) * (a * a * a);
}
// g0 and g1 are the two amplitude functions
float g0(float a) {
return w0(a) + w1(a);
}
float g1(float a) {
return w2(a) + w3(a);
}
// h0 and h1 are the two offset functions
float h0(float a) {
return -1.0 + w1(a) / (w0(a) + w1(a));
}
float h1(float a) {
return 1.0 + w3(a) / (w2(a) + w3(a));
}
vec4 texture2D_bicubic(sampler2D tex, vec2 uv) {
vec2 texel_size = vec2(1.0) / lightmap_texture_size;
uv = uv * lightmap_texture_size + vec2(0.5);
vec2 iuv = floor(uv);
vec2 fuv = fract(uv);
float g0x = g0(fuv.x);
float g1x = g1(fuv.x);
float h0x = h0(fuv.x);
float h1x = h1(fuv.x);
float h0y = h0(fuv.y);
float h1y = h1(fuv.y);
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - vec2(0.5)) * texel_size;
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - vec2(0.5)) * texel_size;
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - vec2(0.5)) * texel_size;
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - vec2(0.5)) * texel_size;
return (g0(fuv.y) * (g0x * texture2D(tex, p0) + g1x * texture2D(tex, p1))) +
(g1(fuv.y) * (g0x * texture2D(tex, p2) + g1x * texture2D(tex, p3)));
}
#endif //USE_LIGHTMAP_FILTER_BICUBIC
#endif
#ifdef USE_LIGHTMAP_CAPTURE
uniform mediump vec4 lightmap_captures[12];
#endif
#ifdef USE_RADIANCE_MAP
uniform samplerCube radiance_map; // texunit:-2
@ -1121,7 +1049,7 @@ varying vec4 color_interp;
varying vec2 uv_interp;
#endif
#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP)
#if defined(ENABLE_UV2_INTERP)
varying vec2 uv2_interp;
#endif
@ -1819,51 +1747,6 @@ FRAGMENT_SHADER_CODE
#endif
}
#ifdef USE_LIGHTMAP
//ambient light will come entirely from lightmap is lightmap is used
#if defined(USE_LIGHTMAP_FILTER_BICUBIC)
ambient_light = texture2D_bicubic(lightmap, uv2_interp).rgb * lightmap_energy;
#else
ambient_light = texture2D(lightmap, uv2_interp).rgb * lightmap_energy;
#endif
#endif
#ifdef USE_LIGHTMAP_CAPTURE
{
vec3 cone_dirs[12];
cone_dirs[0] = vec3(0.0, 0.0, 1.0);
cone_dirs[1] = vec3(0.866025, 0.0, 0.5);
cone_dirs[2] = vec3(0.267617, 0.823639, 0.5);
cone_dirs[3] = vec3(-0.700629, 0.509037, 0.5);
cone_dirs[4] = vec3(-0.700629, -0.509037, 0.5);
cone_dirs[5] = vec3(0.267617, -0.823639, 0.5);
cone_dirs[6] = vec3(0.0, 0.0, -1.0);
cone_dirs[7] = vec3(0.866025, 0.0, -0.5);
cone_dirs[8] = vec3(0.267617, 0.823639, -0.5);
cone_dirs[9] = vec3(-0.700629, 0.509037, -0.5);
cone_dirs[10] = vec3(-0.700629, -0.509037, -0.5);
cone_dirs[11] = vec3(0.267617, -0.823639, -0.5);
vec3 local_normal = normalize(camera_matrix * vec4(normal, 0.0)).xyz;
vec4 captured = vec4(0.0);
float sum = 0.0;
for (int i = 0; i < 12; i++) {
float amount = max(0.0, dot(local_normal, cone_dirs[i])); //not correct, but creates a nice wrap around effect
captured += lightmap_captures[i] * amount;
sum += amount;
}
captured /= sum;
// Alpha channel is used to indicate if dynamic objects keep the environment lighting
if (lightmap_captures[0].a > 0.5) {
ambient_light += captured.rgb;
} else {
ambient_light = captured.rgb;
}
}
#endif
#endif //BASE PASS
//

View File

@ -539,9 +539,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("editors/3d/default_z_near", 0.05);
_initial_set("editors/3d/default_z_far", 500.0);
_initial_set("editors/3d/lightmap_baking_number_of_cpu_threads", 0);
hints["editors/3d/lightmap_baking_number_of_cpu_threads"] = PropertyInfo(Variant::INT, "editors/3d/lightmap_baking_number_of_cpu_threads", PROPERTY_HINT_RANGE, "-2,128,1", PROPERTY_USAGE_DEFAULT);
// 3D: Navigation
_initial_set("editors/3d/navigation/navigation_scheme", 0);
_initial_set("editors/3d/navigation/invert_y_axis", false);

View File

@ -257,22 +257,6 @@ void MeshInstanceEditor::_menu_option(int p_option) {
case MENU_OPTION_CREATE_OUTLINE_MESH: {
outline_dialog->popup_centered(Vector2(200, 90));
} break;
case MENU_OPTION_CREATE_UV2: {
Ref<ArrayMesh> mesh2 = node->get_mesh();
if (!mesh2.is_valid()) {
err_dialog->set_text(TTR("Contained Mesh is not of type ArrayMesh."));
err_dialog->popup_centered_minsize();
return;
}
Error err = mesh2->lightmap_unwrap(node->get_global_transform());
if (err != OK) {
err_dialog->set_text(TTR("UV Unwrap failed, mesh may not be manifold?"));
err_dialog->popup_centered_minsize();
return;
}
} break;
case MENU_OPTION_DEBUG_UV1: {
Ref<Mesh> mesh2 = node->get_mesh();
if (!mesh2.is_valid()) {
@ -469,7 +453,6 @@ MeshInstanceEditor::MeshInstanceEditor() {
options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("View UV1"), MENU_OPTION_DEBUG_UV1);
options->get_popup()->add_item(TTR("View UV2"), MENU_OPTION_DEBUG_UV2);
options->get_popup()->add_item(TTR("Unwrap UV2 for Lightmap/AO"), MENU_OPTION_CREATE_UV2);
options->get_popup()->connect("id_pressed", this, "_menu_option");

View File

@ -48,7 +48,6 @@ class MeshInstanceEditor : public Control {
MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES,
MENU_OPTION_CREATE_NAVMESH,
MENU_OPTION_CREATE_OUTLINE_MESH,
MENU_OPTION_CREATE_UV2,
MENU_OPTION_DEBUG_UV1,
MENU_OPTION_DEBUG_UV2,
};

View File

@ -214,23 +214,6 @@ Ref<Material> GeometryInstance::get_material_overlay() const {
return material_overlay;
}
void GeometryInstance::set_generate_lightmap(bool p_enabled) {
generate_lightmap = p_enabled;
}
bool GeometryInstance::get_generate_lightmap() {
return generate_lightmap;
}
void GeometryInstance::set_lightmap_scale(LightmapScale p_scale) {
ERR_FAIL_INDEX(p_scale, LIGHTMAP_SCALE_MAX);
lightmap_scale = p_scale;
}
GeometryInstance::LightmapScale GeometryInstance::get_lightmap_scale() const {
return lightmap_scale;
}
void GeometryInstance::set_lod_min_distance(float p_dist) {
lod_min_distance = p_dist;
VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis);
@ -323,12 +306,6 @@ void GeometryInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting);
ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting);
ClassDB::bind_method(D_METHOD("set_generate_lightmap", "enabled"), &GeometryInstance::set_generate_lightmap);
ClassDB::bind_method(D_METHOD("get_generate_lightmap"), &GeometryInstance::get_generate_lightmap);
ClassDB::bind_method(D_METHOD("set_lightmap_scale", "scale"), &GeometryInstance::set_lightmap_scale);
ClassDB::bind_method(D_METHOD("get_lightmap_scale"), &GeometryInstance::get_lightmap_scale);
ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance::set_lod_max_hysteresis);
ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis);
@ -354,11 +331,6 @@ void GeometryInstance::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01"), "set_extra_cull_margin", "get_extra_cull_margin");
ADD_GROUP("Baked Light", "");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag", FLAG_USE_BAKED_LIGHT);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_lightmap"), "set_generate_lightmap", "get_generate_lightmap");
ADD_PROPERTY(PropertyInfo(Variant::INT, "lightmap_scale", PROPERTY_HINT_ENUM, "1x,2x,4x,8x"), "set_lightmap_scale", "get_lightmap_scale");
ADD_GROUP("LOD", "lod_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_distance", "get_lod_min_distance");
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_hysteresis", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_hysteresis", "get_lod_min_hysteresis");
@ -367,12 +339,6 @@ void GeometryInstance::_bind_methods() {
//ADD_SIGNAL( MethodInfo("visibility_changed"));
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_1X);
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_2X);
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_4X);
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_8X);
BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_MAX);
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_OFF);
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_ON);
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
@ -395,7 +361,5 @@ GeometryInstance::GeometryInstance() {
shadow_casting_setting = SHADOW_CASTING_SETTING_ON;
extra_cull_margin = 0;
generate_lightmap = true;
lightmap_scale = LightmapScale::LIGHTMAP_SCALE_1X;
//VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0);
}

View File

@ -91,14 +91,6 @@ public:
FLAG_MAX = VS::INSTANCE_FLAG_MAX,
};
enum LightmapScale {
LIGHTMAP_SCALE_1X,
LIGHTMAP_SCALE_2X,
LIGHTMAP_SCALE_4X,
LIGHTMAP_SCALE_8X,
LIGHTMAP_SCALE_MAX,
};
enum ShadowCastingSetting {
SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF,
SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON,
@ -108,8 +100,6 @@ public:
private:
bool flags[FLAG_MAX];
bool generate_lightmap;
LightmapScale lightmap_scale;
ShadowCastingSetting shadow_casting_setting;
Ref<Material> material_override;
Ref<Material> material_overlay;
@ -131,12 +121,6 @@ public:
void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
ShadowCastingSetting get_cast_shadows_setting() const;
void set_generate_lightmap(bool p_enabled);
bool get_generate_lightmap();
void set_lightmap_scale(LightmapScale p_scale);
LightmapScale get_lightmap_scale() const;
void set_lod_min_distance(float p_dist);
float get_lod_min_distance() const;
@ -164,7 +148,6 @@ public:
};
VARIANT_ENUM_CAST(GeometryInstance::Flags);
VARIANT_ENUM_CAST(GeometryInstance::LightmapScale);
VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting);
#endif

View File

@ -433,21 +433,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
return newmesh;
}
void Mesh::set_lightmap_size_hint(const Vector2 &p_size) {
lightmap_size_hint = p_size;
}
Size2 Mesh::get_lightmap_size_hint() const {
return lightmap_size_hint;
}
void Mesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint);
ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint);
ClassDB::bind_method(D_METHOD("get_aabb"), &Mesh::get_aabb);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint");
ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count);
ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &Mesh::surface_get_arrays);
ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &Mesh::surface_get_blend_shape_arrays);
@ -1362,7 +1350,7 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach
surfaces_tools[i]->commit(Ref<ArrayMesh>((ArrayMesh *)this), lightmap_surfaces[i].format);
}
set_lightmap_size_hint(Size2(size_x, size_y));
//set_lightmap_size_hint(Size2(size_x, size_y));
if (!cached) {
//free stuff

View File

@ -144,8 +144,6 @@ public:
virtual AABB get_aabb() const = 0;
void set_lightmap_size_hint(const Vector2 &p_size);
Size2 get_lightmap_size_hint() const;
void clear_cache() const;
typedef Vector<PoolVector<Vector3>> (*ConvexDecompositionFunc)(const real_t *p_vertices, int p_vertex_count, const uint32_t *p_triangles, int p_triangle_count, int p_max_convex_hulls, Vector<PoolVector<uint32_t>> *r_convex_indices);

View File

@ -135,12 +135,6 @@ public:
SelfList<InstanceBase> dependency_item;
InstanceBase *lightmap_capture;
RID lightmap;
Vector<Color> lightmap_capture_data; //in a array (12 values) to avoid wasting space if unused. Alpha is unused, but needed to send to shader
int lightmap_slice;
Rect2 lightmap_uv_rect;
virtual void base_removed() = 0;
virtual void base_changed(bool p_aabb, bool p_materials) = 0;
InstanceBase() :
@ -153,9 +147,6 @@ public:
layer_mask = 1;
baked_light = false;
redraw_if_visible = false;
lightmap_capture = nullptr;
lightmap_slice = -1;
lightmap_uv_rect = Rect2(0, 0, 1, 1);
on_interpolate_list = false;
on_interpolate_transform_list = false;
interpolated = true;
@ -516,33 +507,6 @@ public:
virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) = 0;
virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) = 0;
/* LIGHTMAP CAPTURE */
struct LightmapCaptureOctree {
enum {
CHILD_EMPTY = 0xFFFFFFFF
};
uint16_t light[6][3]; //anisotropic light
float alpha;
uint32_t children[8];
};
virtual RID lightmap_capture_create() = 0;
virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) = 0;
virtual AABB lightmap_capture_get_bounds(RID p_capture) const = 0;
virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) = 0;
virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const = 0;
virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) = 0;
virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const = 0;
virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) = 0;
virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const = 0;
virtual void lightmap_capture_set_energy(RID p_capture, float p_energy) = 0;
virtual float lightmap_capture_get_energy(RID p_capture) const = 0;
virtual void lightmap_capture_set_interior(RID p_capture, bool p_interior) = 0;
virtual bool lightmap_capture_is_interior(RID p_capture) const = 0;
virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const = 0;
/* PARTICLES */
virtual RID particles_create() = 0;

View File

@ -356,27 +356,6 @@ public:
BIND2(reflection_probe_set_cull_mask, RID, uint32_t)
BIND2(reflection_probe_set_resolution, RID, int)
/* LIGHTMAP CAPTURE */
BIND0R(RID, lightmap_capture_create)
BIND2(lightmap_capture_set_bounds, RID, const AABB &)
BIND1RC(AABB, lightmap_capture_get_bounds, RID)
BIND2(lightmap_capture_set_octree, RID, const PoolVector<uint8_t> &)
BIND1RC(PoolVector<uint8_t>, lightmap_capture_get_octree, RID)
BIND2(lightmap_capture_set_octree_cell_transform, RID, const Transform &)
BIND1RC(Transform, lightmap_capture_get_octree_cell_transform, RID)
BIND2(lightmap_capture_set_octree_cell_subdiv, RID, int)
BIND1RC(int, lightmap_capture_get_octree_cell_subdiv, RID)
BIND2(lightmap_capture_set_energy, RID, float)
BIND1RC(float, lightmap_capture_get_energy, RID)
BIND2(lightmap_capture_set_interior, RID, bool)
BIND1RC(bool, lightmap_capture_is_interior, RID)
/* PARTICLES */
BIND0R(RID, particles_create)
@ -537,7 +516,6 @@ public:
BIND3(instance_set_blend_shape_weight, RID, int, float)
BIND3(instance_set_surface_material, RID, int, RID)
BIND2(instance_set_visible, RID, bool)
BIND5(instance_set_use_lightmap, RID, RID, RID, int, const Rect2 &)
BIND2(instance_set_custom_aabb, RID, AABB)

View File

@ -351,18 +351,6 @@ void *VisualServerScene::_instance_pair(void *p_self, SpatialPartitionID, Instan
geom->reflection_dirty = true;
return E; //this element should make freeing faster
} else if (B->base_type == VS::INSTANCE_LIGHTMAP_CAPTURE && ((1 << A->base_type) & VS::INSTANCE_GEOMETRY_MASK)) {
InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(B->base_data);
InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(A->base_data);
InstanceLightmapCaptureData::PairInfo pinfo;
pinfo.geometry = A;
pinfo.L = geom->lightmap_captures.push_back(B);
List<InstanceLightmapCaptureData::PairInfo>::Element *E = lightmap_capture->geometries.push_back(pinfo);
((VisualServerScene *)p_self)->_instance_queue_update(A, false, false); //need to update capture
return E; //this element should make freeing faster
}
@ -403,16 +391,6 @@ void VisualServerScene::_instance_unpair(void *p_self, SpatialPartitionID, Insta
reflection_probe->geometries.erase(E);
geom->reflection_dirty = true;
} else if (B->base_type == VS::INSTANCE_LIGHTMAP_CAPTURE && ((1 << A->base_type) & VS::INSTANCE_GEOMETRY_MASK)) {
InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(B->base_data);
InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(A->base_data);
List<InstanceLightmapCaptureData::PairInfo>::Element *E = reinterpret_cast<List<InstanceLightmapCaptureData::PairInfo>::Element *>(udata);
geom->lightmap_captures.erase(E->get().L);
lightmap_capture->geometries.erase(E);
((VisualServerScene *)p_self)->_instance_queue_update(A, false, false); //need to update capture
}
}
@ -549,13 +527,6 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) {
reflection_probe_render_list.remove(&reflection_probe->update_list);
}
} break;
case VS::INSTANCE_LIGHTMAP_CAPTURE: {
InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(instance->base_data);
//erase dependencies, since no longer a lightmap
while (lightmap_capture->users.front()) {
instance_set_use_lightmap(lightmap_capture->users.front()->get()->self, RID(), RID(), -1, Rect2(0, 0, 1, 1));
}
} break;
default: {
}
}
@ -611,11 +582,6 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) {
reflection_probe->instance = VSG::scene_render->reflection_probe_instance_create(p_base);
} break;
case VS::INSTANCE_LIGHTMAP_CAPTURE: {
InstanceLightmapCaptureData *lightmap_capture = memnew(InstanceLightmapCaptureData);
instance->base_data = lightmap_capture;
//lightmap_capture->instance = VSG::scene_render->lightmap_capture_instance_create(p_base);
} break;
default: {
}
}
@ -1054,12 +1020,6 @@ void VisualServerScene::instance_set_visible(RID p_instance, bool p_visible) {
instance->scenario->sps->set_pairable(instance, p_visible, 1 << VS::INSTANCE_REFLECTION_PROBE, p_visible ? VS::INSTANCE_GEOMETRY_MASK : 0);
}
} break;
case VS::INSTANCE_LIGHTMAP_CAPTURE: {
if (instance->spatial_partition_id && instance->scenario) {
instance->scenario->sps->set_pairable(instance, p_visible, 1 << VS::INSTANCE_LIGHTMAP_CAPTURE, p_visible ? VS::INSTANCE_GEOMETRY_MASK : 0);
}
} break;
default: {
// if we haven't called set_pairable, we STILL need to do a collision check
@ -1074,36 +1034,6 @@ inline bool is_geometry_instance(VisualServer::InstanceType p_type) {
return p_type == VS::INSTANCE_MESH || p_type == VS::INSTANCE_MULTIMESH || p_type == VS::INSTANCE_PARTICLES || p_type == VS::INSTANCE_IMMEDIATE;
}
void VisualServerScene::instance_set_use_lightmap(RID p_instance, RID p_lightmap_instance, RID p_lightmap, int p_lightmap_slice, const Rect2 &p_lightmap_uv_rect) {
Instance *instance = instance_owner.get(p_instance);
ERR_FAIL_COND(!instance);
instance->lightmap = RID();
instance->lightmap_slice = -1;
instance->lightmap_uv_rect = Rect2(0, 0, 1, 1);
instance->baked_light = false;
if (instance->lightmap_capture) {
InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(((Instance *)instance->lightmap_capture)->base_data);
lightmap_capture->users.erase(instance);
instance->lightmap_capture = nullptr;
}
if (p_lightmap_instance.is_valid()) {
Instance *lightmap_instance = instance_owner.get(p_lightmap_instance);
ERR_FAIL_COND(!lightmap_instance);
ERR_FAIL_COND(lightmap_instance->base_type != VS::INSTANCE_LIGHTMAP_CAPTURE);
instance->lightmap_capture = lightmap_instance;
InstanceLightmapCaptureData *lightmap_capture = static_cast<InstanceLightmapCaptureData *>(((Instance *)instance->lightmap_capture)->base_data);
lightmap_capture->users.insert(instance);
instance->lightmap = p_lightmap;
instance->lightmap_slice = p_lightmap_slice;
instance->lightmap_uv_rect = p_lightmap_uv_rect;
instance->baked_light = true;
}
}
void VisualServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb) {
Instance *instance = instance_owner.get(p_instance);
ERR_FAIL_COND(!instance);
@ -1871,13 +1801,6 @@ void VisualServerScene::_update_instance(Instance *p_instance) {
VSG::storage->particles_set_emission_transform(p_instance->base, *instance_xform);
}
if (p_instance->base_type == VS::INSTANCE_LIGHTMAP_CAPTURE) {
InstanceLightmapCaptureData *capture = static_cast<InstanceLightmapCaptureData *>(p_instance->base_data);
for (List<InstanceLightmapCaptureData::PairInfo>::Element *E = capture->geometries.front(); E; E = E->next()) {
_instance_queue_update(E->get().geometry, false, true);
}
}
if (p_instance->aabb.has_no_surface()) {
return;
}
@ -1892,15 +1815,6 @@ void VisualServerScene::_update_instance(Instance *p_instance) {
light->shadow_dirty = true;
}
}
if (!p_instance->lightmap_capture && geom->lightmap_captures.size()) {
//affected by lightmap captures, must update capture info!
_update_instance_lightmap_captures(p_instance);
} else {
if (!p_instance->lightmap_capture_data.empty()) {
p_instance->lightmap_capture_data.resize(0); //not in use, clear capture data
}
}
}
p_instance->mirror = instance_xform->basis.determinant() < 0.0;
@ -1920,7 +1834,7 @@ void VisualServerScene::_update_instance(Instance *p_instance) {
uint32_t pairable_mask = 0;
bool pairable = false;
if (p_instance->base_type == VS::INSTANCE_LIGHT || p_instance->base_type == VS::INSTANCE_REFLECTION_PROBE || p_instance->base_type == VS::INSTANCE_LIGHTMAP_CAPTURE) {
if (p_instance->base_type == VS::INSTANCE_LIGHT || p_instance->base_type == VS::INSTANCE_REFLECTION_PROBE) {
pairable_mask = p_instance->visible ? VS::INSTANCE_GEOMETRY_MASK : 0;
pairable = true;
}
@ -1990,10 +1904,6 @@ void VisualServerScene::_update_instance_aabb(Instance *p_instance) {
case VisualServer::INSTANCE_REFLECTION_PROBE: {
new_aabb = VSG::storage->reflection_probe_get_aabb(p_instance->base);
} break;
case VisualServer::INSTANCE_LIGHTMAP_CAPTURE: {
new_aabb = VSG::storage->lightmap_capture_get_bounds(p_instance->base);
} break;
default: {
}
@ -2168,246 +2078,6 @@ void VisualServerScene::_update_dirty_instance(Instance *p_instance) {
p_instance->update_materials = false;
}
_FORCE_INLINE_ static void _light_capture_sample_octree(const RasterizerStorage::LightmapCaptureOctree *p_octree, int p_cell_subdiv, const Vector3 &p_pos, const Vector3 &p_dir, float p_level, Vector3 &r_color, float &r_alpha) {
static const Vector3 aniso_normal[6] = {
Vector3(-1, 0, 0),
Vector3(1, 0, 0),
Vector3(0, -1, 0),
Vector3(0, 1, 0),
Vector3(0, 0, -1),
Vector3(0, 0, 1)
};
int size = 1 << (p_cell_subdiv - 1);
int clamp_v = size - 1;
//first of all, clamp
Vector3 pos;
pos.x = CLAMP(p_pos.x, 0, clamp_v);
pos.y = CLAMP(p_pos.y, 0, clamp_v);
pos.z = CLAMP(p_pos.z, 0, clamp_v);
float level = (p_cell_subdiv - 1) - p_level;
int target_level;
float level_filter;
if (level <= 0.0) {
level_filter = 0;
target_level = 0;
} else {
target_level = Math::ceil(level);
level_filter = target_level - level;
}
Vector3 color[2][8];
float alpha[2][8];
memset(alpha, 0, sizeof(float) * 2 * 8);
//find cell at given level first
for (int c = 0; c < 2; c++) {
int current_level = MAX(0, target_level - c);
int level_cell_size = (1 << (p_cell_subdiv - 1)) >> current_level;
for (int n = 0; n < 8; n++) {
int x = int(pos.x);
int y = int(pos.y);
int z = int(pos.z);
if (n & 1) {
x += level_cell_size;
}
if (n & 2) {
y += level_cell_size;
}
if (n & 4) {
z += level_cell_size;
}
int ofs_x = 0;
int ofs_y = 0;
int ofs_z = 0;
x = CLAMP(x, 0, clamp_v);
y = CLAMP(y, 0, clamp_v);
z = CLAMP(z, 0, clamp_v);
int half = size / 2;
uint32_t cell = 0;
for (int i = 0; i < current_level; i++) {
const RasterizerStorage::LightmapCaptureOctree *bc = &p_octree[cell];
int child = 0;
if (x >= ofs_x + half) {
child |= 1;
ofs_x += half;
}
if (y >= ofs_y + half) {
child |= 2;
ofs_y += half;
}
if (z >= ofs_z + half) {
child |= 4;
ofs_z += half;
}
cell = bc->children[child];
if (cell == RasterizerStorage::LightmapCaptureOctree::CHILD_EMPTY) {
break;
}
half >>= 1;
}
if (cell == RasterizerStorage::LightmapCaptureOctree::CHILD_EMPTY) {
alpha[c][n] = 0;
} else {
alpha[c][n] = p_octree[cell].alpha;
for (int i = 0; i < 6; i++) {
//anisotropic read light
float amount = p_dir.dot(aniso_normal[i]);
if (amount < 0) {
amount = 0;
}
color[c][n].x += p_octree[cell].light[i][0] / 1024.0 * amount;
color[c][n].y += p_octree[cell].light[i][1] / 1024.0 * amount;
color[c][n].z += p_octree[cell].light[i][2] / 1024.0 * amount;
}
}
//print_line("\tlev " + itos(c) + " - " + itos(n) + " alpha: " + rtos(cells[test_cell].alpha) + " col: " + color[c][n]);
}
}
float target_level_size = size >> target_level;
Vector3 pos_fract[2];
pos_fract[0].x = Math::fmod(pos.x, target_level_size) / target_level_size;
pos_fract[0].y = Math::fmod(pos.y, target_level_size) / target_level_size;
pos_fract[0].z = Math::fmod(pos.z, target_level_size) / target_level_size;
target_level_size = size >> MAX(0, target_level - 1);
pos_fract[1].x = Math::fmod(pos.x, target_level_size) / target_level_size;
pos_fract[1].y = Math::fmod(pos.y, target_level_size) / target_level_size;
pos_fract[1].z = Math::fmod(pos.z, target_level_size) / target_level_size;
float alpha_interp[2];
Vector3 color_interp[2];
for (int i = 0; i < 2; i++) {
Vector3 color_x00 = color[i][0].linear_interpolate(color[i][1], pos_fract[i].x);
Vector3 color_xy0 = color[i][2].linear_interpolate(color[i][3], pos_fract[i].x);
Vector3 blend_z0 = color_x00.linear_interpolate(color_xy0, pos_fract[i].y);
Vector3 color_x0z = color[i][4].linear_interpolate(color[i][5], pos_fract[i].x);
Vector3 color_xyz = color[i][6].linear_interpolate(color[i][7], pos_fract[i].x);
Vector3 blend_z1 = color_x0z.linear_interpolate(color_xyz, pos_fract[i].y);
color_interp[i] = blend_z0.linear_interpolate(blend_z1, pos_fract[i].z);
float alpha_x00 = Math::lerp(alpha[i][0], alpha[i][1], pos_fract[i].x);
float alpha_xy0 = Math::lerp(alpha[i][2], alpha[i][3], pos_fract[i].x);
float alpha_z0 = Math::lerp(alpha_x00, alpha_xy0, pos_fract[i].y);
float alpha_x0z = Math::lerp(alpha[i][4], alpha[i][5], pos_fract[i].x);
float alpha_xyz = Math::lerp(alpha[i][6], alpha[i][7], pos_fract[i].x);
float alpha_z1 = Math::lerp(alpha_x0z, alpha_xyz, pos_fract[i].y);
alpha_interp[i] = Math::lerp(alpha_z0, alpha_z1, pos_fract[i].z);
}
r_color = color_interp[0].linear_interpolate(color_interp[1], level_filter);
r_alpha = Math::lerp(alpha_interp[0], alpha_interp[1], level_filter);
//print_line("pos: " + p_posf + " level " + rtos(p_level) + " down to " + itos(target_level) + "." + rtos(level_filter) + " color " + r_color + " alpha " + rtos(r_alpha));
}
_FORCE_INLINE_ static Color _light_capture_voxel_cone_trace(const RasterizerStorage::LightmapCaptureOctree *p_octree, const Vector3 &p_pos, const Vector3 &p_dir, float p_aperture, int p_cell_subdiv) {
float bias = 0.0; //no need for bias here
float max_distance = (Vector3(1, 1, 1) * (1 << (p_cell_subdiv - 1))).length();
float dist = bias;
float alpha = 0.0;
Vector3 color;
Vector3 scolor;
float salpha;
while (dist < max_distance && alpha < 0.95) {
float diameter = MAX(1.0, 2.0 * p_aperture * dist);
_light_capture_sample_octree(p_octree, p_cell_subdiv, p_pos + dist * p_dir, p_dir, log2(diameter), scolor, salpha);
float a = (1.0 - alpha);
color += scolor * a;
alpha += a * salpha;
dist += diameter * 0.5;
}
return Color(color.x, color.y, color.z, alpha);
}
void VisualServerScene::_update_instance_lightmap_captures(Instance *p_instance) {
InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(p_instance->base_data);
static const Vector3 cone_traces[12] = {
Vector3(0, 0, 1),
Vector3(0.866025, 0, 0.5),
Vector3(0.267617, 0.823639, 0.5),
Vector3(-0.700629, 0.509037, 0.5),
Vector3(-0.700629, -0.509037, 0.5),
Vector3(0.267617, -0.823639, 0.5),
Vector3(0, 0, -1),
Vector3(0.866025, 0, -0.5),
Vector3(0.267617, 0.823639, -0.5),
Vector3(-0.700629, 0.509037, -0.5),
Vector3(-0.700629, -0.509037, -0.5),
Vector3(0.267617, -0.823639, -0.5)
};
float cone_aperture = 0.577; // tan(angle) 60 degrees
if (p_instance->lightmap_capture_data.empty()) {
p_instance->lightmap_capture_data.resize(12);
}
//print_line("update captures for pos: " + p_instance->transform.origin);
for (int i = 0; i < 12; i++) {
new (&p_instance->lightmap_capture_data.ptrw()[i]) Color;
}
bool interior = true;
//this could use some sort of blending..
for (List<Instance *>::Element *E = geom->lightmap_captures.front(); E; E = E->next()) {
const PoolVector<RasterizerStorage::LightmapCaptureOctree> *octree = VSG::storage->lightmap_capture_get_octree_ptr(E->get()->base);
//print_line("octree size: " + itos(octree->size()));
if (octree->size() == 0) {
continue;
}
Transform to_cell_xform = VSG::storage->lightmap_capture_get_octree_cell_transform(E->get()->base);
int cell_subdiv = VSG::storage->lightmap_capture_get_octree_cell_subdiv(E->get()->base);
to_cell_xform = to_cell_xform * E->get()->transform.affine_inverse();
PoolVector<RasterizerStorage::LightmapCaptureOctree>::Read octree_r = octree->read();
Vector3 pos = to_cell_xform.xform(p_instance->transform.origin);
const float capture_energy = VSG::storage->lightmap_capture_get_energy(E->get()->base);
interior = interior && VSG::storage->lightmap_capture_is_interior(E->get()->base);
for (int i = 0; i < 12; i++) {
Vector3 dir = to_cell_xform.basis.xform(cone_traces[i]).normalized();
Color capture = _light_capture_voxel_cone_trace(octree_r.ptr(), pos, dir, cone_aperture, cell_subdiv);
capture.r *= capture_energy;
capture.g *= capture_energy;
capture.b *= capture_energy;
p_instance->lightmap_capture_data.write[i] += capture;
}
}
p_instance->lightmap_capture_data.write[0].a = interior ? 0.0f : 1.0f;
}
bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario) {
InstanceLightData *light = static_cast<InstanceLightData *>(p_instance->base_data);
@ -3333,7 +3003,6 @@ bool VisualServerScene::free(RID p_rid) {
}
}
instance_set_use_lightmap(p_rid, RID(), RID(), -1, Rect2(0, 0, 1, 1));
instance_set_scenario(p_rid, RID());
instance_set_base(p_rid, RID());
instance_geometry_set_material_override(p_rid, RID());

View File

@ -423,8 +423,6 @@ public:
List<Instance *> reflection_probes;
bool reflection_dirty;
List<Instance *> lightmap_captures;
InstanceGeometryData() {
lighting_dirty = true;
reflection_dirty = true;
@ -485,19 +483,6 @@ public:
}
};
struct InstanceLightmapCaptureData : public InstanceBaseData {
struct PairInfo {
List<Instance *>::Element *L; //iterator in geometry
Instance *geometry;
};
List<PairInfo> geometries;
Set<Instance *> users;
InstanceLightmapCaptureData() {
}
};
int instance_cull_count;
Instance *instance_cull_result[MAX_INSTANCE_CULL];
Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps
@ -522,7 +507,6 @@ public:
virtual void instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight);
virtual void instance_set_surface_material(RID p_instance, int p_surface, RID p_material);
virtual void instance_set_visible(RID p_instance, bool p_visible);
virtual void instance_set_use_lightmap(RID p_instance, RID p_lightmap_instance, RID p_lightmap, int p_lightmap_slice, const Rect2 &p_lightmap_uv_rect);
virtual void instance_set_custom_aabb(RID p_instance, AABB p_aabb);
@ -721,7 +705,6 @@ public:
_FORCE_INLINE_ void _update_instance(Instance *p_instance);
_FORCE_INLINE_ void _update_instance_aabb(Instance *p_instance);
_FORCE_INLINE_ void _update_dirty_instance(Instance *p_instance);
_FORCE_INLINE_ void _update_instance_lightmap_captures(Instance *p_instance);
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario);

View File

@ -158,7 +158,6 @@ void VisualServerWrapMT::finish() {
omni_light_free_cached_ids();
spot_light_free_cached_ids();
reflection_probe_free_cached_ids();
lightmap_capture_free_cached_ids();
particles_free_cached_ids();
camera_free_cached_ids();
viewport_free_cached_ids();

View File

@ -286,24 +286,6 @@ public:
FUNC2(reflection_probe_set_cull_mask, RID, uint32_t)
FUNC2(reflection_probe_set_resolution, RID, int)
/* LIGHTMAP CAPTURE */
FUNCRID(lightmap_capture)
FUNC2(lightmap_capture_set_bounds, RID, const AABB &)
FUNC1RC(AABB, lightmap_capture_get_bounds, RID)
FUNC2(lightmap_capture_set_octree, RID, const PoolVector<uint8_t> &)
FUNC1RC(PoolVector<uint8_t>, lightmap_capture_get_octree, RID)
FUNC2(lightmap_capture_set_octree_cell_transform, RID, const Transform &)
FUNC1RC(Transform, lightmap_capture_get_octree_cell_transform, RID)
FUNC2(lightmap_capture_set_octree_cell_subdiv, RID, int)
FUNC1RC(int, lightmap_capture_get_octree_cell_subdiv, RID)
FUNC2(lightmap_capture_set_energy, RID, float)
FUNC1RC(float, lightmap_capture_get_energy, RID)
FUNC2(lightmap_capture_set_interior, RID, bool)
FUNC1RC(bool, lightmap_capture_is_interior, RID)
/* PARTICLES */
FUNCRID(particles)
@ -452,7 +434,6 @@ public:
FUNC3(instance_set_blend_shape_weight, RID, int, float)
FUNC3(instance_set_surface_material, RID, int, RID)
FUNC2(instance_set_visible, RID, bool)
FUNC5(instance_set_use_lightmap, RID, RID, RID, int, const Rect2 &)
FUNC2(instance_set_custom_aabb, RID, AABB)

View File

@ -1990,19 +1990,6 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &VisualServer::reflection_probe_set_enable_shadows);
ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &VisualServer::reflection_probe_set_cull_mask);
ClassDB::bind_method(D_METHOD("lightmap_capture_create"), &VisualServer::lightmap_capture_create);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &VisualServer::lightmap_capture_set_bounds);
ClassDB::bind_method(D_METHOD("lightmap_capture_get_bounds", "capture"), &VisualServer::lightmap_capture_get_bounds);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree", "capture", "octree"), &VisualServer::lightmap_capture_set_octree);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_transform", "capture", "xform"), &VisualServer::lightmap_capture_set_octree_cell_transform);
ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_transform", "capture"), &VisualServer::lightmap_capture_get_octree_cell_transform);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_subdiv", "capture", "subdiv"), &VisualServer::lightmap_capture_set_octree_cell_subdiv);
ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_subdiv", "capture"), &VisualServer::lightmap_capture_get_octree_cell_subdiv);
ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree", "capture"), &VisualServer::lightmap_capture_get_octree);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_energy", "capture", "energy"), &VisualServer::lightmap_capture_set_energy);
ClassDB::bind_method(D_METHOD("lightmap_capture_get_energy", "capture"), &VisualServer::lightmap_capture_get_energy);
ClassDB::bind_method(D_METHOD("lightmap_capture_set_interior", "capture", "interior"), &VisualServer::lightmap_capture_set_interior);
ClassDB::bind_method(D_METHOD("lightmap_capture_is_interior", "capture"), &VisualServer::lightmap_capture_is_interior);
#endif
ClassDB::bind_method(D_METHOD("particles_create"), &VisualServer::particles_create);
ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &VisualServer::particles_set_emitting);
@ -2112,7 +2099,6 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &VisualServer::instance_set_blend_shape_weight);
ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &VisualServer::instance_set_surface_material);
ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &VisualServer::instance_set_visible);
ClassDB::bind_method(D_METHOD("instance_set_use_lightmap", "instance", "lightmap_instance", "lightmap", "lightmap_slice", "lightmap_uv_rect"), &VisualServer::instance_set_use_lightmap, DEFVAL(-1), DEFVAL(Rect2(0, 0, 1, 1)));
ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &VisualServer::instance_set_custom_aabb);
ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &VisualServer::instance_attach_skeleton);
ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &VisualServer::instance_set_exterior);
@ -2400,7 +2386,6 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP_CAPTURE);
BIND_ENUM_CONSTANT(INSTANCE_MAX);
BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);

View File

@ -526,22 +526,6 @@ public:
virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) = 0;
virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution) = 0;
/* LIGHTMAP CAPTURE */
virtual RID lightmap_capture_create() = 0;
virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) = 0;
virtual AABB lightmap_capture_get_bounds(RID p_capture) const = 0;
virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) = 0;
virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) = 0;
virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const = 0;
virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) = 0;
virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const = 0;
virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const = 0;
virtual void lightmap_capture_set_energy(RID p_capture, float p_energy) = 0;
virtual float lightmap_capture_get_energy(RID p_capture) const = 0;
virtual void lightmap_capture_set_interior(RID p_capture, bool p_interior) = 0;
virtual bool lightmap_capture_is_interior(RID p_capture) const = 0;
/* PARTICLES API */
virtual RID particles_create() = 0;
@ -813,7 +797,6 @@ public:
INSTANCE_PARTICLES,
INSTANCE_LIGHT,
INSTANCE_REFLECTION_PROBE,
INSTANCE_LIGHTMAP_CAPTURE,
INSTANCE_MAX,
INSTANCE_GEOMETRY_MASK = (1 << INSTANCE_MESH) | (1 << INSTANCE_MULTIMESH) | (1 << INSTANCE_IMMEDIATE) | (1 << INSTANCE_PARTICLES)
@ -834,8 +817,6 @@ public:
virtual void instance_set_surface_material(RID p_instance, int p_surface, RID p_material) = 0;
virtual void instance_set_visible(RID p_instance, bool p_visible) = 0;
virtual void instance_set_use_lightmap(RID p_instance, RID p_lightmap_instance, RID p_lightmap, int p_lightmap_slice, const Rect2 &p_lightmap_uv_rect) = 0;
virtual void instance_set_custom_aabb(RID p_instance, AABB aabb) = 0;
virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton) = 0;