Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Multisplat16 working in procedural generation? #448

Open
Critsium-xy opened this issue Jun 2, 2024 · 3 comments
Open

How to get Multisplat16 working in procedural generation? #448

Critsium-xy opened this issue Jun 2, 2024 · 3 comments

Comments

@Critsium-xy
Copy link

If I create a new HTerrainData using code like this:

var terrain_data = HTerrainData.new()

And in generating procedure, I can get only one splatmap like this

var splatmap0: Image = terrain_data.get_image(HTerrainData.CHANNEL_SPLAT)

How can I get and edit other splatmaps?
If I tried like this, it will raise an error

var splatmap1: Image = terrain_data.get_image(HTerrainData.CHANNEL_SPLAT,1)
var splatmap2: Image = terrain_data.get_image(HTerrainData.CHANNEL_SPLAT,2)
var splatmap3: Image = terrain_data.get_image(HTerrainData.CHANNEL_SPLAT,3)

And finally, could you help describe how to edit this four splatmaps to assign 16 different materials? Thank you!

@Zylann
Copy link
Owner

Zylann commented Jun 2, 2024

var splatmap1: Image = terrain_data.get_image(HTerrainData.CHANNEL_SPLAT,1)

This is how you should be able to get them though. Maybe the reason you could not is because by the time you run this, the terrain doesn't even know that they are needed, so they aren't there, so it might cause an error.

The issue is that the API isn't really thought for setting up these maps from scratch by code. If you change the terrain to use Multisplat16 in the editor and paint a bit on it, then save, it will have the images when you get them from script.
If you don't want to do that, then you'd have to do what the painting tool does to add them, something like:

	var data = terrain.data
	while data.get_map_count(HTerrainData.CHANNEL_SPLAT) < 4:
		data._edit_add_map(HTerrainData.CHANNEL_SPLAT)

could you help describe how to edit this four splatmaps to assign 16 different materials? Thank you!

Not sure exactly what part you mean here. If you mean how to edit the splatmaps, then it's like a regular splatmap, except there are 16 weights across 4 images instead of just 4 weights in 1. You have to make sure they sum up to 1 across all images. Then it's just math.
In GDScript, the code for normalizing would be something like:

var d := splat0.r + splat0.g + splat0.b + splat0.a \
       + splat1.r + splat1.g + splat1.b + splat1.a \
       + splat2.r + splat2.g + splat2.b + splat2.a \
       + splat3.r + splat3.g + splat3.b + splat3.a
splat0 /= d
splat1 /= d
splat2 /= d
splat3 /= d

The editor uses shaders on a viewport instead of editing the images with GDScript:

float sum = sum(s0) + sum(s1) + sum(s2) + sum(s3);

@Critsium-xy
Copy link
Author

@Zylann Thank you! And I can do Globalmap baking in code?

@Zylann
Copy link
Owner

Zylann commented Jun 2, 2024

A globalmap is just like any other map, so you can do it in code too, however I don't think you can use the baker used in the editor. Or you'll have to do some digging to make it usable in-game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants