diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
tree | 2b1c31f45add24085b64425ce440f577424c16a1 /modules/lightmapper_rd | |
parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'modules/lightmapper_rd')
-rw-r--r-- | modules/lightmapper_rd/lightmapper_rd.cpp | 76 | ||||
-rw-r--r-- | modules/lightmapper_rd/lightmapper_rd.h | 31 | ||||
-rw-r--r-- | modules/lightmapper_rd/lm_blendseams.glsl | 2 | ||||
-rw-r--r-- | modules/lightmapper_rd/lm_common_inc.glsl | 7 | ||||
-rw-r--r-- | modules/lightmapper_rd/lm_compute.glsl | 9 | ||||
-rw-r--r-- | modules/lightmapper_rd/lm_raster.glsl | 3 | ||||
-rw-r--r-- | modules/lightmapper_rd/register_types.cpp | 1 |
7 files changed, 77 insertions, 52 deletions
diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 6983c222c0..b55c73e9bc 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* lightmapper_rd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 */ +/* "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. */ +/*************************************************************************/ + #include "lightmapper_rd.h" #include "core/math/geometry.h" #include "core/project_settings.h" @@ -34,6 +64,7 @@ void LightmapperRD::add_directional_light(bool p_static, const Vector3 &p_direct l.size = p_angular_distance; lights.push_back(l); } + void LightmapperRD::add_omni_light(bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_size) { Light l; l.type = LIGHT_TYPE_OMNI; @@ -50,8 +81,8 @@ void LightmapperRD::add_omni_light(bool p_static, const Vector3 &p_position, con l.size = p_size; lights.push_back(l); } -void LightmapperRD::add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size) { +void LightmapperRD::add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size) { Light l; l.type = LIGHT_TYPE_SPOT; l.position[0] = p_position.x; @@ -83,11 +114,9 @@ void LightmapperRD::add_probe(const Vector3 &p_position) { } void LightmapperRD::_plot_triangle_into_triangle_index_list(int p_size, const Vector3i &p_ofs, const AABB &p_bounds, const Vector3 p_points[3], uint32_t p_triangle_index, LocalVector<TriangleSort> &triangles, uint32_t p_grid_size) { - int half_size = p_size / 2; for (int i = 0; i < 8; i++) { - AABB aabb = p_bounds; aabb.size *= 0.5; Vector3i n = p_ofs; @@ -127,11 +156,9 @@ void LightmapperRD::_plot_triangle_into_triangle_index_list(int p_size, const Ve } Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_size, Vector<Ref<Image>> &albedo_images, Vector<Ref<Image>> &emission_images, AABB &bounds, Size2i &atlas_size, int &atlas_slices, BakeStepFunc p_step_function, void *p_bake_userdata) { - Vector<Size2i> sizes; for (int m_i = 0; m_i < mesh_instances.size(); m_i++) { - MeshInstance &mi = mesh_instances.write[m_i]; Size2i s = Size2i(mi.data.albedo_on_uv2->get_width(), mi.data.albedo_on_uv2->get_height()); sizes.push_back(s); @@ -159,7 +186,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ //determine best texture array atlas size by bruteforce fitting while (atlas_size.x <= p_max_texture_size && atlas_size.y <= p_max_texture_size) { - Vector<Vector2i> source_sizes = sizes; Vector<int> source_indices; source_indices.resize(source_sizes.size()); @@ -172,7 +198,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ int slices = 0; while (source_sizes.size() > 0) { - Vector<Vector3i> offsets = Geometry::partial_pack_rects(source_sizes, atlas_size); Vector<int> new_indices; Vector<Vector2i> new_sources; @@ -236,7 +261,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ //assign uv positions for (int m_i = 0; m_i < mesh_instances.size(); m_i++) { - MeshInstance &mi = mesh_instances.write[m_i]; mi.offset.x = best_atlas_offsets[m_i].x; mi.offset.y = best_atlas_offsets[m_i].y; @@ -249,7 +273,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ } void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i atlas_size, int atlas_slices, AABB &bounds, int grid_size, Vector<Probe> &probe_positions, GenerateProbes p_generate_probes, Vector<int> &slice_triangle_count, Vector<int> &slice_seam_count, RID &vertex_buffer, RID &triangle_buffer, RID &box_buffer, RID &lights_buffer, RID &triangle_cell_indices_buffer, RID &probe_positions_buffer, RID &grid_texture, RID &grid_texture_sdf, RID &seams_buffer, BakeStepFunc p_step_function, void *p_bake_userdata) { - HashMap<Vertex, uint32_t, VertexHash> vertex_map; //fill triangles array and vertex array @@ -269,7 +292,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i bounds = AABB(); 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); @@ -286,7 +308,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i } for (int i = 0; i < mi.data.points.size(); i += 3) { - Vector3 vtxs[3] = { mi.data.points[i + 0], mi.data.points[i + 1], mi.data.points[i + 2] }; Vector2 uvs[3] = { mi.data.uv2[i + 0] * uv_scale + uv_offset, mi.data.uv2[i + 1] * uv_scale + uv_offset, mi.data.uv2[i + 2] * uv_scale + uv_offset }; Vector3 normal[3] = { mi.data.normal[i + 0], mi.data.normal[i + 1], mi.data.normal[i + 2] }; @@ -295,7 +316,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i Triangle t; t.slice = mi.slice; for (int k = 0; k < 3; k++) { - bounds.expand_to(vtxs[k]); Vertex v; @@ -397,7 +417,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i //fill list of triangles in grid LocalVector<TriangleSort> triangle_sort; for (uint32_t i = 0; i < triangles.size(); i++) { - const Triangle &t = triangles[i]; Vector3 face[3] = { Vector3(vertex_array[t.indices[0]].position[0], vertex_array[t.indices[0]].position[1], vertex_array[t.indices[0]].position[2]), @@ -541,7 +560,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i } void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int atlas_slices, int grid_size, AABB bounds, float p_bias, Vector<int> slice_triangle_count, RID position_tex, RID unocclude_tex, RID normal_tex, RID raster_depth_buffer, RID rasterize_shader, RID raster_base_uniform) { - Vector<RID> framebuffers; for (int i = 0; i < atlas_slices; i++) { @@ -564,7 +582,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int RID raster_pipeline = rd->render_pipeline_create(rasterize_shader, rd->framebuffer_get_format(framebuffers[0]), RD::INVALID_FORMAT_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(3), 0); RID raster_pipeline_wire; { - RD::PipelineRasterizationState rw; rw.wireframe = true; raster_pipeline_wire = rd->render_pipeline_create(rasterize_shader, rd->framebuffer_get_format(framebuffers[0]), RD::INVALID_FORMAT_ID, RD::RENDER_PRIMITIVE_TRIANGLES, rw, RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(3), 0); @@ -577,7 +594,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int clear_colors.push_back(Color(0, 0, 0, 0)); for (int i = 0; i < atlas_slices; i++) { - RasterPushConstant raster_push_constant; raster_push_constant.atlas_size[0] = atlas_size.x; raster_push_constant.atlas_size[1] = atlas_size.y; @@ -614,7 +630,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int } 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); } @@ -810,7 +825,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> base_uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_STORAGE_BUFFER; u.binding = 1; @@ -945,7 +959,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d compute_shader.instance(); err = compute_shader->parse_versions_from_text(lm_compute_shader_glsl, p_bake_sh ? "\n#define USE_SH_LIGHTMAPS\n" : ""); if (err != OK) { - FREE_TEXTURES FREE_BUFFERS FREE_RASTER_RESOURCES @@ -1032,11 +1045,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* UNOCCLUDE */ { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1074,11 +1085,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* PRIMARY (direct) LIGHT PASS */ { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1156,11 +1165,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d } if (p_bounces > 0) { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1256,7 +1263,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < x_regions; i++) { for (int j = 0; j < y_regions; j++) { - int x = i * max_region_size; int y = j * max_region_size; int w = MIN((i + 1) * max_region_size, atlas_size.width) - x; @@ -1268,7 +1274,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d group_size = Vector3i((w - 1) / 8 + 1, (h - 1) / 8 + 1, 1); for (int k = 0; k < ray_iterations; k++) { - RD::ComputeListID compute_list = rd->compute_list_begin(); rd->compute_list_bind_compute_pipeline(compute_list, compute_shader_secondary_pipeline); rd->compute_list_bind_uniform_set(compute_list, compute_base_uniform_set, 0); @@ -1302,7 +1307,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d RID light_probe_buffer; if (probe_positions.size()) { - light_probe_buffer = rd->storage_buffer_create(sizeof(float) * 4 * 9 * probe_positions.size()); if (p_step_function) { @@ -1311,9 +1315,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> uniforms; { - { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_STORAGE_BUFFER; u.binding = 0; @@ -1366,7 +1368,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d int ray_iterations = (push_constant.ray_count - 1) / max_rays + 1; for (int i = 0; i < ray_iterations; i++) { - RD::ComputeListID compute_list = rd->compute_list_begin(); rd->compute_list_bind_compute_pipeline(compute_list, compute_shader_light_probes_pipeline); rd->compute_list_bind_uniform_set(compute_list, compute_base_uniform_set, 0); @@ -1456,13 +1457,11 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* DILATE LIGHTMAP */ { - SWAP(light_accum_tex, light_accum_tex2); Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1537,7 +1536,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d rd->free(blendseams_triangle_raster_shader); { - //pre copy for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { rd->texture_copy(light_accum_tex, light_accum_tex2, Vector3(), Vector3(), Vector3(atlas_size.width, atlas_size.height, 1), 0, 0, i, i, true); @@ -1555,7 +1553,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_TEXTURE; u.binding = 0; @@ -1585,10 +1582,8 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<Color> clear_colors; clear_colors.push_back(Color(0, 0, 0, 1)); for (int i = 0; i < atlas_slices; i++) { - int subslices = (p_bake_sh ? 4 : 1); for (int k = 0; k < subslices; k++) { - RasterSeamsPushConstant seams_push_constant; seams_push_constant.slice = uint32_t(i * subslices + k); seams_push_constant.debug = debug; @@ -1638,7 +1633,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d rd->draw_list_bind_render_pipeline(draw_list, blendseams_line_raster_pipeline); for (int j = 1; j < uv_offset_count; j++) { - seams_push_constant.base_index = seam_offset; seams_push_constant.uv_offset[0] = uv_offsets[j].x / float(atlas_size.width); seams_push_constant.uv_offset[1] = uv_offsets[j].y / float(atlas_size.height); @@ -1708,19 +1702,22 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d int LightmapperRD::get_bake_texture_count() const { return bake_textures.size(); } + Ref<Image> LightmapperRD::get_bake_texture(int p_index) const { ERR_FAIL_INDEX_V(p_index, bake_textures.size(), Ref<Image>()); return bake_textures[p_index]; } + int LightmapperRD::get_bake_mesh_count() const { return mesh_instances.size(); } + Variant LightmapperRD::get_bake_mesh_userdata(int p_index) const { ERR_FAIL_INDEX_V(p_index, mesh_instances.size(), Variant()); return mesh_instances[p_index].data.userdata; } -Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const { +Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const { ERR_FAIL_COND_V(bake_textures.size() == 0, Rect2()); Rect2 uv_ofs; Vector2 atlas_size = Vector2(bake_textures[0]->get_width(), bake_textures[0]->get_height()); @@ -1728,6 +1725,7 @@ Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const { uv_ofs.size = Vector2(mesh_instances[p_index].data.albedo_on_uv2->get_width(), mesh_instances[p_index].data.albedo_on_uv2->get_height()) / atlas_size; return uv_ofs; } + int LightmapperRD::get_bake_mesh_texture_slice(int p_index) const { ERR_FAIL_INDEX_V(p_index, mesh_instances.size(), Variant()); return mesh_instances[p_index].slice; diff --git a/modules/lightmapper_rd/lightmapper_rd.h b/modules/lightmapper_rd/lightmapper_rd.h index cb98efbeaa..6cb3ecbe9e 100644 --- a/modules/lightmapper_rd/lightmapper_rd.h +++ b/modules/lightmapper_rd/lightmapper_rd.h @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* lightmapper_rd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 */ +/* "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 LIGHTMAPPER_RD_H #define LIGHTMAPPER_RD_H @@ -168,7 +198,6 @@ class LightmapperRD : public Lightmapper { }; struct RasterSeamsPushConstant { - uint32_t base_index; uint32_t slice; float uv_offset[2]; diff --git a/modules/lightmapper_rd/lm_blendseams.glsl b/modules/lightmapper_rd/lm_blendseams.glsl index ef1ece8ea1..8a9ea91311 100644 --- a/modules/lightmapper_rd/lm_blendseams.glsl +++ b/modules/lightmapper_rd/lm_blendseams.glsl @@ -26,7 +26,6 @@ VERSION_DEFINES layout(location = 0) out vec3 uv_interp; void main() { - #ifdef MODE_TRIANGLES uint triangle_idx = params.base_index + gl_VertexIndex / 3; @@ -103,7 +102,6 @@ layout(location = 0) out vec4 dst_color; layout(set = 1, binding = 0) uniform texture2DArray src_color_tex; void main() { - if (params.debug) { #ifdef MODE_TRIANGLES dst_color = vec4(1, 0, 1, 1); diff --git a/modules/lightmapper_rd/lm_common_inc.glsl b/modules/lightmapper_rd/lm_common_inc.glsl index 0ff455936e..15946d5327 100644 --- a/modules/lightmapper_rd/lm_common_inc.glsl +++ b/modules/lightmapper_rd/lm_common_inc.glsl @@ -11,6 +11,7 @@ struct Vertex { layout(set = 0, binding = 1, std430) restrict readonly buffer Vertices { Vertex data[]; } + vertices; struct Triangle { @@ -21,6 +22,7 @@ struct Triangle { layout(set = 0, binding = 2, std430) restrict readonly buffer Triangles { Triangle data[]; } + triangles; struct Box { @@ -33,11 +35,13 @@ struct Box { layout(set = 0, binding = 3, std430) restrict readonly buffer Boxes { Box data[]; } + boxes; layout(set = 0, binding = 4, std430) restrict readonly buffer GridIndices { uint data[]; } + grid_indices; #define LIGHT_TYPE_DIRECTIONAL 0 @@ -66,6 +70,7 @@ struct Light { layout(set = 0, binding = 5, std430) restrict readonly buffer Lights { Light data[]; } + lights; struct Seam { @@ -76,11 +81,13 @@ struct Seam { layout(set = 0, binding = 6, std430) restrict readonly buffer Seams { Seam data[]; } + seams; layout(set = 0, binding = 7, std430) restrict readonly buffer Probes { vec4 data[]; } + probe_positions; layout(set = 0, binding = 8) uniform utexture3D grid; diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl index a178bd9b2e..a442016969 100644 --- a/modules/lightmapper_rd/lm_compute.glsl +++ b/modules/lightmapper_rd/lm_compute.glsl @@ -36,6 +36,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout(set = 1, binding = 0, std430) restrict buffer LightProbeData { vec4 data[]; } + light_probes; layout(set = 1, binding = 1) uniform texture2DArray source_light; @@ -93,11 +94,11 @@ layout(push_constant, binding = 0, std430) uniform Params { mat3x4 env_transform; } + params; //check it, but also return distance and barycentric coords (for uv lookup) bool ray_hits_triangle(vec3 from, vec3 dir, float max_dist, vec3 p0, vec3 p1, vec3 p2, out float r_distance, out vec3 r_barycentric) { - const vec3 e0 = p1 - p0; const vec3 e1 = p0 - p2; vec3 triangleNormal = cross(e1, e0); @@ -146,7 +147,6 @@ bool trace_ray(vec3 p_from, vec3 p_to uint iters = 0; while (all(greaterThanEqual(icell, ivec3(0))) && all(lessThan(icell, ivec3(params.grid_size))) && iters < 1000) { - uvec2 cell_data = texelFetch(usampler3D(grid, linear_sampler), icell, 0).xy; if (cell_data.x > 0) { //triangles here @@ -258,7 +258,6 @@ float quick_hash(vec2 pos) { } void main() { - #ifdef MODE_LIGHT_PROBES int probe_index = int(gl_GlobalInvocationID.x); if (probe_index >= params.atlas_size.x) { //too large, do nothing @@ -294,7 +293,6 @@ void main() { #endif for (uint i = 0; i < params.light_count; i++) { - vec3 light_pos; float attenuation; if (lights.data[i].type == LIGHT_TYPE_DIRECTIONAL) { @@ -313,7 +311,6 @@ void main() { attenuation = pow(max(1.0 - d, 0.0), lights.data[i].attenuation); if (lights.data[i].type == LIGHT_TYPE_SPOT) { - vec3 rel = normalize(position - light_pos); float angle = acos(dot(rel, lights.data[i].direction)); if (angle > lights.data[i].spot_angle) { @@ -512,7 +509,6 @@ void main() { vec3 norm; if (trace_ray(base_pos, ray_to, d, norm)) { - if (d < min_d) { vertex_pos = base_pos + rays[i] * d + norm * params.bias * 10.0; //this bias needs to be greater than the regular bias, because otherwise later, rays will go the other side when pointing back. min_d = d; @@ -561,7 +557,6 @@ void main() { light = textureLod(sampler2DArray(source_light, linear_sampler), uvw, 0.0).rgb; light += textureLod(sampler2DArray(source_direct_light, linear_sampler), uvw, 0.0).rgb; } else { - //did not hit a triangle, reach out for the sky vec3 sky_dir = normalize(mat3(params.env_transform) * ray_dir); diff --git a/modules/lightmapper_rd/lm_raster.glsl b/modules/lightmapper_rd/lm_raster.glsl index ae3038aead..36b706bcd5 100644 --- a/modules/lightmapper_rd/lm_raster.glsl +++ b/modules/lightmapper_rd/lm_raster.glsl @@ -26,12 +26,12 @@ layout(push_constant, binding = 0, std430) uniform Params { ivec3 grid_size; uint pad2; } + params; /* clang-format on */ void main() { - uint triangle_idx = params.base_triangle + gl_VertexIndex / 3; uint triangle_subidx = gl_VertexIndex % 3; @@ -95,7 +95,6 @@ layout(location = 1) out vec4 normal; layout(location = 2) out vec4 unocclude; void main() { - vec3 vertex_pos = vertex_interp; { diff --git a/modules/lightmapper_rd/register_types.cpp b/modules/lightmapper_rd/register_types.cpp index f3938f3190..0e6d7590cc 100644 --- a/modules/lightmapper_rd/register_types.cpp +++ b/modules/lightmapper_rd/register_types.cpp @@ -41,7 +41,6 @@ static Lightmapper *create_lightmapper_rd() { #endif void register_lightmapper_rd_types() { - GLOBAL_DEF("rendering/gpu_lightmapper/quality/low_quality_ray_count", 16); GLOBAL_DEF("rendering/gpu_lightmapper/quality/medium_quality_ray_count", 64); GLOBAL_DEF("rendering/gpu_lightmapper/quality/high_quality_ray_count", 256); |