[Mod] Ray-traced explosion library/API [explosions]

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

[Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Wed Aug 15, 2018 22:51

Library for ray-traced explosions in Minetest

Ray-tracing can be used to simulate explosions in voxel games like Minetest. The biggest advantage of using it is the ability to make different materials have different blast resistance. I have been working on an API to create ray-traced explosions in Minetest. This mod is the implementation of that API. The idea is that this mod can be added as an dependency for other mods, which want to simulate explosions.

Features

  • Supports explosions of varying strength
  • Supports blast resistance, and provides default values for nodes in common mods (currently only the mods in Minetest Game)
  • Supports explosions of custom shapes (like an blast which only goes in one direction)
  • Callback functions for nodes which are affected by blast, to customize their behavior
  • Well optimized

Video

Here is a short video of the mod in action. Where I blow a hole in a mountain with TNT. https://youtu.be/84jLMwplM_o

Note that the video shows TNT from a test mod which uses the API from this mod. This mod only defines the functions documented above, not any blocks to actually test them.

Git repo

Here is the git repo. It contains all necessary documentation in the README. https://gitlab.com/ryvnf/explosions

TODO

  • Add sound effects (or maybe leave that to the user of the API)
  • Add particle effects (or maybe leave that to the user of the API)
  • Add knockback effect to entities near the explosion
  • Add default blast resistance for the nodes of additional common mods (like technic, moreores, etc)
  • Spawn drops from the explosion, allow nodes to specify how likely a drop is (to allow mining with dynamite)
Last edited by ryvnf_ on Thu Aug 16, 2018 09:49, edited 1 time in total.
 

User avatar
ChimneySwift
Member
 
Posts: 312
Joined: Fri Sep 22, 2017 06:46
Location: 127.0.0.1
GitHub: ChimneySwift
IRC: ChimneySwift
In-game: ChimneySwift

Re: [Mod] Ray-traced explosion library/API [explosions]

by ChimneySwift » Thu Aug 16, 2018 00:53

Woah!! That video looked really awesome! Much more realistic than the current TNT. +1
rm -rf dignity
 

User avatar
TenPlus1
Member
 
Posts: 2357
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1
 

User avatar
gpcf
Member
 
Posts: 251
Joined: Fri May 27, 2016 10:48
In-game: gabriel

Re: [Mod] Ray-traced explosion library/API [explosions]

by gpcf » Thu Aug 16, 2018 23:08

Is the TNT test mod available anywhere, for quick testing of this library?
 

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

Re: [Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Fri Aug 17, 2018 12:13

gpcf wrote:Is the TNT test mod available anywhere, for quick testing of this library?


I haven't made it public yet. I have a few more things I want to add to it.

I want it to be both a mod showcasing the API with different TNT:s of different strengths and shaped charges. It should also serve as a reference mod for people wanting to use the API. So I will make it public when I have an implementation that uses all parts of the API.
 

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

Re: [Mod] Ray-traced explosion library/API [explosions]

by rubenwardy » Fri Aug 17, 2018 12:16

This is very impressive looking! How well does it perform on a bigger explosion? Are you using the engine's raycast API?
 

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

Re: [Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Sat Aug 18, 2018 19:30

rubenwardy wrote:This is very impressive looking! How well does it perform on a bigger explosion? Are you using the engine's raycast API?


Thanks!

It does not use any raycast API. Everything is written in Lua. Is there an API available implemented engine-side usable by mods? That might be a way to increase the performance.

The mod is optimized in such a way that it will trace less rays for smaller explosions, but more rays for larger explosions. The amount of traced rays increases with r^2 (the surface area of a sphere). This is because tracing less rays would create artifacts (like floating nodes, or weird patterns) in the environment. Each ray is traced up to the explosions radius, r. So the total time complexity for tracing explosions or radius r is O(r^3).

While this sounds very bad. An explosion of strength 1600 which has a radius of 16 and 2562 rays will be traced immediately. The delay is barely noticeable. And generally, I don't think explosions larger than that are common, other than some "lol NUKE TNT lets blow everything up" mod.

The default mod doesn't support explosions with strengths above 1600 (it will trace the explosions, but expect them to create artifacts in the environment). This is to keep the base mod relatively lightweight. Supporting larger explosions would require storing more subdivisions of an ico-sphere in memory, which makes the memory of the mod go up several megabytes. I plan on making some kind of extension which extends the mod with more subdivisions, allowing for larger explosions.
 

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

Re: [Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Tue Aug 21, 2018 17:20

rubenwardy wrote:This is very impressive looking! How well does it perform on a bigger explosion? Are you using the engine's raycast API?


I read about it and I assume you are talking about the `Raycast` or `minetest.raycast` function.

I have tested the API function, and it has a quite major problem for being usable in this mod. And that is that the ray will never cross diagonals, this causes the amount of nodes a ray passes to be heavily dependent on the direction of the ray. By looking in a casting a ray 32 nodes in a cardinal direction, the ray can pass as few as 32 blocks. But as you cast the ray in a direction which is not cardinal, it will pass more nodes. I could personally get it up to 55 blocks (almost twice as much as the perfect case).

If each crossed nodes have a blast resistance, the ray going 55 nodes will die much faster than the ray going 32 nodes. Even though they are casted with the same distance. This wouldn't be a problem if the API had a way to tell how much distance a ray crosses through a node, which unfortunately it appears to lack.

So for now, the API will stick to having raycasting coded in Lua.
 

CrazyDave
New member
 
Posts: 1
Joined: Thu Aug 02, 2018 16:00
GitHub: DBHeise
In-game: CrazyDave

Re: [Mod] Ray-traced explosion library/API [explosions]

by CrazyDave » Wed Aug 22, 2018 14:39

Awesome! Great idea!

From the video it looks like the blocks are just moved, could it be possible to have the blocks not just moved but made ready to pickup/vacuum?
 

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

Re: [Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Thu Aug 23, 2018 19:53

CrazyDave wrote:Awesome! Great idea!

From the video it looks like the blocks are just moved, could it be possible to have the blocks not just moved but made ready to pickup/vacuum?


Yes!

I think I should explain what happens. The mod defines two types of node callbacks.

One callback `on_blast_break' gets called when a ray penetrates a node, the other callback `on_blast_shock' gets called when a ray hits a node but does not have enough strength to go through it.

The default behavior for `on_blast_break' is to remove the node. The default behavior for `on_blast_shock' is to make the node a falling node with a velocity proportional to the remaining ray strength.

This allows people to configure what happens on a per node basis. The mod currently does not spawn any drops from explosions. That is something that I still haven't decided on. I think maybe introducing drops as a default behaivor in `on_blast_break' might be a good idea. Problem is that too many drops might make large explosions quite heavy on the server.

But the node callbacks does allow you to specify a callback function which removes the node and makes it yield a drop. Which could be used to create drop from specific nodes (like minerals).
 

ryvnf_
New member
 
Posts: 6
Joined: Wed Aug 15, 2018 21:10
GitHub: ryvnf
IRC: ryvnf
In-game: ryvnf

Re: [Mod] Ray-traced explosion library/API [explosions]

by ryvnf_ » Thu Aug 23, 2018 19:54

I am currently working on entity damage and knockback. This requires doubling the raycast radius (if one wants damage to be twice the radius), which makes everything around 16x slower, if one wants the damage to be consistent around the radius of the explosion. (otherwise there will be special "holes" were rays miss, if player or entity stands in the "hole", it will not take any damage from the explosion).

As I would like everything to be as efficient as possible have worked to optimize the raycasting code.

I have managed to make it take around 31 % of the time it used to trace an explosion.

This was primary achieved by removing as much table creation (primary for vectors) as possible, and removing function calls. This comes with a big cost of readability, but I think it is worth it. The big bottleneck currently is the updating of entities (the flying nodes of the explosion), where there as far as I know is no way to create an entity, or updating its velocity without creating vectors. So there probably isn't much that can be done there.

One more thing I want to fix is that I notice the default undirected explosion shape will sometimes create artifacts if the explosion is detonated above ground. I think this might be solvable by changing switching the shape (currently the mod uses icospheres of various subdivisions exported from Blender).

So the mod isn't quite ready for public use yet. But it is getting there. I won't have much time to work on it the coming two weeks, but after that I hope to finish it and release it.
 


Return to WIP Mods



Who is online

Users browsing this forum: davidthecreator and 3 guests