How to apply a glsl pixel shader to a texture?
How to apply a glsl pixel shader to a texture?
I have a texture and i would like to apply to it a glsl shader. Is it possible and how to do it ? For example i want to apply this glsl shader to my texture :
varying vec4 coord;
uniform sampler2D texture;
uniform float opacity;
void main() {
vec4 col = texture2D(texture, coord.xy);
col.a *= opacity;
gl_FragColor = col;
}
1 Answer
1
I would say create another texture empty and of similar properties of original texture. Attach this texture to fbo and send fbo and original texture in shader. Generate full quad pass of you size of texture. Read texel from original texture in shader apply your code from fragment shader and write value to fbo attached texture using gl_FragCoord. And tge attached texture is result you want.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I also think this question is too board (and close-voted accordingly.) The short answer is: render a full-screen quad (or even better: a full-screen triangle) while applying this as the fragment shader. The vertex shader can be quite trivial.
– derhass
Jun 30 at 17:24