I am trying to make a procedurally generated island. I think I am almost finished with actual terrain generation part using OpenSimplex noise, only thing left is making it into a island surrounded by water. For that I am using a radial gradient Texture something that looks a bit like the picture below:
Only issue is I don't know how to get the Gradiant value. Preferably I am looking for a function that can return value from 0-1 based on the white and black areas of the map. I checked docs countless times and searched online, only thing I could find is get_offset()
function but I am not sure how it works or if its what I am looking for. Thanks in advance.
If you want to read the pixels of a Texture
from GDScript, you need to:
Texture
. GradientTexture2d
is a Texture
.Image
of the Texture
by calling the get_data
method.lock
method on the Image
, so you can access the pixels. Remember to call unlock
later.get_pixel
method or the get_pixelv
method on it, which gives you a Color
.unlock
method on the image
.On the other hand, if you want to work with the Gradient
from GDScript, you need to:
interpolate
method on the Gradient
which gives you a Color
. You can get the Gradient
of a GradientTexture2D
by reading the gradient
property.Either way, you would have a Color
. Now, you probably want to read one of the channels of the Color
. For that you can access the r
, g
, b
and a
properties of the Color
. If your image is gray scale, the r
, g
, b
properties of the Color
s you get from it should be equal, so either of them will do.
Addendum: On Godot 4.x we no longer need to use lock
/unlock
.