Skip to content

Commit c1c6ca8

Browse files
committed
Fix BaseMaterial3D UV1 Offset/Scale being ignored when baking VoxelGI
UV1 Triplanar and Emission on UV2 properties are still ignored, but implementing them is much more involved.
1 parent a4607f4 commit c1c6ca8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

scene/3d/voxelizer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
152152
lnormal = normal;
153153
}
154154

155-
int uv_x = CLAMP(int(Math::fposmod(uv.x, (real_t)1.0) * bake_texture_size), 0, bake_texture_size - 1);
156-
int uv_y = CLAMP(int(Math::fposmod(uv.y, (real_t)1.0) * bake_texture_size), 0, bake_texture_size - 1);
155+
int uv_x = CLAMP(int(Math::fposmod(uv.x * p_material.uv1_scale.x + p_material.uv1_offset.x, (real_t)1.0) * bake_texture_size), 0, bake_texture_size - 1);
156+
int uv_y = CLAMP(int(Math::fposmod(uv.y * p_material.uv1_scale.y + p_material.uv1_offset.y, (real_t)1.0) * bake_texture_size), 0, bake_texture_size - 1);
157157

158158
int ofs = uv_y * bake_texture_size + uv_x;
159159
albedo_accum.r += p_material.albedo[ofs].r;
@@ -184,8 +184,8 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
184184
lnormal = normal;
185185
}
186186

187-
int uv_x = CLAMP(Math::fposmod(uv.x, (real_t)1.0) * bake_texture_size, 0, bake_texture_size - 1);
188-
int uv_y = CLAMP(Math::fposmod(uv.y, (real_t)1.0) * bake_texture_size, 0, bake_texture_size - 1);
187+
int uv_x = CLAMP(Math::fposmod(uv.x * p_material.uv1_scale.x + p_material.uv1_offset.x, (real_t)1.0) * bake_texture_size, 0, bake_texture_size - 1);
188+
int uv_y = CLAMP(Math::fposmod(uv.y * p_material.uv1_scale.y + p_material.uv1_offset.y, (real_t)1.0) * bake_texture_size, 0, bake_texture_size - 1);
189189

190190
int ofs = uv_y * bake_texture_size + uv_x;
191191

@@ -377,11 +377,15 @@ Voxelizer::MaterialCache Voxelizer::_get_material_cache(Ref<Material> p_material
377377
mc.emission = _get_bake_texture(empty, Color(0, 0, 0), Color(0, 0, 0));
378378
}
379379

380+
mc.uv1_scale = mat->get_uv1_scale();
381+
mc.uv1_offset = mat->get_uv1_offset();
380382
} else {
381383
Ref<Image> empty;
382384

383385
mc.albedo = _get_bake_texture(empty, Color(0, 0, 0), Color(1, 1, 1));
384386
mc.emission = _get_bake_texture(empty, Color(0, 0, 0), Color(0, 0, 0));
387+
mc.uv1_scale = Vector3(1, 1, 1);
388+
mc.uv1_offset = Vector3(0, 0, 0);
385389
}
386390

387391
material_cache[p_material] = mc;

scene/3d/voxelizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class Voxelizer {
9191
//128x128 textures
9292
Vector<Color> albedo;
9393
Vector<Color> emission;
94+
95+
Vector3 uv1_scale;
96+
Vector3 uv1_offset;
9497
};
9598

9699
HashMap<Ref<Material>, MaterialCache> material_cache;

0 commit comments

Comments
 (0)