summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/baked_lightmap.cpp4
-rw-r--r--scene/3d/camera.cpp5
-rw-r--r--scene/3d/spatial.cpp8
-rw-r--r--scene/3d/voxel_light_baker.cpp74
-rw-r--r--scene/3d/voxel_light_baker.h5
5 files changed, 37 insertions, 59 deletions
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp
index 9a77626296..8c282a31b8 100644
--- a/scene/3d/baked_lightmap.cpp
+++ b/scene/3d/baked_lightmap.cpp
@@ -772,8 +772,8 @@ void BakedLightmap::_bind_methods() {
BakedLightmap::BakedLightmap() {
extents = Vector3(10, 10, 10);
- bake_cell_size = 0.1;
- capture_cell_size = 0.25;
+ bake_cell_size = 0.25;
+ capture_cell_size = 0.5;
bake_quality = BAKE_QUALITY_MEDIUM;
bake_mode = BAKE_MODE_CONE_TRACE;
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index c74abb7e2d..7143310036 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -70,6 +70,9 @@ void Camera::_validate_property(PropertyInfo &p_property) const {
void Camera::_update_camera() {
+ if (!is_inside_tree())
+ return;
+
Transform tr = get_camera_transform();
tr.origin += tr.basis.get_axis(1) * v_offset;
tr.origin += tr.basis.get_axis(0) * h_offset;
@@ -81,7 +84,7 @@ void Camera::_update_camera() {
get_viewport()->_camera_transform_changed_notify();
*/
- if (!is_inside_tree() || get_tree()->is_node_being_edited(this) || !is_current())
+ if (get_tree()->is_node_being_edited(this) || !is_current())
return;
get_viewport()->_camera_transform_changed_notify();
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index d9f88ac693..e890533ab7 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -558,27 +558,27 @@ bool Spatial::is_visible() const {
void Spatial::rotate(const Vector3 &p_normal, float p_radians) {
Transform t = get_transform();
- t.basis.rotate(p_normal, p_radians);
+ t.basis.rotate_local(p_normal, p_radians); //use local rotation here, as it makes more sense here in tree hierarchy
set_transform(t);
}
void Spatial::rotate_x(float p_radians) {
Transform t = get_transform();
- t.basis.rotate(Vector3(1, 0, 0), p_radians);
+ t.basis.rotate_local(Vector3(1, 0, 0), p_radians);
set_transform(t);
}
void Spatial::rotate_y(float p_radians) {
Transform t = get_transform();
- t.basis.rotate(Vector3(0, 1, 0), p_radians);
+ t.basis.rotate_local(Vector3(0, 1, 0), p_radians);
set_transform(t);
}
void Spatial::rotate_z(float p_radians) {
Transform t = get_transform();
- t.basis.rotate(Vector3(0, 0, 1), p_radians);
+ t.basis.rotate_local(Vector3(0, 0, 1), p_radians);
set_transform(t);
}
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp
index bf0f801e32..bd7e52d947 100644
--- a/scene/3d/voxel_light_baker.cpp
+++ b/scene/3d/voxel_light_baker.cpp
@@ -30,11 +30,9 @@
#include "voxel_light_baker.h"
#include "os/os.h"
+#include "os/threaded_array_processor.h"
#include <stdlib.h>
-#ifdef _OPENMP
-#include <omp.h>
-#endif
#define FINDMINMAX(x0, x1, x2, min, max) \
min = max = x0; \
@@ -1689,7 +1687,7 @@ _ALWAYS_INLINE_ uint32_t xorshift32(uint32_t *state) {
return x;
}
-Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal, uint32_t *rng_state) {
+Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal) {
int samples_per_quality[3] = { 48, 128, 512 };
@@ -1711,8 +1709,7 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V
const Light *light = bake_light.ptr();
const Cell *cells = bake_cells.ptr();
- // Prevent false sharing when running on OpenMP
- uint32_t local_rng_state = *rng_state;
+ uint32_t local_rng_state = rand(); //needs to be fixed again
for (int i = 0; i < samples; i++) {
@@ -1796,10 +1793,28 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V
}
// Make sure we don't reset this thread's RNG state
- *rng_state = local_rng_state;
+
return accum / samples;
}
+void VoxelLightBaker::_lightmap_bake_point(uint32_t p_x, LightMap *p_line) {
+
+ LightMap *pixel = &p_line[p_x];
+ if (pixel->pos == Vector3())
+ return;
+ //print_line("pos: " + pixel->pos + " normal " + pixel->normal);
+ switch (bake_mode) {
+ case BAKE_MODE_CONE_TRACE: {
+ pixel->light = _compute_pixel_light_at_pos(pixel->pos, pixel->normal) * energy;
+ } break;
+ case BAKE_MODE_RAY_TRACE: {
+ pixel->light = _compute_ray_trace_at_pos(pixel->pos, pixel->normal) * energy;
+ } break;
+ // pixel->light = Vector3(1, 1, 1);
+ //}
+ }
+}
+
Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh, LightMapData &r_lightmap, bool (*p_bake_time_func)(void *, float, float), void *p_bake_time_ud) {
//transfer light information to a lightmap
@@ -1862,53 +1877,10 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh
volatile int lines = 0;
// make sure our OS-level rng is seeded
- srand(OS::get_singleton()->get_ticks_usec());
-
- // setup an RNG state for each OpenMP thread
- uint32_t threadcount = 1;
- uint32_t threadnum = 0;
-#ifdef _OPENMP
- threadcount = omp_get_max_threads();
-#endif
- Vector<uint32_t> rng_states;
- rng_states.resize(threadcount);
- for (uint32_t i = 0; i < threadcount; i++) {
- do {
- rng_states[i] = rand();
- } while (rng_states[i] == 0);
- }
- uint32_t *rng_states_p = rng_states.ptrw();
for (int i = 0; i < height; i++) {
- //print_line("bake line " + itos(i) + " / " + itos(height));
-#ifdef _OPENMP
-#pragma omp parallel for schedule(dynamic, 1) private(threadnum)
-#endif
- for (int j = 0; j < width; j++) {
-
-#ifdef _OPENMP
- threadnum = omp_get_thread_num();
-#endif
-
- //if (i == 125 && j == 280) {
-
- LightMap *pixel = &lightmap_ptr[i * width + j];
- if (pixel->pos == Vector3())
- continue; //unused, skipe
-
- //print_line("pos: " + pixel->pos + " normal " + pixel->normal);
- switch (bake_mode) {
- case BAKE_MODE_CONE_TRACE: {
- pixel->light = _compute_pixel_light_at_pos(pixel->pos, pixel->normal) * energy;
- } break;
- case BAKE_MODE_RAY_TRACE: {
- pixel->light = _compute_ray_trace_at_pos(pixel->pos, pixel->normal, &rng_states_p[threadnum]) * energy;
- } break;
- // pixel->light = Vector3(1, 1, 1);
- //}
- }
- }
+ thread_process_array(width, this, &VoxelLightBaker::_lightmap_bake_point, &lightmap_ptr[i * width]);
lines = MAX(lines, i); //for multithread
if (p_bake_time_func) {
diff --git a/scene/3d/voxel_light_baker.h b/scene/3d/voxel_light_baker.h
index 7db31f8a67..68e11c356b 100644
--- a/scene/3d/voxel_light_baker.h
+++ b/scene/3d/voxel_light_baker.h
@@ -148,9 +148,12 @@ private:
_FORCE_INLINE_ void _sample_baked_octree_filtered_and_anisotropic(const Vector3 &p_posf, const Vector3 &p_direction, float p_level, Vector3 &r_color, float &r_alpha);
_FORCE_INLINE_ Vector3 _voxel_cone_trace(const Vector3 &p_pos, const Vector3 &p_normal, float p_aperture);
_FORCE_INLINE_ Vector3 _compute_pixel_light_at_pos(const Vector3 &p_pos, const Vector3 &p_normal);
- _FORCE_INLINE_ Vector3 _compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal, uint32_t *rng_state);
+ _FORCE_INLINE_ Vector3 _compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal);
+
+ void _lightmap_bake_point(uint32_t p_x, LightMap *p_line);
public:
+
void begin_bake(int p_subdiv, const AABB &p_bounds);
void plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);
void begin_bake_light(BakeQuality p_quality = BAKE_QUALITY_MEDIUM, BakeMode p_bake_mode = BAKE_MODE_CONE_TRACE, float p_propagation = 0.85, float p_energy = 1);