I tried to implement a light cookie image, but I ran into a quirk, the texture projection does not take into account the depth buffer, as well as the direction of the normals, in addition to this it is projected into both sides. This video demonstrates this problem, I’m not sure if it’s a bug.
My code, which is nothing unusual.
tex_flashlight = Texture("Flashlight")
tex_flashlight.read("data/textures/flaight4.png")
tex_flashlight.set_wrap_u(Texture.WM_border_color)
tex_flashlight.set_wrap_v(Texture.WM_border_color)
ts_flashlight = TextureStage('ts_flashlight')
ts_flashlight.set_sort(100)
ts_flashlight.set_color(LVecBase4f(0, 0, 0, 1))
ts_flashlight.set_mode(TextureStage.M_add)
self.lens = PerspectiveLens()
self.lens.set_near_far(0.01, 100)
self.lens.set_fov(30)
slight = Spotlight('flashlight')
slight.set_lens(self.lens)
slight.set_exponent(128.0)
slight.set_color((20, 20, 20, 1))
slight.set_attenuation(LVecBase3f(0, 1, 0))
slight.show_frustum()
slight.set_shadow_caster(True, 1024, 1024)
self.node_path = NodePath(slight)
self.node_path.set_pos(0.5, 0.5, 1.2)
fps.world.project_texture(ts_flashlight, tex_flashlight, self.node_path)
It is worth noting that the lighting correctly takes into account the depth buffer.