简体   繁体   中英

OpenGL : Blending & feedback effect

I'm struggling on a simple project, as an example/sandbox, I'm rendering a small oscillating rectangle on my output. I'm not using glclearcolor() but instead, on every frame I draw a black rectangle before anything else, blending with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;

My goal is to see as I play with the alpha of this black rectangle feedback of previous frames, slowly fading, some kind of trail, and it's more or less working.

My main problem though, the trail never really disappears, and the longer I try to get the trail, the worse it gets. Also, I have to quite crank the alpha before seeing any trail, I don't really understand why.

在此处输入图像描述

The default OpenGL framebuffer only uses 8 bits for each color component. You can increase this by using a custom framebuffer backed by floats, or 16 or 32-bit components.

I'm not sure whether not using glClearColor is the proper way to implement motion trail. It's possible that the last bit of alpha blending runs into precision/rounding problem, where 0.9 * 0x01 might give you back 0x01 (for each rgba octet). (although I would be surprised you can see the difference but who knows). If that's not the case I would switch to a proper glClearColor and then create a trail of boxes similar to how you do the leading box, with deterministic decay/resource freeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM