Skip to content

Commit

Permalink
Offset pivot to get correct impostor position
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekpil committed Jun 3, 2021
1 parent 4c8a53c commit 706e9a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/octahedral_impostors/scripts/baking/baker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions addons/octahedral_impostors/scripts/baking/exporter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 := {}
Expand Down Expand Up @@ -96,13 +97,15 @@ 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...")
shadow_mat.set_shader_param("imposterFrames", Vector2(frames_xy, frames_xy))
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...")
Expand Down
5 changes: 5 additions & 0 deletions addons/octahedral_impostors/scripts/baking/scene_baker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 706e9a5

Please sign in to comment.