Godot Version
4.4.1
Question
Hi everyone,
I followed a tutorial and make a function to get color of a pixel using ray-casting method. The result came very quick in Forward+ renderer, but in Compatible, it runs very slow , around 3~4 seconds.
My plan is making a webgame , the map is a big bmp file, and this is not very good. Is there any solution?
func _on_player_province_selected(coord) -> void:
var province_color = province_map.get_image().get_pixel(coord.x*10, coord.y*10)
var selected_prov = $Provinces.color2province[province_color]
print(selected_prov)
pass
func shoot_ray():
var mouse_pos = get_viewport().get_mouse_position()
var ray_len = 2000
var from = camera.project_ray_origin(mouse_pos)
var to = from + camera.project_ray_normal(mouse_pos)*ray_len
var space = get_world_3d().direct_space_state
var ray_query = PhysicsRayQueryParameters3D.new()
ray_query.from = from
ray_query.to = to
var raycast_res = space.intersect_ray(ray_query)
if !(raycast_res.is_empty()):
var rx = raycast_res.position.x
#var ry = raycast_res.position.y
var rz = raycast_res.position.z
print("FOUND")
province_selected.emit(Vector2(rx,rz))
(these two functions are separated in each files)