From 706e9a5550e77844815c8608879514e702d77e84 Mon Sep 17 00:00:00 2001 From: wojtekpil Date: Thu, 3 Jun 2021 21:15:20 +0200 Subject: [PATCH] Offset pivot to get correct impostor position --- addons/octahedral_impostors/scripts/baking/baker.gd | 2 ++ addons/octahedral_impostors/scripts/baking/exporter.gd | 3 +++ addons/octahedral_impostors/scripts/baking/scene_baker.gd | 5 +++++ .../scripts/baking/scene_bakers/multi_bake_scene.gd | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/addons/octahedral_impostors/scripts/baking/baker.gd b/addons/octahedral_impostors/scripts/baking/baker.gd index a5c7bcf..4772487 100644 --- a/addons/octahedral_impostors/scripts/baking/baker.gd +++ b/addons/octahedral_impostors/scripts/baking/baker.gd @@ -118,6 +118,8 @@ func bake(): yield(get_tree(), "idle_frame") yield(get_tree(), "idle_frame") + exporter.position_offset = scene_baker.get_pivot_translation() + for mapbaker in profile.standard_map_bakers: map_baker = mapbaker.new() print("Baking: ", map_baker.get_name()) diff --git a/addons/octahedral_impostors/scripts/baking/exporter.gd b/addons/octahedral_impostors/scripts/baking/exporter.gd index e089a04..8b05a36 100644 --- a/addons/octahedral_impostors/scripts/baking/exporter.gd +++ b/addons/octahedral_impostors/scripts/baking/exporter.gd @@ -9,6 +9,7 @@ var export_path := "res://" var frames_xy := 12 var is_full_sphere := false var scale_instance := 1.0 +var position_offset := Vector3.ZERO var packedscene_filename := "impostor.tscn" var saved_maps := {} @@ -96,6 +97,7 @@ func export_scene(mat: Material, texture_array: bool = false, shadow_mat: Materi mat.set_shader_param("isFullSphere", is_full_sphere) mat.set_shader_param("aabb_max", scale_instance/2.0) mat.set_shader_param("scale", scale_instance) + mat.set_shader_param("positionOffset", position_offset) if shadow_mat != null: print("Creating shadow material...") @@ -103,6 +105,7 @@ func export_scene(mat: Material, texture_array: bool = false, shadow_mat: Materi shadow_mat.set_shader_param("isFullSphere", is_full_sphere) shadow_mat.set_shader_param("aabb_max", -scale_instance/2.0) shadow_mat.set_shader_param("scale", scale_instance) + shadow_mat.set_shader_param("positionOffset", position_offset) mi_shadow.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_SHADOWS_ONLY print("Loading resources...") diff --git a/addons/octahedral_impostors/scripts/baking/scene_baker.gd b/addons/octahedral_impostors/scripts/baking/scene_baker.gd index b07d138..71e782c 100644 --- a/addons/octahedral_impostors/scripts/baking/scene_baker.gd +++ b/addons/octahedral_impostors/scripts/baking/scene_baker.gd @@ -9,6 +9,11 @@ signal atlas_ready #baked atlas image will be read from here after signal var atlas_image: Image + +func get_pivot_translation() -> Vector3: + return Vector3.ZERO + + func set_atlas_image(img: Image) -> void: atlas_image = img diff --git a/addons/octahedral_impostors/scripts/baking/scene_bakers/multi_bake_scene.gd b/addons/octahedral_impostors/scripts/baking/scene_bakers/multi_bake_scene.gd index 844d9ec..a1d0192 100644 --- a/addons/octahedral_impostors/scripts/baking/scene_bakers/multi_bake_scene.gd +++ b/addons/octahedral_impostors/scripts/baking/scene_bakers/multi_bake_scene.gd @@ -20,6 +20,11 @@ var camera_distance_scaled: float onready var baking_camera: Camera = $Camera + +func get_pivot_translation() -> Vector3: + return scene_to_bake.translation * (-1.0) * frames_xy + + func get_scene_to_bake_aabb(node := scene_to_bake) -> AABB: var aabb := AABB(Vector3.ONE * 65536.0, -Vector3.ONE * 65536.0 * 2.0) if node is GeometryInstance and not node is CSGShape: