GLSL: adding color from previous drawing

Started by
0 comments, last by V-man 12 years, 2 months ago
hi,

I'm trying to simulate lighting effect on my 2D scene. so for example i have a objects drawn in a flat plane, and then i want to give a lighting effect on the scene by highlighting a specific area. so if the light source position is at (0, 0), every pixel at distance less than radius (let say 4) has a brighter color.

Let say I draw the plane and objects with rgb (0.1, 0.1, 0.1). If its highlighted (based on the position and light radius) I want to update the color to (0.2, 0.2, 0.2). Is it possible to do that in openGL? How can I get the value of the current pixel on the fragment without using 2 buffers?


thanks in advance.
Advertisement
That requires RTT = render to texture
You render your scene to a texture. On the second step, you render to your back buffer and you sample that texture from your fragment shader.

However, I would just re-render the scene with the light. It is likely to perform much better than hacking around with RTT.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement