Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 08:25:12 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)OpenGL blend modes, using shaders
Pages: [1]
Print
Author Topic: OpenGL blend modes, using shaders  (Read 3344 times)
eri0o
Level 0
**


Making Adventures


View Profile WWW
« on: May 21, 2021, 02:03:28 AM »

Blend modes are the blending options like layers have in Photoshop, this is in a 2D game.

So, there are some blend modes that are possible to do with plain glBlend and similar functions, but I had to use glTexEnvi while doing it and it's not available in OpenGL ES 2.0, and I would like to be able to have blend modes compatible with OpenGL ES 2.0 because I can easily turn it on WebGL compatible code using Emscripten.

Well, part of the magic of the glBlend functions is they happen without needing to "interrupt things" in the GL pipeline: https://stackoverflow.com/a/17666532

For using shaders to do it, like https://www.shadertoy.com/view/XdS3RW , say I am drawing things in the reverse z-order they are on screen, so what's in the background is draw first, and then what's on top of it, and so on up to the layer with biggest z-index. Well, I can't seem to figure out, how do I get the screen in each step into a texture, so I can blend using a shader?
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #1 on: May 21, 2021, 06:45:28 AM »

If you're looking to implement arbitrary effects that combine the results of previous geometry with new geometry, you're probably going to be in the realm of multipass rendering - as in, create an FBO and set it as your render target, draw some stuff to it, then use that as a texture input for further drawing so that you can read from it in a fragment shader. This will of course get very expensive as the number of passes increases.

A quick google search for "opengl programmable blending" had some informative results. From what I'm able to gather, it seems like some graphics pipelines do support it (iOS 6+ and Nvidia Tegra both showed up in that search), though I suspect you won't be able to get it reliably with WebGL at this point. Maybe someday in the future? It is unfortunate, but that's low-level graphics programming for you. If it were me, I'd probably try to break down my problem into something more specific than arbitrary Photoshop blend modes applied on an arbitrary number of layers per frame, and implement something efficient that just covers the exact use cases needed. Then again, you might be able to get away with the expensive multipass rendering option, depending on how heavily your game ends up using it.
Logged

eri0o
Level 0
**


Making Adventures


View Profile WWW
« Reply #2 on: May 28, 2021, 10:01:53 AM »

Thanks for the informations. I haven't yet figured out how to advance on this. I was surprised because I thought I would find this solved but turns out with Open GL ES 2.0 it's not so trivial.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #3 on: June 02, 2021, 04:55:17 PM »

Multi-pass isn't really expensive these days, a ton of games do lots of passes these days. It gives you a lot of flexibility as well.

Hell in the case of Unity, mutli-pass can the faster way to do a lot of things compared to camera stacking.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic