I try to combine in the shader which renders the screen quad the total rays texture with the base texture. The first one contains all simple rendered cube light sources emitting godrays (algorithm based on this implementation:
https://lokeshsharma97.wordpress.com/20 ... ys-opengl/ the only difference is I don't add the colors of both textures in the one shader). The second texture contains just all rendered non-glowing mesh objects, in my case this is the room filled with some random furniture. How I combine is just adding colors from both textures:
Code: Select all
vec4 color = base_color + rays_color;
gl_FragColor = color;
GL blending is disabled in my rendered material, i.e.I use video::EMT_SOLID as a base material. How those textures and their combination result look like:
The base texture
The rays texture
The final texture
How you can see, the problem is that the total cube lights colors, especially of the red one, look like semi-transparent. However, in the rays texture they are fully opaque. I tried also to bypass this problem calculating luminance of the given rays color and using this as an alpha component:
Code: Select all
float luminance = dot(rays_color, vec3(0.3, 0.59, 0.11))/3.0; // I divide by 3.0 because I suppose this is the maximum value that the dot product can output, such way normalizing this
// The brighter the given fragment of the rays, the higher its opacity
vec4 color = (1.0-luminance)*base_color + luminance*rays_color;
gl_FragColor = color;
However, that doesn't render the rays around the light sources leaving only the cubes themselves. How could I combine them correctly?