How can you do Ray Casting in Minetest?

User avatar
Me Me and Me
Member
 
Posts: 50
Joined: Sun Jul 03, 2016 21:08
Location: Vulcan, in the leftmost star of Orion's Belt
In-game: MeMeandMe2 Regulus

How can you do Ray Casting in Minetest?

by Me Me and Me » Fri Apr 13, 2018 01:19

Hi! I'm trying to make a beam-like gun in minetest,
and I know in some game engines you use "Ray Casting" to emit the beam.
So I was wondering, is there an easy way to do that in minetest?

Thanks, Me Me and Me.
I Love Formspecs!
 

User avatar
rubenwardy
Moderator
 
Posts: 5244
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Fri Apr 13, 2018 10:34

If you search for raycast lua_api, you'll see there's a function called minetest.raycast
 

User avatar
stu
Member
 
Posts: 878
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Re: How can you do Ray Casting in Minetest?

by stu » Sat Apr 14, 2018 19:05

Me Me and Me wrote:Hi! I'm trying to make a beam-like gun in minetest,
and I know in some game engines you use "Ray Casting" to emit the beam.


Do you mean like a laser-beam? If so then that is not really what ray-casting means in game-engine terms. `minetest.raycast` is generally used to detect objects or nodes that intersect an imaginary line (or ray) which may be useful to tell if your gun has actually 'hit' anything but will not emit any kind of beam.

AFAIK it should be possible to project some sort of beam using particle effects.
 

User avatar
Me Me and Me
Member
 
Posts: 50
Joined: Sun Jul 03, 2016 21:08
Location: Vulcan, in the leftmost star of Orion's Belt
In-game: MeMeandMe2 Regulus

Re: How can you do Ray Casting in Minetest?

by Me Me and Me » Tue Apr 17, 2018 01:45

stu wrote:Do you mean like a laser-beam? If so then that is not really what ray-casting means in game-engine terms. `minetest.raycast` is generally used to detect objects or nodes that intersect an imaginary line (or ray) which may be useful to tell if your gun has actually 'hit' anything but will not emit any kind of beam.

AFAIK it should be possible to project some sort of beam using particle effects.

Thanks stu, I'll use particles for the beam in my gun mod.
I Love Formspecs!
 

sofar
Developer
 
Posts: 1600
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Tue Apr 17, 2018 05:03

Me Me and Me wrote:Thanks stu, I'll use particles for the beam in my gun mod.


particles may not work as there's no `yaw` and `pitch` value for particles, so you can't make a `line` that follows an arbitrary 3d vector. You'll have to get really smart with mesh entities to do it, or use a bajillion particles.
 

twoelk
Member
 
Posts: 1202
Joined: Fri Apr 19, 2013 16:19
Location: northern Germany

Re: How can you do Ray Casting in Minetest?

by twoelk » Tue Apr 17, 2018 13:59

no beacons possible that may guide me home from far away? - sigh, no working pharus of Alexandria then
 

sofar
Developer
 
Posts: 1600
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Tue Apr 17, 2018 15:48

twoelk wrote:no beacons possible that may guide me home from far away? - sigh, no working pharus of Alexandria then


Beacons are vertical, so you can use particles. But a beam that isn't vertical isn't easy to make with a particle.
 

User avatar
sorcerykid
Member
 
Posts: 737
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
In-game: Nemo

Re: How can you do Ray Casting in Minetest?

by sorcerykid » Tue Apr 17, 2018 16:19

It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.
 

User avatar
stu
Member
 
Posts: 878
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Re: How can you do Ray Casting in Minetest?

by stu » Tue Apr 17, 2018 16:46

sofar wrote:particles may not work as there's no `yaw` and `pitch` value for particles, so you can't make a `line` that follows an arbitrary 3d vector. You'll have to get really smart with mesh entities to do it, or use a bajillion particles.

Oh, I was not aware of this limitation. I have not done much with particles and was actually thinking about how you used them for lightning, of course that is rather different to a linear directional beam.

I still wonder if you did project enough particles continuously with the right velocity that it could appear like a straight beam due to persistence of vision. You'd have to try it I guess. And yes, doing this with entities would be very cumbersome and probably would not work too well in multiplayer.

sorcerykid wrote:It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.


I would also like a way to draw 3d lines in the world space that might be managed in a similar way to particles, however, I think the best we could hope for is 'glow' for the time being. I think that dynamic lighting will not be making it into MT 0.5.0 =)
 

sofar
Developer
 
Posts: 1600
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Tue Apr 17, 2018 17:03

sorcerykid wrote:It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.


Particles can't emit light, but they can appear to be `lit` to max light values, which is what the lightning mod uses to make the lightning bolt appear brightly in the sky. This can be used to create effects that at least have some illusion of creating light.

I then add a `fire` node at the impact site that actually does emit light. Good enough for lightning, and the method may be usable by other mods to do similar things.
 

sofar
Developer
 
Posts: 1600
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Tue Apr 17, 2018 17:07

stu wrote:I still wonder if you did project enough particles continuously with the right velocity that it could appear like a straight beam due to persistence of vision. You'd have to try it I guess. And yes, doing this with entities would be very cumbersome and probably would not work too well in multiplayer.


Trivial with a particle generator and some simple math that calculates the proper 3d vector and puts it in velocity, and calculate the speed value such that the particles disappear right at the target. However, the amount of particles needed to get a good visual may be problematic, and cause the client to drop FPS.
 

User avatar
stu
Member
 
Posts: 878
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Re: How can you do Ray Casting in Minetest?

by stu » Tue Apr 17, 2018 17:41

sofar wrote:Trivial with a particle generator and some simple math that calculates the proper 3d vector and puts it in velocity, and calculate the speed value such that the particles disappear right at the target. However, the amount of particles needed to get a good visual may be problematic, and cause the client to drop FPS.

Yeah, that's kinda what I was thinking about. In theory though, particles should be really inexpense in terms of client FPS, sadly I realise that this is not quite the case for MTE right now.
 

twoelk
Member
 
Posts: 1202
Joined: Fri Apr 19, 2013 16:19
Location: northern Germany

Re: How can you do Ray Casting in Minetest?

by twoelk » Tue Apr 17, 2018 18:16

didn't irrlicht have something like spotlight?
 

Astrobe
Member
 
Posts: 32
Joined: Sun Apr 01, 2018 10:46

Re: How can you do Ray Casting in Minetest?

by Astrobe » Tue Apr 17, 2018 19:33

Sorry a bit OT, but what would be your advice for having fireworks arrows light briefly the neighborhood? I'd like to use them in mines (I believe they may be better balance-wise than torch arrows). Maybe create a temporary glowing node? Can I create for instance a glowing air node or something like that?
 

sofar
Developer
 
Posts: 1600
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Tue Apr 17, 2018 21:04

stu wrote:Yeah, that's kinda what I was thinking about. In theory though, particles should be really inexpense in terms of client FPS, sadly I realise that this is not quite the case for MTE right now.


with this merge: https://github.com/minetest/minetest/pull/6072

it should be possible, likely, to do this entirely client side, which would significantly increase the amount of particles you could generate if you needed more than 1 particle spawner. And you'd get zero-latency visuals.

I tested an early CSM particle PR and easily could do 2k particles per second I think.
 

User avatar
rubenwardy
Moderator
 
Posts: 5244
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Tue Apr 17, 2018 21:33

sofar wrote:with this merge: https://github.com/minetest/minetest/pull/6072

it should be possible, likely, to do this entirely client side, which would significantly increase the amount of particles you could generate if you needed more than 1 particle spawner. And you'd get zero-latency visuals.

I tested an early CSM particle PR and easily could do 2k particles per second I think.


That helps when you need to modify spawner positions a lot, but that is not the reason particles are slow in most cases. The reason is we use a scene node *per particle*. This causes a large amount of calls to the GPU
 

User avatar
stu
Member
 
Posts: 878
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Re: How can you do Ray Casting in Minetest?

by stu » Wed Apr 18, 2018 16:28

rubenwardy wrote:The reason is we use a scene node *per particle*. This causes a large amount of calls to the GPU

Well yeah, that ought to do it :D Although it does beg the question, why we don't use Irrlicht's built-in support for particle systems, IParticleSystemSceneNode & friends?
 

User avatar
rubenwardy
Moderator
 
Posts: 5244
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Wed Apr 18, 2018 19:31

Because the pr was sloppily made and should never have been merged
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest