Hello!
I'm new in shaders and GLSL.
I am trying to create plane with texture and apply on it shader, which edit texture that is at my plane.
What I need, is to have all pixels of texture in array.
I don't know so much about shaders, I tried search something about my problem but nothing found.
This is image what I am trying to do:
I need to edit pixel by pixel, to edit texture.
I don't know how to access resolution of texture and how to access specified pixels, like X=3,Y=22,Z=6.
Sorry for this strange description of my problem, but my english is very bad and i don't know how to describe
GLSL Shader pixel editing
you simply can't.
The fragment program let's you change each pixel one by one. You can of course calculate the position of the pixel that is processed by using the texture coordinates and multiply it with the resolution of your texture:
gl_Textcoord[0].st * vec2(512.0,256.0)
but I'm sure you don't want that. if you want to draw always the same on the texture you can just use two textures and blend them appropriately.
If you want to edit a texture pixel by pixel you should better lock the texture and then use the setPixel method
The fragment program let's you change each pixel one by one. You can of course calculate the position of the pixel that is processed by using the texture coordinates and multiply it with the resolution of your texture:
gl_Textcoord[0].st * vec2(512.0,256.0)
but I'm sure you don't want that. if you want to draw always the same on the texture you can just use two textures and blend them appropriately.
If you want to edit a texture pixel by pixel you should better lock the texture and then use the setPixel method
It's literally impossible for a shader to change an input texture. However, you can use the shader to sample the input texture and generate an output based on that. If you render that output to an RTT, you can then lock your output texture and have access to its pixels.
When you sample textures, you do so using UV coordinates, normalized from 0 to 1. To sample a specific pixel, store the resolution of the texture in shader variables, then divide the pixel coordinate by the resolution to get the UV coordinate for that pixel.
I hope that helps.
When you sample textures, you do so using UV coordinates, normalized from 0 to 1. To sample a specific pixel, store the resolution of the texture in shader variables, then divide the pixel coordinate by the resolution to get the UV coordinate for that pixel.
I hope that helps.