summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorFerenc Arn <tagcup@yahoo.com>2017-11-15 19:01:02 -0500
committerFerenc Arn <tagcup@yahoo.com>2017-11-15 20:01:53 -0500
commit1980a54dbbb50f27b8560167683109c485dcf7c9 (patch)
treea489a0a27c365e1d4266f29c547ec785ccdccb9d /scene/3d
parent6b34f10ab1dc92fa0addf57cb3cdcce5fd109d5b (diff)
Fix energy not affecting emissive texture in GI baker.
Also fix emission_tex being invalid always due to wrong reference type. Fixes #10534.
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/gi_probe.cpp38
-rw-r--r--scene/3d/gi_probe.h2
2 files changed, 18 insertions, 22 deletions
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index 002ce1793b..bc70feaffb 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -410,7 +410,7 @@ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
if (min > rad || max < -rad) return false;
-/*======================== Z-tests ========================*/
+ /*======================== Z-tests ========================*/
#define AXISTEST_Z12(a, b, fa, fb) \
p1 = a * v1.x - b * v1.y; \
@@ -891,7 +891,7 @@ void GIProbe::_fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Bak
}
}
-Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_color, bool p_color_add) {
+Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_color_mul, const Color &p_color_add) {
Vector<Color> ret;
@@ -899,7 +899,7 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo
ret.resize(bake_texture_size * bake_texture_size);
for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
- ret[i] = p_color;
+ ret[i] = p_color_add;
}
return ret;
@@ -919,15 +919,9 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo
for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
Color c;
- if (p_color_add) {
- c.r = (r[i * 4 + 0] / 255.0) + p_color.r;
- c.g = (r[i * 4 + 1] / 255.0) + p_color.g;
- c.b = (r[i * 4 + 2] / 255.0) + p_color.b;
- } else {
- c.r = (r[i * 4 + 0] / 255.0) * p_color.r;
- c.g = (r[i * 4 + 1] / 255.0) * p_color.g;
- c.b = (r[i * 4 + 2] / 255.0) * p_color.b;
- }
+ c.r = (r[i * 4 + 0] / 255.0) * p_color_mul.r + p_color_add.r;
+ c.g = (r[i * 4 + 1] / 255.0) * p_color_mul.g + p_color_add.g;
+ c.b = (r[i * 4 + 2] / 255.0) * p_color_mul.b + p_color_add.b;
c.a = r[i * 4 + 3] / 255.0;
@@ -958,17 +952,15 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
if (albedo_tex.is_valid()) {
img_albedo = albedo_tex->get_data();
+ mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo(), Color(0, 0, 0)); // albedo texture, color is multiplicative
} else {
+ mc.albedo = _get_bake_texture(img_albedo, Color(1, 1, 1), mat->get_albedo()); // no albedo texture, color is additive
}
- mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo(), false);
-
- Ref<ImageTexture> emission_tex = mat->get_texture(SpatialMaterial::TEXTURE_EMISSION);
+ Ref<Texture> emission_tex = mat->get_texture(SpatialMaterial::TEXTURE_EMISSION);
Color emission_col = mat->get_emission();
- emission_col.r *= mat->get_emission_energy();
- emission_col.g *= mat->get_emission_energy();
- emission_col.b *= mat->get_emission_energy();
+ float emission_energy = mat->get_emission_energy();
Ref<Image> img_emission;
@@ -977,13 +969,17 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
img_emission = emission_tex->get_data();
}
- mc.emission = _get_bake_texture(img_emission, emission_col, mat->get_emission_operator() == SpatialMaterial::EMISSION_OP_ADD);
+ if (mat->get_emission_operator() == SpatialMaterial::EMISSION_OP_ADD) {
+ mc.emission = _get_bake_texture(img_emission, Color(1, 1, 1) * emission_energy, emission_col * emission_energy);
+ } else {
+ mc.emission = _get_bake_texture(img_emission, emission_col * emission_energy, Color(0, 0, 0));
+ }
} else {
Ref<Image> empty;
- mc.albedo = _get_bake_texture(empty, Color(0.7, 0.7, 0.7));
- mc.emission = _get_bake_texture(empty, Color(0, 0, 0));
+ mc.albedo = _get_bake_texture(empty, Color(0, 0, 0), Color(1, 1, 1));
+ mc.emission = _get_bake_texture(empty, Color(0, 0, 0), Color(0, 0, 0));
}
p_baker->material_cache[p_material] = mc;
diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h
index 8aca2c549b..8f13960b67 100644
--- a/scene/3d/gi_probe.h
+++ b/scene/3d/gi_probe.h
@@ -178,7 +178,7 @@ private:
int color_scan_cell_width;
int bake_texture_size;
- Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color, bool p_color_add = false);
+ Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color_mul, const Color &p_color_add);
Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker);
void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const Rect3 &p_aabb, Baker *p_baker);
void _plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);