We have implemented a glow map into our renderer. It basically uses a blur filter on the glow map pass. But, I cannot figure out how to do tracers in OpenGL. Someone suggested using a couple of textures that are saved between frames, ping-ponging them so to speak. However, I am stuck at the part where I need to implement it. My C++ code is:
glowmap_copier.use_program();
// create output temp texture, with texstorage
GLuint temp_tex;
glGenTextures(1, &temp_tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, temp_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, win_x, win_y, 0, GL_RGBA, GL_FLOAT, NULL);
glBindImageTexture(0, temp_tex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, temp_tex);
glUniform1i(glGetUniformLocation(glowmap_copier.get_program(), "output_image"), 0);
// activate glow and last frame glow input textures
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, glowmap_tex);
glUniform1i(glGetUniformLocation(glowmap_copier.get_program(), "inputa_image"), 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex);
glUniform1i(glGetUniformLocation(glowmap_copier.get_program(), "inputb_image"), 2);
// call compute shader
glDispatchCompute((GLuint)win_x, (GLuint)win_y, 1);
// Wait for compute shader to finish
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
// copy from temp to last frame using glCopyImageSubData
glCopyImageSubData(temp_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
last_frame_glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
win_x, win_y, 1);
glDeleteTextures(1, &temp_tex);
and:
// OpenGL 4.3 introduces compute shaders
#version 430
layout(local_size_x = 1, local_size_y = 1) in;
layout(binding = 0, rgba32f) writeonly uniform image2D output_image;
layout(binding = 1, rgba32f) readonly uniform image2D inputa_image;
layout(binding = 2, rgba32f) readonly uniform image2D inputb_image;
void main()
{
// Get global coordinates
const ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
const vec4 output_pixel = imageLoad(inputa_image, pixel_coords) + imageLoad(inputb_image, pixel_coords);
imageStore(output_image, pixel_coords, output_pixel);
}
An image of the glow effect is:
What I would like is to be able to accumulate the effect, and have it fade over time. Tracers, basically. Any ideas on how to do something like this in OpenGL 4? P.S. it seems that this problem is analogous to motion blur.
An example of the glow map is below. The glow map contains non-black data for the reaper's small eyes, as well as the 4 lights, and a small border around the game board. There is also an orange glowing thing, which represents the mouse location.