GLSL Shader pixel editing

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

GLSL Shader pixel editing

Post by kazymjir »

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:
Image

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 :)
mk.1
Posts: 76
Joined: Wed Oct 10, 2007 7:37 pm

Post by mk.1 »

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
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

Post by kazymjir »

Hmm, it's not good.
I need to edit texture every frame (it will be RTT texture), locking texture and editing pixels in that way will generate high load on cpu.
I need to edit this texture using GPU.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

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.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

You don't need to use shaders to use the hardware to edit a texture, you can just use two render targets:
set render target 1, render the background image, render some 2d effects on top.
render target 1 is now your background image. set render target 2, repeat...
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

Post by kazymjir »

I can't use your soultions, because effect what i want to get seem be more complicated that i through.
Ill try make it later, when my skill will level up.

Thanks for replies and will to help me!
Post Reply