Skip to content

Commit c66d89d

Browse files
committed
Merge pull request #107382 from Calinou/editor-lightmapprobe-add-gizmo-size-setting
Add a LightmapProbe gizmo size editor setting
2 parents f485f6c + 437e2ee commit c66d89d

File tree

6 files changed

+138
-120
lines changed

6 files changed

+138
-120
lines changed

doc/classes/EditorSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@
518518
<member name="editors/3d_gizmos/gizmo_settings/bone_shape" type="int" setter="" getter="">
519519
The shape of [Skeleton3D] bone gizmos in the 3D editor. [b]Wire[/b] is a thin line, while [b]Octahedron[/b] is a set of lines that represent a thicker hollow line pointing in a specific direction (similar to most 3D animation software).
520520
</member>
521+
<member name="editors/3d_gizmos/gizmo_settings/lightmap_gi_probe_size" type="float" setter="" getter="">
522+
Size of probe gizmos displayed when editing [LightmapGI] and [LightmapProbe] nodes. Setting this to [code]0.0[/code] will hide the probe spheres of [LightmapGI] and wireframes of [LightmapProbe] nodes, but will keep the wireframes linking probes from [LightmapGI] and billboard icons from [LightmapProbe] intact.
523+
</member>
521524
<member name="editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size" type="float" setter="" getter="">
522525
Size of the disk gizmo displayed when editing [Path3D]'s tilt handles.
523526
</member>

editor/editor_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
850850
_initial_set("editors/3d_gizmos/gizmo_settings/bone_axis_length", (float)0.1);
851851
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d_gizmos/gizmo_settings/bone_shape", 1, "Wire,Octahedron");
852852
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
853+
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d_gizmos/gizmo_settings/lightmap_gi_probe_size", 0.4, "0.0,1.0,0.001,or_greater", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
853854

854855
// If a line is a multiple of this, it uses the primary grid color.
855856
// Use a power of 2 value by default as it's more common to use powers of 2 in level design.

editor/plugins/gizmos/lightmap_gi_gizmo_plugin.cpp

Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
#include "scene/3d/lightmap_gi.h"
3737

3838
LightmapGIGizmoPlugin::LightmapGIGizmoPlugin() {
39+
// NOTE: This gizmo only renders solid spheres for previewing indirect lighting on dynamic objects.
40+
// The wireframe representation for LightmapProbe nodes is handled in LightmapProbeGizmoPlugin.
3941
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/lightmap_lines");
42+
probe_size = EDITOR_GET("editors/3d_gizmos/gizmo_settings/lightmap_gi_probe_size");
4043

4144
gizmo_color.a = 0.1;
4245
create_material("lightmap_lines", gizmo_color);
@@ -45,8 +48,8 @@ LightmapGIGizmoPlugin::LightmapGIGizmoPlugin() {
4548
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
4649
// Fade out probes when camera gets too close to them.
4750
mat->set_distance_fade(StandardMaterial3D::DISTANCE_FADE_PIXEL_DITHER);
48-
mat->set_distance_fade_min_distance(0.5);
49-
mat->set_distance_fade_max_distance(1.5);
51+
mat->set_distance_fade_min_distance(probe_size * 0.5);
52+
mat->set_distance_fade_max_distance(probe_size * 1.5);
5053
mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
5154
mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, false);
5255
mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
@@ -129,91 +132,93 @@ void LightmapGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
129132
LocalVector<Vector3> vertices;
130133
LocalVector<Color> colors;
131134
LocalVector<int> indices;
132-
float radius = 0.3;
133-
134-
// L2 Spherical Harmonics evaluation and diffuse convolution coefficients.
135-
const float sh_coeffs[5] = {
136-
static_cast<float>(sqrt(1.0 / (4.0 * Math::PI)) * Math::PI),
137-
static_cast<float>(sqrt(3.0 / (4.0 * Math::PI)) * Math::PI * 2.0 / 3.0),
138-
static_cast<float>(sqrt(15.0 / (4.0 * Math::PI)) * Math::PI * 1.0 / 4.0),
139-
static_cast<float>(sqrt(5.0 / (16.0 * Math::PI)) * Math::PI * 1.0 / 4.0),
140-
static_cast<float>(sqrt(15.0 / (16.0 * Math::PI)) * Math::PI * 1.0 / 4.0)
141-
};
142-
143-
for (int p = 0; p < points.size(); p++) {
144-
int vertex_base = vertices.size();
145-
Vector3 sh_col[9];
146-
for (int i = 0; i < 9; i++) {
147-
sh_col[i].x = sh[p * 9 + i].r;
148-
sh_col[i].y = sh[p * 9 + i].g;
149-
sh_col[i].z = sh[p * 9 + i].b;
150-
}
151-
152-
for (int i = 0; i <= stack_count; ++i) {
153-
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
154-
float xy = radius * Math::cos(stack_angle); // r * cos(u)
155-
float z = radius * Math::sin(stack_angle); // r * sin(u)
156-
157-
// add (sector_count+1) vertices per stack
158-
// the first and last vertices have same position and normal, but different tex coords
159-
for (int j = 0; j <= sector_count; ++j) {
160-
float sector_angle = j * sector_step; // starting from 0 to 2pi
161-
162-
// vertex position (x, y, z)
163-
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
164-
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
165-
166-
Vector3 n = Vector3(x, z, y);
167-
vertices.push_back(points[p] + n);
168-
n.normalize();
169-
170-
const Vector3 light = (sh_coeffs[0] * sh_col[0] +
171-
sh_coeffs[1] * sh_col[1] * n.y +
172-
sh_coeffs[1] * sh_col[2] * n.z +
173-
sh_coeffs[1] * sh_col[3] * n.x +
174-
sh_coeffs[2] * sh_col[4] * n.x * n.y +
175-
sh_coeffs[2] * sh_col[5] * n.y * n.z +
176-
sh_coeffs[3] * sh_col[6] * (3.0 * n.z * n.z - 1.0) +
177-
sh_coeffs[2] * sh_col[7] * n.x * n.z +
178-
sh_coeffs[4] * sh_col[8] * (n.x * n.x - n.y * n.y));
179-
180-
colors.push_back(Color(light.x, light.y, light.z, 1));
135+
float radius = probe_size * 0.5f;
136+
137+
if (!Math::is_zero_approx(radius)) {
138+
// L2 Spherical Harmonics evaluation and diffuse convolution coefficients.
139+
const float sh_coeffs[5] = {
140+
static_cast<float>(sqrt(1.0 / (4.0 * Math::PI)) * Math::PI),
141+
static_cast<float>(sqrt(3.0 / (4.0 * Math::PI)) * Math::PI * 2.0 / 3.0),
142+
static_cast<float>(sqrt(15.0 / (4.0 * Math::PI)) * Math::PI * 1.0 / 4.0),
143+
static_cast<float>(sqrt(5.0 / (16.0 * Math::PI)) * Math::PI * 1.0 / 4.0),
144+
static_cast<float>(sqrt(15.0 / (16.0 * Math::PI)) * Math::PI * 1.0 / 4.0)
145+
};
146+
147+
for (int p = 0; p < points.size(); p++) {
148+
int vertex_base = vertices.size();
149+
Vector3 sh_col[9];
150+
for (int i = 0; i < 9; i++) {
151+
sh_col[i].x = sh[p * 9 + i].r;
152+
sh_col[i].y = sh[p * 9 + i].g;
153+
sh_col[i].z = sh[p * 9 + i].b;
181154
}
182-
}
183155

184-
for (int i = 0; i < stack_count; ++i) {
185-
int k1 = i * (sector_count + 1); // beginning of current stack
186-
int k2 = k1 + sector_count + 1; // beginning of next stack
187-
188-
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
189-
// 2 triangles per sector excluding first and last stacks
190-
// k1 => k2 => k1+1
191-
if (i != 0) {
192-
indices.push_back(vertex_base + k1);
193-
indices.push_back(vertex_base + k2);
194-
indices.push_back(vertex_base + k1 + 1);
156+
for (int i = 0; i <= stack_count; ++i) {
157+
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
158+
float xy = radius * Math::cos(stack_angle); // r * cos(u)
159+
float z = radius * Math::sin(stack_angle); // r * sin(u)
160+
161+
// add (sector_count+1) vertices per stack
162+
// the first and last vertices have same position and normal, but different tex coords
163+
for (int j = 0; j <= sector_count; ++j) {
164+
float sector_angle = j * sector_step; // starting from 0 to 2pi
165+
166+
// vertex position (x, y, z)
167+
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
168+
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
169+
170+
Vector3 n = Vector3(x, z, y);
171+
vertices.push_back(points[p] + n);
172+
n.normalize();
173+
174+
const Vector3 light = (sh_coeffs[0] * sh_col[0] +
175+
sh_coeffs[1] * sh_col[1] * n.y +
176+
sh_coeffs[1] * sh_col[2] * n.z +
177+
sh_coeffs[1] * sh_col[3] * n.x +
178+
sh_coeffs[2] * sh_col[4] * n.x * n.y +
179+
sh_coeffs[2] * sh_col[5] * n.y * n.z +
180+
sh_coeffs[3] * sh_col[6] * (3.0 * n.z * n.z - 1.0) +
181+
sh_coeffs[2] * sh_col[7] * n.x * n.z +
182+
sh_coeffs[4] * sh_col[8] * (n.x * n.x - n.y * n.y));
183+
184+
colors.push_back(Color(light.x, light.y, light.z, 1));
195185
}
186+
}
196187

197-
// k1+1 => k2 => k2+1
198-
if (i != (stack_count - 1)) {
199-
indices.push_back(vertex_base + k1 + 1);
200-
indices.push_back(vertex_base + k2);
201-
indices.push_back(vertex_base + k2 + 1);
188+
for (int i = 0; i < stack_count; ++i) {
189+
int k1 = i * (sector_count + 1); // beginning of current stack
190+
int k2 = k1 + sector_count + 1; // beginning of next stack
191+
192+
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
193+
// 2 triangles per sector excluding first and last stacks
194+
// k1 => k2 => k1+1
195+
if (i != 0) {
196+
indices.push_back(vertex_base + k1);
197+
indices.push_back(vertex_base + k2);
198+
indices.push_back(vertex_base + k1 + 1);
199+
}
200+
201+
// k1+1 => k2 => k2+1
202+
if (i != (stack_count - 1)) {
203+
indices.push_back(vertex_base + k1 + 1);
204+
indices.push_back(vertex_base + k2);
205+
indices.push_back(vertex_base + k2 + 1);
206+
}
202207
}
203208
}
204209
}
205-
}
206210

207-
Array array;
208-
array.resize(RS::ARRAY_MAX);
209-
array[RS::ARRAY_VERTEX] = Vector<Vector3>(vertices);
210-
array[RS::ARRAY_INDEX] = Vector<int>(indices);
211-
array[RS::ARRAY_COLOR] = Vector<Color>(colors);
211+
Array array;
212+
array.resize(RS::ARRAY_MAX);
213+
array[RS::ARRAY_VERTEX] = Vector<Vector3>(vertices);
214+
array[RS::ARRAY_INDEX] = Vector<int>(indices);
215+
array[RS::ARRAY_COLOR] = Vector<Color>(colors);
212216

213-
Ref<ArrayMesh> mesh;
214-
mesh.instantiate();
215-
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array, Array(), Dictionary(), 0); //no compression
216-
mesh->surface_set_material(0, material_probes);
217+
Ref<ArrayMesh> mesh;
218+
mesh.instantiate();
219+
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array, Array(), Dictionary(), 0); //no compression
220+
mesh->surface_set_material(0, material_probes);
217221

218-
p_gizmo->add_mesh(mesh);
222+
p_gizmo->add_mesh(mesh);
223+
}
219224
}

editor/plugins/gizmos/lightmap_gi_gizmo_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
class LightmapGIGizmoPlugin : public EditorNode3DGizmoPlugin {
3636
GDCLASS(LightmapGIGizmoPlugin, EditorNode3DGizmoPlugin);
3737

38+
float probe_size = 0.4f;
39+
3840
public:
3941
bool has_gizmo(Node3D *p_spatial) override;
4042
String get_gizmo_name() const override;

editor/plugins/gizmos/lightmap_probe_gizmo_plugin.cpp

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
#include "scene/3d/lightmap_probe.h"
3737

3838
LightmapProbeGizmoPlugin::LightmapProbeGizmoPlugin() {
39+
// NOTE: This gizmo only renders LightmapProbe nodes as wireframes.
40+
// The solid sphere representation is handled in LightmapGIGizmoPlugin.
3941
create_icon_material("lightmap_probe_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoLightmapProbe"), EditorStringName(EditorIcons)));
4042

4143
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/lightprobe_lines");
44+
probe_size = EDITOR_GET("editors/3d_gizmos/gizmo_settings/lightmap_gi_probe_size");
4245

4346
gizmo_color.a = 0.3;
4447
create_material("lightprobe_lines", gizmo_color);
@@ -70,52 +73,54 @@ void LightmapProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
7073
float stack_step = Math::PI / stack_count;
7174

7275
Vector<Vector3> vertices;
73-
float radius = 0.2;
74-
75-
for (int i = 0; i <= stack_count; ++i) {
76-
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
77-
float xy = radius * Math::cos(stack_angle); // r * cos(u)
78-
float z = radius * Math::sin(stack_angle); // r * sin(u)
79-
80-
// add (sector_count+1) vertices per stack
81-
// the first and last vertices have same position and normal, but different tex coords
82-
for (int j = 0; j <= sector_count; ++j) {
83-
float sector_angle = j * sector_step; // starting from 0 to 2pi
84-
85-
// vertex position (x, y, z)
86-
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
87-
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
88-
89-
Vector3 n = Vector3(x, z, y);
90-
vertices.push_back(n);
91-
}
92-
}
93-
94-
for (int i = 0; i < stack_count; ++i) {
95-
int k1 = i * (sector_count + 1); // beginning of current stack
96-
int k2 = k1 + sector_count + 1; // beginning of next stack
97-
98-
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
99-
// 2 triangles per sector excluding first and last stacks
100-
// k1 => k2 => k1+1
101-
if (i != 0) {
102-
lines.push_back(vertices[k1]);
103-
lines.push_back(vertices[k2]);
104-
lines.push_back(vertices[k1]);
105-
lines.push_back(vertices[k1 + 1]);
76+
// Make the lines' radius slightly smaller than its mesh representation to avoid Z-fighting.
77+
float radius = probe_size * 0.495f;
78+
79+
if (!Math::is_zero_approx(radius)) {
80+
for (int i = 0; i <= stack_count; ++i) {
81+
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
82+
float xy = radius * Math::cos(stack_angle); // r * cos(u)
83+
float z = radius * Math::sin(stack_angle); // r * sin(u)
84+
85+
// add (sector_count+1) vertices per stack
86+
// the first and last vertices have same position and normal, but different tex coords
87+
for (int j = 0; j <= sector_count; ++j) {
88+
float sector_angle = j * sector_step; // starting from 0 to 2pi
89+
90+
// vertex position (x, y, z)
91+
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
92+
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
93+
94+
Vector3 n = Vector3(x, z, y);
95+
vertices.push_back(n);
10696
}
97+
}
10798

108-
if (i != (stack_count - 1)) {
109-
lines.push_back(vertices[k1 + 1]);
110-
lines.push_back(vertices[k2]);
111-
lines.push_back(vertices[k2]);
112-
lines.push_back(vertices[k2 + 1]);
99+
for (int i = 0; i < stack_count; ++i) {
100+
int k1 = i * (sector_count + 1); // beginning of current stack
101+
int k2 = k1 + sector_count + 1; // beginning of next stack
102+
103+
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
104+
// 2 triangles per sector excluding first and last stacks
105+
// k1 => k2 => k1+1
106+
if (i != 0) {
107+
lines.push_back(vertices[k1]);
108+
lines.push_back(vertices[k2]);
109+
lines.push_back(vertices[k1]);
110+
lines.push_back(vertices[k1 + 1]);
111+
}
112+
113+
if (i != (stack_count - 1)) {
114+
lines.push_back(vertices[k1 + 1]);
115+
lines.push_back(vertices[k2]);
116+
lines.push_back(vertices[k2]);
117+
lines.push_back(vertices[k2 + 1]);
118+
}
113119
}
114120
}
115-
}
116121

122+
p_gizmo->add_lines(lines, material_lines);
123+
}
117124
const Ref<Material> icon = get_material("lightmap_probe_icon", p_gizmo);
118-
119-
p_gizmo->add_lines(lines, material_lines);
120125
p_gizmo->add_unscaled_billboard(icon, 0.05);
121126
}

editor/plugins/gizmos/lightmap_probe_gizmo_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
class LightmapProbeGizmoPlugin : public EditorNode3DGizmoPlugin {
3636
GDCLASS(LightmapProbeGizmoPlugin, EditorNode3DGizmoPlugin);
3737

38+
float probe_size = 0.4f;
39+
3840
public:
3941
bool has_gizmo(Node3D *p_spatial) override;
4042
String get_gizmo_name() const override;

0 commit comments

Comments
 (0)