Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Innorium |
Hi
I have a 256x256 Texture created in gdscript filled red.
dynImage.create(256,256,false,Image.FORMAT_RGBAF) // I tried different formats
dynImage.fill(Color(1,0,0,1))
I now set one pixel to black
dynImage.lock()
for i in range(1): //I tested with bigger ranges, it gets darker
for i2 in range(1):
dynImage.set_pixel(i,i2,Color(0,0,0,1))
dynImage.unlock()
make a ImageTexture and “send” it to the shader
imageTexture.create_from_image(dynImage)
material.set_shader_param("myTexture",imageTexture);
in the shader I try to access this pixel.
shader_type canvas_item;
uniform sampler2D myTexture : hint_black;
void fragment(){
if(int(UV.x*100.0)%2==0)
COLOR = texture(myTexture,vec2(0,0));
else
COLOR = texture(myTexture,vec2(0.1,0.1));
To test if it still has the color black I tried this:
if(texture(myTexture,vec2(0.1,0.1))==vec4(0,0,0,1))
COLOR = vec4(0,1,0,1);
}
What I receive is this.
If I change the range for i,i2 to 30 it is a black and get’s green by the test.
I tried to acess the pixel in the gd_script with get_pixel → still black as expected
Since I am more or less new to this stuff, I guess I missunderstand something.
My guesses would be, that there is some kind of image compression, I don’t know how to turn off.
What I want to do is to send raw image data to the shader and read the color pixel by pixel afterwards.
I am using Godot 3.1, if that is of importance.
Maybe someone can point out my mistake.
Thank you in advance
I’m glad I found this web site, I couldn’t find any knowledge on this matter prior to. Also, operate a site and if you are ever interested in doing some visitor writing for me if possible feel free to let me know, I’m always looking for people to check out my web site.
geometry dash
sloperun3az | 2019-04-19 12:20