Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may want to render a black rectangle with alpha going from 1.0 to 0.0 using glBlendFunc (GL_ONE, GL_SRC_ALPHA).</p> <p>Edit in response to your comment (reply doesn't fit in a comment):</p> <p>You cannot fade single pixels depending on their age with a simple fade-to-black operation. Usually a render target does not "remember" what has drawn to it in previous frames. I could think of a way to do this by alternatingly rendering to one of a pair of FBOs and using their alpha channel for it, but you needed a shader there. So what you would do is first render the FBO containing the pixels at their previous positions, decreasing their alpha value by one, dropping them when alpha == 0, otherwise darkening them whenever their alpha decreases, then render the pixels at their current positions with alpha == 255.</p> <p>If you only have moving pixels:</p> <pre><code>render FBO 2 to FBO 1, darkening each pixel in it by a scale (skip during first pass) render moving pixels to FBO 1 render FBO 1 to FBO 2 (FBO 2 is the "age" buffer) render FBO 2 to screen </code></pre> <p>If you want to modify some scene (i.e. have a scene and moving pixels in it):</p> <pre><code>set glBlendFunc (GL_ONE, GL_ZERO) render FBO 2 to FBO 1, reducing each alpha &gt; 0.0 in it by a scale (skip during first pass) render moving pixels to FBO 1 render FBO 1 to FBO 2 (FBO 2 is the "age" buffer) render the scene to screen set glBlendFunc (GL_ONE, GL_SRC_ALPHA) render FBO 2 to screen </code></pre> <p>Actually the scale should be (float) / 255.0 / 255.0 to make the components equally fade away (and not one that started at a lower value become zero before the others do).</p> <p>If you only have a few moving pixels, you could re-render the pixel at all previous positions up to 255 "ticks" back.</p> <p>Since you need to re-render each of the pixels anyway, just render each one with the proper color gradient: Darker, the older the pixel is. If you have a real lot of pixels, the dual FBO approach might work.</p> <p>I am writing ticks, and not frames, because frames can take a varying amount of time depending on renderer and hardware, but you probably want to have the pixel trail fade away within a constant time. That means you need to dim each pixel only after so-and-so many milliseconds, keeping their color for the frames in between.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload