Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | toblin |
I’m working with shaders, where I want to provide a Texture3D
as input to the shader. To do so I need to define the data in the Texture3D
. But I’m having troubles doing so.
First I create my image, and set the value of its only pixel to 0.7, 0,0,0
:
var image = Image.new()
image.create(1, 1, false, Image.FORMAT_RGB8)
image.lock()
image.set_pixel( 0,0, Color(0.7, 0.0, 0.0, 0.0))
When I check the pixel value, it seems to have worked, as image.get_pixel(0,0)
gives me 0.698039,0,0,1
.
Then I try to use the image to define data in a Texture3D
var texture = Texture3D.new()
texture.create( 1, 1, 1, Image.FORMAT_RGB8 )
texture.set_layer_data(image, 1)
But when I check the pixel value, it has suddenly changed. texture.data['layers'][0].get_pixel(0,0))
gives 0,0,0,1
as output. And it doesn’t seem to work to set the pixel value after it has been entered into the texture:
texture.data['layers'][0].lock()
texture.data['layers'][0].set_pixel(0,0, Color(0.7, 0.0, 0.0, 0.0))
does not work as it gives the error set_pixel: Image must be locked with 'lock()' before using set_pixel()
.
So, why isn’t the above working? And a more open question is: how would one properly define the data in a Texture3D?
Shouldn’t it also be texture.set_layer_data(image, 0)
?
Tim Martin | 2020-09-09 12:38
You are correct! I came to the same conclusion independently =). Should have read your comment earlier xD.
toblin | 2020-09-11 07:50