decals_spawn.gd 932 B

123456789101112131415161718192021222324252627282930313233343536
  1. extends Spatial
  2. # decals based on https://github.com/Mr-Slurpy/Screen-Space-Decals
  3. onready var cnode=get_node("decal")
  4. onready var cnode_mat=get_node("decal").material_override
  5. onready var cspawn=get_node("spawn")
  6. onready var vptx=get_node("../material_id")
  7. var rp_counter=0
  8. func _ready():
  9. pass
  10. func new_decal_at(pos,abasis,mid):
  11. rp_counter+=1
  12. rp_counter=rp_counter%40
  13. var ccopy=cnode.duplicate(DUPLICATE_SCRIPTS)
  14. ccopy.material_override=cnode_mat.duplicate(false)
  15. ccopy.material_override.render_priority=rp_counter
  16. ccopy.set_local()
  17. ccopy.set_viewport(vptx.get_viewport().get_texture())
  18. ccopy.set_material_id(mid)
  19. ccopy.visible=true
  20. ccopy.translation=pos
  21. var bscale=ccopy.scale
  22. ccopy.transform.basis=abasis
  23. ccopy.scale=bscale
  24. cspawn.add_child(ccopy)
  25. bscale=ccopy.get_node("expl").scale
  26. ccopy.get_node("expl").transform.basis=abasis.inverse()
  27. ccopy.get_node("expl").scale=bscale
  28. func _process(delta):
  29. pass