New modder, some questions

Post Reply
nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

New modder, some questions

by nfries88 » Post

Hey everyone, I'm new to minetest/modding but I had a game idea that minetest seemed pretty good for so I'm giving it a try, I just have some questions.

I've already read the modding book and the source of some mods to get a feel for it, and I've already written a mod adding a hud displaying some useful info for making the first few mods I want to work on, which are basically immersive look and feel mods. If you know similar mods already exist, let me know! I'm not trying to reinvent wheels here :)

==Clouds==

The first is I want to do something about minetest's clouds. The ones built into the sky box spawn as a layer one node thick while real world clouds are usually hundreds of meters thick with irregular 3D shapes, and the clouds don't change color vibrantly enough to really capture the beauty of sunset and sunrise. I see there's a default:cloud included with minetest game, but it just uses a flat white texture and doesn't seem to be used for anything.

I know I could spawn it as an ore in air, the problem is with changing the colors of the different faces. Ideally the face most directly getting lit by the sun would be yellow, adjacent faces would be red, and the faces not getting any sunlight would be a slightly purplish dark gray.

It looks like best results would be gotten by registering new nodes for sunrise and sunset clouds based on height so that the correct faces are the right color, and then swapping the individual nodes from default:cloud to the appropriate new cloud node depending on time of day. This has the downside of potentially having to change tens of thousands of cloud nodes in an instant.

But an acceptable compromise would be to simply change the textures of default:cloud to the appropriate sunrise and sunset ones, then change them back for night and day. But I don't see an API for changing the textures of a registered node, would just changing the data in the minetest.registered_nodes table work?

There's also the problem of clipping at the edge of loaded mapblocks. I know there's no way to completely get around this, but with the default loading distance even scaled down clouds that are relatively near the player will get clipped. How can I expand the distance at which mapblocks are loaded, whether in settings or in scripts?


UPDATE: I tried just placing some sunset-colorized clouds on top of stuff and it looks okayish if the blocks are between you and the sunset (although the yellow face isn't visible at all), but it looks awful if you're looking the opposite direction. Seems like to do sunrise/sunset clouds right it needs to be based on the individual player's location, which I have no clue how to do.

==Wind==

I'd also like to add wind that's actually able to knock leaves off trees, kick up sand, etc at high speeds. This doesn't have to match the real-world physics of wind at all, and the wind doesn't need to be super consistent (missing rows of blocks is okay). I kind of imagine this as just spawning entities at random locations which are "wind emitters", and these "wind emitters" in turn spawn "wind" entities that head in random directions, gradually decelerate, cause "wind" and "dust" particles when they pass relevant nodes, and cease to exist when they run out of speed. Is this something feasible? Does anyone know how many actively moving entities will stress the engine?

nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

Re: New modder, some questions

by nfries88 » Post

I've continued dabbling with the clouds and found that making clouds a colorized, nearly opaque liquid node type and using an ABM to change the color based on light level actually produces the desired effect at sunset with a couple caveats:

1) light level is too coarse-grained, so cloud colors change very rapidly and in large groups, making a very weak effect
2) the angle of light from the sun doesn't seem to change as the sun sets, so the bottom nodes change instead of the nodes farthest from the sun

So I think I need to emulate the scattering of light inside the clouds by counting the number of cloud nodes between a particular node and an air node in the direction of the sun, and selecting color based on that count.

This brings me to new questions:
1) Is there an existing way to estimate the position of the sun, or at least a reasonable normal vector towards the sun, based on the game's time-of-day? Or do I just gotta play around with /time and come up with my own estimations?
2) Is there a way for a mod to change the lighting direction for the sun and moon?

This also got me thinking about the skybox; its set from static images, but I didn't see any image composition API available. Seems like a serious limitation for a game engine to not allow programmatic composition of images when textures make up so much of its visuals. I suppose I could roll my own as a mod if Lua has built-in binary file I/O support though.

nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

Re: New modder, some questions

by nfries88 » Post

I have had some success with estimating the sun's unit vector based on time of day, and increasing the range of the palette I'm using for some nicer gradients.

Ofc now that I'm playing with actually having these clouds generate in worlds, it seems that nodes in map blocks without a player don't run ABMs even when they're visible?

Image
clouds.png
clouds.png (80.63 KiB) Viewed 454 times

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: New modder, some questions

by Nathan.S » Post

I'm pretty sure this is how it works.
The abm running is controlled by the

Code: Select all

active_block_range
setting in minetest.conf. Mapblocks that are outside of that range won't have their ABMs run, even if they are visible to players.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

Re: New modder, some questions

by nfries88 » Post

Nathan.S wrote:
Sun Sep 20, 2020 23:07
I'm pretty sure this is how it works.
The abm running is controlled by the

Code: Select all

active_block_range
setting in minetest.conf. Mapblocks that are outside of that range won't have their ABMs run, even if they are visible to players.
considering that my game froze when I set this to 256 I'm thinking that would've worked and I need to do something different. Right now I'm using ABMs with a chance=16 and coloring the clouds with a recursive function (since I have to use get_node() along the sun's vector to calculate the distance sunlight is traveling through the cloud anyway, I figured this would be better than running an abm for every cloud), this was working smoothly on even very large clouds with the default active block range. Thanks, I'll keep playing around!

EDIT: clearly this is talking about map blocks, not nodes, so I set that value ridiculously high. 16 is doing what I was hoping for with only a tiny bit of lag, but how big is a map block?

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: New modder, some questions

by GreenXenith » Post

YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

Re: New modder, some questions

by nfries88 » Post

I'm having trouble with voxelmanip now. I'm trying to work on generating clouds, I figured I'd start with generating an ellipsoid and add noise after I got that working.

unfortunately my clouds are only sometimes generating as expected. often pieces are fragmented off, sometimes at quite a distance from where they should be. I tried using logs to find the problem, but everthing in the logs is as I expect it to be.

Image

Finally I decided to just place one cloud node at a time to figure out what was going on

Code: Select all

nates_clouds.create_cloud_at = function(pos, vm, e1, e2)
	local random_range = function(prng, rmin, rmax)
		local resdivisor = rmax - rmin
		return math.abs(rmin + (prng:next() % resdivisor))
	end
	-- create cumulus cloud
	local maxlen = 16
	local p0 = {x=pos.x - (maxlen / 2), y=pos.y-(maxlen/2), z=pos.z-(maxlen/2),}
	local p1 = {x=pos.x + (maxlen / 2), y=pos.y+(maxlen/2), z=pos.z+(maxlen/2),}
	
	if(vm == nil) then
		vm = minetest.get_voxel_manip()
	end
	minetest.log("creating cloud centered at" .. minetest.pos_to_string(pos))
	e1, e2 = vm:read_from_map(p0, p1)
	minetest.log("emerged range" .. minetest.pos_to_string(e1) .. " " .. minetest.pos_to_string(e2))
	local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
	local id_air = minetest.get_content_id("air")
	local id_cloud = minetest.get_content_id("nates_clouds:cloud")
	local seed = minetest.get_mapgen_setting("seed")
	-- generate different radiuses for ellipsoid centered on pos
	seed = seed + (vector.length(pos) * 1000)
	local rand = PcgRandom(seed)
	local rx = 1--random_range(rand, maxlen/2, maxlen-2)--rand:rand_normal_dist(maxlen/2, maxlen-2, 8)
	local ry = 1--random_range(rand, maxlen/2, maxlen-2)--rand:rand_normal_dist(maxlen/2, maxlen-2, 8)
	local rz = 1--random_range(rand, maxlen/2, maxlen-2)--rand:rand_normal_dist(maxlen/2, maxlen-2, 8)
	
	minetest.log("radii: " .. rx .. " " .. ry .. " " .. rz)
	
	local inv_rxsq = 1.0 / (rx * rx)
	local inv_rysq = 1.0 / (ry * ry)
	local inv_rzsq = 1.0 / (rz * rz)
	local vmdata = vm:get_data()
	
	for z=p0.z, p1.z do -- north/south
		local zsq = z - pos.z
		zsq = zsq * zsq
			for y=p0.y, p1.y do -- up.down
				local ysq = y - pos.y
				ysq = ysq * ysq
					--local idx = area:index(p0.x, y, z)
					for x=p0.x, p1.x do -- east/west
						local xsq = x - pos.x
						xsq = xsq * xsq
						local idx = area:index(x, y, z)
						if(vmdata[idx] == id_air) then
							if(	(xsq * inv_rxsq) + (ysq * inv_rysq) + (zsq * inv_rzsq) < 1.0) then
								vmdata[idx] = id_cloud
								minetest.log("placing cloud at (" .. x .. ", " .. y .. ", " .. z .. ")")
							end
						end
						idx = idx + 1
					end
				
			end
	end
	vm:set_data(vmdata)
	vm:write_to_map()
end
according to my log, it should have been placed at the expected position:

Code: Select all

-------------
  Separator
-------------

2020-09-27 06:45:53: ACTION[Main]: World at [C:\Users\nfrie\Desktop\minetest-5.3.0-win64\bin\..\worlds\Unnamed66206]
2020-09-27 06:45:53: ACTION[Main]: Server for gameid="nates_testbed" listening on 0.0.0.0:51342.
2020-09-27 06:45:55: ACTION[Server]: singleplayer [127.0.0.1] joins game. List of players: singleplayer
2020-09-27 06:46:02: ACTION[Main]: Server: Shutting down
2020-09-27 06:46:32: ACTION[Main]: World at [C:\Users\nfrie\Desktop\minetest-5.3.0-win64\bin\..\worlds\Unnamed66206]
2020-09-27 06:46:32: ACTION[Main]: Server for gameid="nates_testbed" listening on 0.0.0.0:61939.
2020-09-27 06:46:33: ACTION[Server]: singleplayer [127.0.0.1] joins game. List of players: singleplayer
2020-09-27 06:46:39: WARNING[Server]: Assignment to undeclared global "player" inside a function at ...64\bin\..\games\nates_testbed\mods\nates_clouds\init.lua:240.
2020-09-27 06:46:39: [Server]: creating cloud centered at(17.380001068115,1013.9130249023,-172.45401000977)
2020-09-27 06:46:39: [Server]: emerged range(0,992,-192) (31,1023,-161)
2020-09-27 06:46:39: [Server]: radii: 1 1 1
2020-09-27 06:46:39: [Server]: placing cloud at (17.380001068115, 1013.9130249023, -172.45401000977)
2020-09-27 06:47:04: ACTION[Main]: Server: Shutting down
2020-09-27 06:47:31: ACTION[Main]: World at [C:\Users\nfrie\Desktop\minetest-5.3.0-win64\bin\..\worlds\Unnamed66206]
2020-09-27 06:47:31: ACTION[Main]: Server for gameid="nates_testbed" listening on 0.0.0.0:51413.
2020-09-27 06:47:32: ACTION[Server]: singleplayer [127.0.0.1] joins game. List of players: singleplayer
The cloud should have been placed at 17, 1014, -172 right? I was right next to it at 28, 998, -172 according to the HUD


UPDATE: This seems to have been an error involving floating point multiplication in area index calculation? Snapping the initial position to an integer position seems to have resolved my issue.

UPDATE 2 (new problem): My new voxelmanip method for creating and coloring the clouds is working quite well, and quite a bit faster than my get_node()/set_node() scheme. I'm having problem with mod storage now, though. When I create a cloud, I add it to an array of clouds and then store that array in mod storage using:

Code: Select all

--update storage
	cloud_store.numclouds = cloud_store.numclouds + 1
	cloud_store.cloud_areas[cloud_store.numclouds] = {center=pos, p0=p0, p1=p1,}
	minetest.log("added cloud: ".. cloud_store.numclouds)
	mstore:from_table(cloud_store)
and at initialization, I attempt to load the storage using:

Code: Select all

-- load clouds from storage
	mstore = minetest.get_mod_storage()
	local cloud_storage = mstore:to_table()
	if(cloud_storage)then
		if(not cloud_storage.numclouds)then
			mstore:from_table({numclouds=0, cloud_areas={}})
		else
			cloud_store = cloud_storage
		end
	end
	
(mstore and cloud_store are both file-scoped local variables, cloud_store is initialized like in the call to mstore:from_table)
This set up would be ideal because I can know the exact areas of the map I have to manipulate to update colors, instead of having to try to find cloud regions within an ABM or searching the map for clouds, but it never loads as expected so the cloud areas are lost between runs.

UPDATE 3: I resolved this issue by switching to using minetest.serialize/minetest.deserialize and mstore:get_string / mstore:set_string. I think mstore:from_table()/mstore:to_table serve some slightly different purpose than I thought?
Attachments
brokencloudgen.png
brokencloudgen.png (17.02 KiB) Viewed 454 times

Sokomine
Member
Posts: 4289
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: New modder, some questions

by Sokomine » Post

I'm afraid clouds are a bit large for any changes to be done to them each MT day. Won't it make more sense to play with the skybox, perhaps changing even the engine instead of the world?
A list of my mods can be found here.

nfries88
New member
Posts: 6
Joined: Fri Sep 11, 2020 06:08

Re: New modder, some questions

by nfries88 » Post

Sokomine wrote:
Mon Sep 28, 2020 16:20
I'm afraid clouds are a bit large for any changes to be done to them each MT day. Won't it make more sense to play with the skybox, perhaps changing even the engine instead of the world?
Actually I'm changing every cloud within 512 blocks of a player every 32ms (so roughly every other frame). One cloud doesn't really impact performance at all, but one has to wonder about multiple clouds, especially for servers. Right now I'm only spawning cumulus clouds (the little puffy ones you see in nice weather), scaled down pretty far to compensate for the limited reasonably performant view/generation radius of minetest.

To test the performance impact of working on too many clouds at once, I spawned 8 clouds in tight proximity and moved myself to near the center of them. My dtime jitter roughly doubled, but overall fps only declined by the same amount as if the mapgen was generating a new area nearby. I did notice that as I moved around in that update radius, it seemed to stall loading the map from the disk which wasn't great. Still, I'm learning a lot about minetest modding, and that's really the point right now! :)

Image

As far as changing the skybox, I agree that if I could generate images dynamically then updating the skybox would probably be superior.
Attachments
cloudsdtime.png
cloudsdtime.png (256.57 KiB) Viewed 454 times

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: New modder, some questions

by MisterE » Post

perhaps try using entities? entities can change their properties dynamically so they might be better suited. I would be worried though about not being able to see clouds at all, because they were too high up to be shown to the player usually. Or, they would be spawnned or placed too close to the player, and when the player came near by climbing or building, teh effect would be ruined. So, IDK

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests