summaryrefslogtreecommitdiff
path: root/modules/lightmapper_rd
diff options
context:
space:
mode:
Diffstat (limited to 'modules/lightmapper_rd')
-rw-r--r--modules/lightmapper_rd/lightmapper_rd.cpp129
-rw-r--r--modules/lightmapper_rd/lightmapper_rd.h4
-rw-r--r--modules/lightmapper_rd/lm_blendseams.glsl4
-rw-r--r--modules/lightmapper_rd/lm_compute.glsl48
-rw-r--r--modules/lightmapper_rd/lm_raster.glsl4
-rw-r--r--modules/lightmapper_rd/register_types.cpp15
-rw-r--r--modules/lightmapper_rd/register_types.h10
7 files changed, 121 insertions, 93 deletions
diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp
index 37e969db4d..214c60091c 100644
--- a/modules/lightmapper_rd/lightmapper_rd.cpp
+++ b/modules/lightmapper_rd/lightmapper_rd.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "lightmapper_rd.h"
+
#include "core/config/project_settings.h"
#include "core/math/geometry_2d.h"
#include "lm_blendseams.glsl.gen.h"
@@ -174,7 +175,7 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_
}
if (p_step_function) {
- p_step_function(0.1, TTR("Determining optimal atlas size"), p_bake_userdata, true);
+ p_step_function(0.1, RTR("Determining optimal atlas size"), p_bake_userdata, true);
}
atlas_size = Size2i(max, max);
@@ -243,7 +244,7 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_
emission_images.resize(atlas_slices);
if (p_step_function) {
- p_step_function(0.2, TTR("Blitting albedo and emission"), p_bake_userdata, true);
+ p_step_function(0.2, RTR("Blitting albedo and emission"), p_bake_userdata, true);
}
for (int i = 0; i < atlas_slices; i++) {
@@ -295,7 +296,7 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i
for (int m_i = 0; m_i < mesh_instances.size(); m_i++) {
if (p_step_function) {
float p = float(m_i + 1) / mesh_instances.size() * 0.1;
- p_step_function(0.3 + p, vformat(TTR("Plotting mesh into acceleration structure %d/%d"), m_i + 1, mesh_instances.size()), p_bake_userdata, false);
+ p_step_function(0.3 + p, vformat(RTR("Plotting mesh into acceleration structure %d/%d"), m_i + 1, mesh_instances.size()), p_bake_userdata, false);
}
HashMap<Edge, EdgeUV2, EdgeHash> edges;
@@ -409,7 +410,7 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i
seams.sort();
if (p_step_function) {
- p_step_function(0.4, TTR("Optimizing acceleration structure"), p_bake_userdata, true);
+ p_step_function(0.4, RTR("Optimizing acceleration structure"), p_bake_userdata, true);
}
//fill list of triangles in grid
@@ -618,14 +619,14 @@ LightmapperRD::BakeError LightmapperRD::_dilate(RenderingDevice *rd, Ref<RDShade
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 0;
- u.ids.push_back(dest_light_tex);
+ u.append_id(dest_light_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 1;
- u.ids.push_back(source_light_tex);
+ u.append_id(source_light_tex);
uniforms.push_back(u);
}
}
@@ -668,7 +669,7 @@ LightmapperRD::BakeError LightmapperRD::_dilate(RenderingDevice *rd, Ref<RDShade
LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata) {
if (p_step_function) {
- p_step_function(0.0, TTR("Begin Bake"), p_bake_userdata, true);
+ p_step_function(0.0, RTR("Begin Bake"), p_bake_userdata, true);
}
bake_textures.clear();
int grid_size = 128;
@@ -775,11 +776,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
} else {
panorama_tex.instantiate();
panorama_tex->create(8, 8, false, Image::FORMAT_RGBAF);
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- panorama_tex->set_pixel(i, j, Color(0, 0, 0, 1));
- }
- }
+ panorama_tex->fill(Color(0, 0, 0, 1));
}
RD::TextureFormat tfp;
@@ -823,7 +820,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
_create_acceleration_structures(rd, atlas_size, atlas_slices, bounds, grid_size, probe_positions, p_generate_probes, slice_triangle_count, slice_seam_count, vertex_buffer, triangle_buffer, lights_buffer, triangle_cell_indices_buffer, probe_positions_buffer, grid_texture, seams_buffer, p_step_function, p_bake_userdata);
if (p_step_function) {
- p_step_function(0.47, TTR("Preparing shaders"), p_bake_userdata, true);
+ p_step_function(0.47, RTR("Preparing shaders"), p_bake_userdata, true);
}
//shaders
@@ -860,70 +857,70 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 1;
- u.ids.push_back(vertex_buffer);
+ u.append_id(vertex_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 2;
- u.ids.push_back(triangle_buffer);
+ u.append_id(triangle_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 3;
- u.ids.push_back(triangle_cell_indices_buffer);
+ u.append_id(triangle_cell_indices_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 4;
- u.ids.push_back(lights_buffer);
+ u.append_id(lights_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 5;
- u.ids.push_back(seams_buffer);
+ u.append_id(seams_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 6;
- u.ids.push_back(probe_positions_buffer);
+ u.append_id(probe_positions_buffer);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 7;
- u.ids.push_back(grid_texture);
+ u.append_id(grid_texture);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 8;
- u.ids.push_back(albedo_array_tex);
+ u.append_id(albedo_array_tex);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 9;
- u.ids.push_back(emission_array_tex);
+ u.append_id(emission_array_tex);
base_uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_SAMPLER;
u.binding = 10;
- u.ids.push_back(sampler);
+ u.append_id(sampler);
base_uniforms.push_back(u);
}
}
@@ -1031,17 +1028,17 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
push_constant.atlas_slice = 0;
push_constant.region_ofs[0] = 0;
push_constant.region_ofs[1] = 0;
- push_constant.environment_xform[0] = p_environment_transform.elements[0][0];
- push_constant.environment_xform[1] = p_environment_transform.elements[1][0];
- push_constant.environment_xform[2] = p_environment_transform.elements[2][0];
+ push_constant.environment_xform[0] = p_environment_transform.rows[0][0];
+ push_constant.environment_xform[1] = p_environment_transform.rows[1][0];
+ push_constant.environment_xform[2] = p_environment_transform.rows[2][0];
push_constant.environment_xform[3] = 0;
- push_constant.environment_xform[4] = p_environment_transform.elements[0][1];
- push_constant.environment_xform[5] = p_environment_transform.elements[1][1];
- push_constant.environment_xform[6] = p_environment_transform.elements[2][1];
+ push_constant.environment_xform[4] = p_environment_transform.rows[0][1];
+ push_constant.environment_xform[5] = p_environment_transform.rows[1][1];
+ push_constant.environment_xform[6] = p_environment_transform.rows[2][1];
push_constant.environment_xform[7] = 0;
- push_constant.environment_xform[8] = p_environment_transform.elements[0][2];
- push_constant.environment_xform[9] = p_environment_transform.elements[1][2];
- push_constant.environment_xform[10] = p_environment_transform.elements[2][2];
+ push_constant.environment_xform[8] = p_environment_transform.rows[0][2];
+ push_constant.environment_xform[9] = p_environment_transform.rows[1][2];
+ push_constant.environment_xform[10] = p_environment_transform.rows[2][2];
push_constant.environment_xform[11] = 0;
}
@@ -1050,7 +1047,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
rd->sync();
if (p_step_function) {
- p_step_function(0.49, TTR("Un-occluding geometry"), p_bake_userdata, true);
+ p_step_function(0.49, RTR("Un-occluding geometry"), p_bake_userdata, true);
}
/* UNOCCLUDE */
@@ -1061,14 +1058,14 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 0;
- u.ids.push_back(position_tex);
+ u.append_id(position_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 1;
- u.ids.push_back(unocclude_tex); //will be unused
+ u.append_id(unocclude_tex); //will be unused
uniforms.push_back(u);
}
}
@@ -1090,7 +1087,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
}
if (p_step_function) {
- p_step_function(0.5, TTR("Plot direct lighting"), p_bake_userdata, true);
+ p_step_function(0.5, RTR("Plot direct lighting"), p_bake_userdata, true);
}
/* PRIMARY (direct) LIGHT PASS */
@@ -1101,42 +1098,42 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 0;
- u.ids.push_back(light_source_tex);
+ u.append_id(light_source_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 1;
- u.ids.push_back(light_dest_tex); //will be unused
+ u.append_id(light_dest_tex); //will be unused
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 2;
- u.ids.push_back(position_tex);
+ u.append_id(position_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 3;
- u.ids.push_back(normal_tex);
+ u.append_id(normal_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 4;
- u.ids.push_back(light_accum_tex);
+ u.append_id(light_accum_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 5;
- u.ids.push_back(light_primary_dynamic_tex);
+ u.append_id(light_primary_dynamic_tex);
uniforms.push_back(u);
}
}
@@ -1170,7 +1167,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
/* SECONDARY (indirect) LIGHT PASS(ES) */
if (p_step_function) {
- p_step_function(0.6, TTR("Integrate indirect lighting"), p_bake_userdata, true);
+ p_step_function(0.6, RTR("Integrate indirect lighting"), p_bake_userdata, true);
}
if (p_bounces > 0) {
@@ -1180,57 +1177,57 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 0;
- u.ids.push_back(light_dest_tex);
+ u.append_id(light_dest_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 1;
- u.ids.push_back(light_source_tex);
+ u.append_id(light_source_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 2;
- u.ids.push_back(position_tex);
+ u.append_id(position_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 3;
- u.ids.push_back(normal_tex);
+ u.append_id(normal_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 4;
- u.ids.push_back(light_accum_tex);
+ u.append_id(light_accum_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
u.binding = 5;
- u.ids.push_back(unocclude_tex); //reuse unocclude tex
+ u.append_id(unocclude_tex); //reuse unocclude tex
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 6;
- u.ids.push_back(light_environment_tex);
+ u.append_id(light_environment_tex);
uniforms.push_back(u);
}
}
RID secondary_uniform_set[2];
secondary_uniform_set[0] = rd->uniform_set_create(uniforms, compute_shader_secondary, 1);
- uniforms.write[0].ids.write[0] = light_source_tex;
- uniforms.write[1].ids.write[0] = light_dest_tex;
+ uniforms.write[0].set_id(0, light_source_tex);
+ uniforms.write[1].set_id(0, light_dest_tex);
secondary_uniform_set[1] = rd->uniform_set_create(uniforms, compute_shader_secondary, 1);
switch (p_quality) {
@@ -1248,7 +1245,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
} break;
}
- push_constant.ray_count = CLAMP(push_constant.ray_count, 16, 8192);
+ push_constant.ray_count = CLAMP(push_constant.ray_count, 16u, 8192u);
int max_region_size = nearest_power_of_2_templated(int(GLOBAL_GET("rendering/lightmapping/bake_performance/region_size")));
int max_rays = GLOBAL_GET("rendering/lightmapping/bake_performance/max_rays_per_pass");
@@ -1302,7 +1299,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
int total = (atlas_slices * x_regions * y_regions * ray_iterations);
int percent = count * 100 / total;
float p = float(count) / total * 0.1;
- p_step_function(0.6 + p, vformat(TTR("Bounce %d/%d: Integrate indirect lighting %d%%"), b + 1, p_bounces, percent), p_bake_userdata, false);
+ p_step_function(0.6 + p, vformat(RTR("Bounce %d/%d: Integrate indirect lighting %d%%"), b + 1, p_bounces, percent), p_bake_userdata, false);
}
}
}
@@ -1327,7 +1324,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
light_probe_buffer = rd->storage_buffer_create(sizeof(float) * 4 * 9 * probe_positions.size());
if (p_step_function) {
- p_step_function(0.7, TTR("Baking lightprobes"), p_bake_userdata, true);
+ p_step_function(0.7, RTR("Baking lightprobes"), p_bake_userdata, true);
}
Vector<RD::Uniform> uniforms;
@@ -1336,28 +1333,28 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
u.binding = 0;
- u.ids.push_back(light_probe_buffer);
+ u.append_id(light_probe_buffer);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 1;
- u.ids.push_back(light_dest_tex);
+ u.append_id(light_dest_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 2;
- u.ids.push_back(light_primary_dynamic_tex);
+ u.append_id(light_primary_dynamic_tex);
uniforms.push_back(u);
}
{
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 3;
- u.ids.push_back(light_environment_tex);
+ u.append_id(light_environment_tex);
uniforms.push_back(u);
}
}
@@ -1379,7 +1376,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
}
push_constant.atlas_size[0] = probe_positions.size();
- push_constant.ray_count = CLAMP(push_constant.ray_count, 16, 8192);
+ push_constant.ray_count = CLAMP(push_constant.ray_count, 16u, 8192u);
int max_rays = GLOBAL_GET("rendering/lightmapping/bake_performance/max_rays_per_probe_pass");
int ray_iterations = (push_constant.ray_count - 1) / max_rays + 1;
@@ -1402,7 +1399,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
if (p_step_function) {
int percent = i * 100 / ray_iterations;
float p = float(i) / ray_iterations * 0.1;
- p_step_function(0.7 + p, vformat(TTR("Integrating light probes %d%%"), percent), p_bake_userdata, false);
+ p_step_function(0.7 + p, vformat(RTR("Integrating light probes %d%%"), percent), p_bake_userdata, false);
}
}
@@ -1438,7 +1435,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
if (p_use_denoiser) {
if (p_step_function) {
- p_step_function(0.8, TTR("Denoising"), p_bake_userdata, true);
+ p_step_function(0.8, RTR("Denoising"), p_bake_userdata, true);
}
Ref<LightmapDenoiser> denoiser = LightmapDenoiser::create();
@@ -1535,7 +1532,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
RD::Uniform u;
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
u.binding = 0;
- u.ids.push_back(light_accum_tex2);
+ u.append_id(light_accum_tex2);
uniforms.push_back(u);
}
}
@@ -1643,7 +1640,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
}
#endif
if (p_step_function) {
- p_step_function(0.9, TTR("Retrieving textures"), p_bake_userdata, true);
+ p_step_function(0.9, RTR("Retrieving textures"), p_bake_userdata, true);
}
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
diff --git a/modules/lightmapper_rd/lightmapper_rd.h b/modules/lightmapper_rd/lightmapper_rd.h
index 51ab60fc29..503f5f7009 100644
--- a/modules/lightmapper_rd/lightmapper_rd.h
+++ b/modules/lightmapper_rd/lightmapper_rd.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/modules/lightmapper_rd/lm_blendseams.glsl b/modules/lightmapper_rd/lm_blendseams.glsl
index 374c48082e..70164e27c4 100644
--- a/modules/lightmapper_rd/lm_blendseams.glsl
+++ b/modules/lightmapper_rd/lm_blendseams.glsl
@@ -11,7 +11,7 @@ triangles = "#define MODE_TRIANGLES";
#include "lm_common_inc.glsl"
-layout(push_constant, binding = 0, std430) uniform Params {
+layout(push_constant, std430) uniform Params {
uint base_index;
uint slice;
vec2 uv_offset;
@@ -78,7 +78,7 @@ void main() {
#include "lm_common_inc.glsl"
-layout(push_constant, binding = 0, std430) uniform Params {
+layout(push_constant, std430) uniform Params {
uint base_index;
uint slice;
vec2 uv_offset;
diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl
index 158cd960c4..0b6b72a310 100644
--- a/modules/lightmapper_rd/lm_compute.glsl
+++ b/modules/lightmapper_rd/lm_compute.glsl
@@ -70,7 +70,7 @@ layout(rgba16f, set = 1, binding = 0) uniform restrict writeonly image2DArray de
layout(set = 1, binding = 1) uniform texture2DArray source_light;
#endif
-layout(push_constant, binding = 0, std430) uniform Params {
+layout(push_constant, std430) uniform Params {
ivec2 atlas_size; // x used for light probe mode total probes
uint ray_count;
uint ray_to;
@@ -235,19 +235,39 @@ uint trace_ray(vec3 p_from, vec3 p_to
return RAY_MISS;
}
+// https://www.reedbeta.com/blog/hash-functions-for-gpu-rendering/
+uint hash(uint value) {
+ uint state = value * 747796405u + 2891336453u;
+ uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
+ return (word >> 22u) ^ word;
+}
+
+uint random_seed(ivec3 seed) {
+ return hash(seed.x ^ hash(seed.y ^ hash(seed.z)));
+}
+
+// generates a random value in range [0.0, 1.0)
+float randomize(inout uint value) {
+ value = hash(value);
+ return float(value / 4294967296.0);
+}
+
const float PI = 3.14159265f;
-const float GOLDEN_ANGLE = PI * (3.0 - sqrt(5.0));
-
-vec3 vogel_hemisphere(uint p_index, uint p_count, float p_offset) {
- float r = sqrt(float(p_index) + 0.5f) / sqrt(float(p_count));
- float theta = float(p_index) * GOLDEN_ANGLE + p_offset;
- float y = cos(r * PI * 0.5);
- float l = sin(r * PI * 0.5);
- return vec3(l * cos(theta), l * sin(theta), y);
+
+// http://www.realtimerendering.com/raytracinggems/unofficial_RayTracingGems_v1.4.pdf (chapter 15)
+vec3 generate_hemisphere_uniform_direction(inout uint noise) {
+ float noise1 = randomize(noise);
+ float noise2 = randomize(noise) * 2.0 * PI;
+
+ float factor = sqrt(1 - (noise1 * noise1));
+ return vec3(factor * cos(noise2), factor * sin(noise2), noise1);
}
-float quick_hash(vec2 pos) {
- return fract(sin(dot(pos * 19.19, vec2(49.5791, 97.413))) * 49831.189237);
+vec3 generate_hemisphere_cosine_weighted_direction(inout uint noise) {
+ float noise1 = randomize(noise);
+ float noise2 = randomize(noise) * 2.0 * PI;
+
+ return vec3(sqrt(noise1) * cos(noise2), sqrt(noise1) * sin(noise2), sqrt(1.0 - noise1));
}
float get_omni_attenuation(float distance, float inv_range, float decay) {
@@ -404,8 +424,9 @@ void main() {
#endif
vec3 light_average = vec3(0.0);
float active_rays = 0.0;
+ uint noise = random_seed(ivec3(params.ray_from, atlas_pos));
for (uint i = params.ray_from; i < params.ray_to; i++) {
- vec3 ray_dir = normal_mat * vogel_hemisphere(i, params.ray_count, quick_hash(vec2(atlas_pos)));
+ vec3 ray_dir = normal_mat * generate_hemisphere_cosine_weighted_direction(noise);
uint tidx;
vec3 barycentric;
@@ -550,8 +571,9 @@ void main() {
vec4(0.0),
vec4(0.0));
+ uint noise = random_seed(ivec3(params.ray_from, probe_index, 49502741 /* some prime */));
for (uint i = params.ray_from; i < params.ray_to; i++) {
- vec3 ray_dir = vogel_hemisphere(i, params.ray_count, quick_hash(vec2(float(probe_index), 0.0)));
+ vec3 ray_dir = generate_hemisphere_uniform_direction(noise);
if (bool(i & 1)) {
//throw to both sides, so alternate them
ray_dir.z *= -1.0;
diff --git a/modules/lightmapper_rd/lm_raster.glsl b/modules/lightmapper_rd/lm_raster.glsl
index a86968a4f3..875c3e967a 100644
--- a/modules/lightmapper_rd/lm_raster.glsl
+++ b/modules/lightmapper_rd/lm_raster.glsl
@@ -14,7 +14,7 @@ layout(location = 4) flat out uvec3 vertex_indices;
layout(location = 5) flat out vec3 face_normal;
layout(location = 6) flat out uint fragment_action;
-layout(push_constant, binding = 0, std430) uniform Params {
+layout(push_constant, std430) uniform Params {
vec2 atlas_size;
vec2 uv_offset;
vec3 to_cell_size;
@@ -69,7 +69,7 @@ void main() {
#include "lm_common_inc.glsl"
-layout(push_constant, binding = 0, std430) uniform Params {
+layout(push_constant, std430) uniform Params {
vec2 atlas_size;
vec2 uv_offset;
vec3 to_cell_size;
diff --git a/modules/lightmapper_rd/register_types.cpp b/modules/lightmapper_rd/register_types.cpp
index ae9c5fc390..0e0330c1a1 100644
--- a/modules/lightmapper_rd/register_types.cpp
+++ b/modules/lightmapper_rd/register_types.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,11 @@ static Lightmapper *create_lightmapper_rd() {
}
#endif
-void register_lightmapper_rd_types() {
+void initialize_lightmapper_rd_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
GLOBAL_DEF("rendering/lightmapping/bake_quality/low_quality_ray_count", 16);
GLOBAL_DEF("rendering/lightmapping/bake_quality/medium_quality_ray_count", 64);
GLOBAL_DEF("rendering/lightmapping/bake_quality/high_quality_ray_count", 256);
@@ -59,5 +63,8 @@ void register_lightmapper_rd_types() {
#endif
}
-void unregister_lightmapper_rd_types() {
+void uninitialize_lightmapper_rd_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
}
diff --git a/modules/lightmapper_rd/register_types.h b/modules/lightmapper_rd/register_types.h
index 622d6e37a7..42e0ebbf77 100644
--- a/modules/lightmapper_rd/register_types.h
+++ b/modules/lightmapper_rd/register_types.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,9 @@
#ifndef LIGHTMAPPER_RD_REGISTER_TYPES_H
#define LIGHTMAPPER_RD_REGISTER_TYPES_H
-void register_lightmapper_rd_types();
-void unregister_lightmapper_rd_types();
+#include "modules/register_module_types.h"
+
+void initialize_lightmapper_rd_module(ModuleInitializationLevel p_level);
+void uninitialize_lightmapper_rd_module(ModuleInitializationLevel p_level);
#endif // XATLAS_UNWRAP_REGISTER_TYPES_H