Few small GI Probe fixes

This commit is contained in:
Juan Linietsky 2017-07-29 00:03:54 -03:00
parent 260d179d31
commit b276d92c8a
5 changed files with 18 additions and 14 deletions

View file

@ -810,6 +810,9 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
vec2 screen_rel = to_screen - from_screen; vec2 screen_rel = to_screen - from_screen;
if (length(screen_rel)<0.00001)
return 1.0; //too small, don't do anything
/*float pixel_size; //approximate pixel size /*float pixel_size; //approximate pixel size
if (screen_rel.x > screen_rel.y) { if (screen_rel.x > screen_rel.y) {
@ -825,15 +828,16 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
vec2 pixel_incr = normalize(screen_rel)*screen_pixel_size; vec2 pixel_incr = normalize(screen_rel)*screen_pixel_size;
float steps = length(screen_rel) / length(pixel_incr);
float steps = length(screen_rel) / length(pixel_incr);
steps = min(2000.0,steps); //put a limit to avoid freezing in some strange situation
//steps=10.0; //steps=10.0;
vec4 incr = (dest - source)/steps; vec4 incr = (dest - source)/steps;
float ratio=0.0; float ratio=0.0;
float ratio_incr = 1.0/steps; float ratio_incr = 1.0/steps;
do { while(steps>0.0) {
source += incr*2.0; source += incr*2.0;
bias+=incr*2.0; bias+=incr*2.0;
@ -851,7 +855,7 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
ratio+=ratio_incr; ratio+=ratio_incr;
steps-=1.0; steps-=1.0;
} while (steps>0.0); }
return 1.0; return 1.0;
} }

View file

@ -323,8 +323,8 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in
surf_tool->add_smooth_group(false); surf_tool->add_smooth_group(false);
else else
surf_tool->add_smooth_group(true); surf_tool->add_smooth_group(true);
} else if (l.begins_with("g ") || l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh } else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh
//groups are too annoying
if (surf_tool->get_vertex_array().size()) { if (surf_tool->get_vertex_array().size()) {
//another group going on, commit it //another group going on, commit it
if (normals.size() == 0) { if (normals.size() == 0) {

View file

@ -999,7 +999,7 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
return mc; return mc;
} }
void GIProbe::_plot_mesh(const Transform &p_xform, Ref<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) { void GIProbe::_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) {
for (int i = 0; i < p_mesh->get_surface_count(); i++) { for (int i = 0; i < p_mesh->get_surface_count(); i++) {
@ -1093,7 +1093,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
MeshInstance *mi = p_at_node->cast_to<MeshInstance>(); MeshInstance *mi = p_at_node->cast_to<MeshInstance>();
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) { if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) {
Ref<ArrayMesh> mesh = mi->get_mesh(); Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_valid()) { if (mesh.is_valid()) {
Rect3 aabb = mesh->get_aabb(); Rect3 aabb = mesh->get_aabb();
@ -1120,7 +1120,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
for (int i = 0; i < meshes.size(); i += 2) { for (int i = 0; i < meshes.size(); i += 2) {
Transform mxf = meshes[i]; Transform mxf = meshes[i];
Ref<ArrayMesh> mesh = meshes[i + 1]; Ref<Mesh> mesh = meshes[i + 1];
if (!mesh.is_valid()) if (!mesh.is_valid())
continue; continue;

View file

@ -148,7 +148,7 @@ private:
struct PlotMesh { struct PlotMesh {
Ref<Material> override_material; Ref<Material> override_material;
Vector<Ref<Material> > instance_materials; Vector<Ref<Material> > instance_materials;
Ref<ArrayMesh> mesh; Ref<Mesh> mesh;
Transform local_xform; Transform local_xform;
}; };
@ -177,7 +177,7 @@ private:
Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color); Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color);
Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker); 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_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<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material); 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);
void _find_meshes(Node *p_at_node, Baker *p_baker); void _find_meshes(Node *p_at_node, Baker *p_baker);
void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker); void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker);

View file

@ -2716,8 +2716,8 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header, co
success_count++; success_count++;
} }
} }
print_line("BAKE TIME: " + rtos((OS::get_singleton()->get_ticks_usec() - us) / 1000000.0)); //print_line("BAKE TIME: " + rtos((OS::get_singleton()->get_ticks_usec() - us) / 1000000.0));
print_line("valid cells: " + itos(success_count)); //print_line("valid cells: " + itos(success_count));
} break; } break;
case VS::LIGHT_OMNI: case VS::LIGHT_OMNI:
@ -2822,7 +2822,7 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header, co
light->energy[2] += int32_t(light_b * att * ((cell->albedo) & 0xFF) / 255.0); light->energy[2] += int32_t(light_b * att * ((cell->albedo) & 0xFF) / 255.0);
} }
} }
print_line("BAKE TIME: " + rtos((OS::get_singleton()->get_ticks_usec() - us) / 1000000.0)); //print_line("BAKE TIME: " + rtos((OS::get_singleton()->get_ticks_usec() - us) / 1000000.0));
} break; } break;
} }
@ -2921,7 +2921,7 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) {
if (stage >= probe_data->dynamic.mipmaps_3d.size()) if (stage >= probe_data->dynamic.mipmaps_3d.size())
continue; //no mipmap for this one continue; //no mipmap for this one
print_line("generating mipmap stage: " + itos(stage)); //print_line("generating mipmap stage: " + itos(stage));
int level_cell_count = probe_data->dynamic.level_cell_lists[i].size(); int level_cell_count = probe_data->dynamic.level_cell_lists[i].size();
const uint32_t *level_cells = probe_data->dynamic.level_cell_lists[i].ptr(); const uint32_t *level_cells = probe_data->dynamic.level_cell_lists[i].ptr();