Sliced ground building it from height map using Uint8Array and one byte per height point

Creating a ground height map from a custom Uint8Array seems to be sliced by 1/4 of its height.

Some idea?

You need 3 times more values in the Uint8Array:

2 Likes

@docEdub It is actually 4 times more.

For what I see, Babylon uses the RGB values for the height map, ignoring the Alpha of the color.

I’m reading this in the docs: The whiter the pixel the higher the displacement, so it takes the maximum value of the three RGB bytes? Babylon.js docs

@Deltakosh just to confirm, is it like that?

Woudl it be right to documment in groundBuilder.d.ts , CreateGroundFromHeightMap @params url the next:

* @param url sets the URL of@paramsparamsparamsparamsthe height map image resource. Or an object `{ data: Image Uint8Array 4 bytes (RGBA) per height point using the max value from RGB and ignoring Alpha; width: widht of the image; height: height of the image }`

Yes this is correct!

you can see here that we build the final value from the overall luminance:
Babylon.js/packages/dev/core/src/Meshes/Builders/groundBuilder.ts at ce69ba2cc13f65f5da9bd3f355b7f23c379c0c3d · BabylonJS/Babylon.js

1 Like

Ok, I got it, thanks!

@docEdub please update your answer to 4 bytes instead 3, commenting the RGBA then I can select your answer for the solution.

1 Like

Sure, here’s the updated PG using 4 times more values: