Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AGS 4: reimplement custom Blend Modes using shaders #1885

Closed
ivan-mogilko opened this issue Jan 6, 2023 · 3 comments
Closed

AGS 4: reimplement custom Blend Modes using shaders #1885

ivan-mogilko opened this issue Jan 6, 2023 · 3 comments
Labels
ags 4 related to the ags4 development context: graphics

Comments

@ivan-mogilko
Copy link
Contributor

For Direct3D / OpenGL renderers the custom blend modes were implemented using standard alpha-blend operations, which seem to have two problems:

  • the result is not precise;
  • this may conflict with situations where we must use specific kind of alpha blending operations for other reasons.

The latter is now a real problem, after #1874: as the textures used as render targets for the group of sprites must be blended using very particular blend ops.

The proposed solution is to reimplement these Blend Modes using shaders.

My understanding is that in OpenGL shaders must include transparency, because it's currently done through a shader, although I cannot remember why that was made so (afaik this was a part of switching to a more contemporary OpenGL style). Existing shaders may be used as example.

Besides that, we need to decide whether Tint and LightLevel effects should apply along with the BlendMode or not. This decision will affect the complexity of this task.

@ivan-mogilko ivan-mogilko added context: graphics ags 4 related to the ags4 development labels Jan 6, 2023
@ivan-mogilko ivan-mogilko added this to the 4.0.0 (preliminary) milestone Jan 6, 2023
@ericoporto
Copy link
Member

ericoporto commented Jul 30, 2023

My understanding is that in OpenGL shaders must include transparency, because it's currently done through a shader, although I cannot remember why that was made so

I am not 100% sure, but it may be when the OpenGL ES2 version of the renderer was written, because OpenGL ES2 has a lot less things in its API.

Edit: we could move to OpenGL ES3, It may have a bit more things and is available in most devices - Apple added support to WebGL 2.0 in Safari in 2021 which mean it could be used in the Emscripten emulation nowadays.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Mar 25, 2025

After a brief discussion with @AlanDrake we are brought back to this idea, that maybe reimplementing blend modes as shaders will make things work better and/or implementing blend modes easier.

The problem is, I do not have an accurate picture of how do you replace blending with a shader. The shader runs over a input texture and produces an output, which is then rendered to the destination. But if we want to substitute blending to dest with a shader, then we'd need to have a shader that has both sprite texture and render target on input, and then the result of this shader still goes onto the render target.

Trying to imagine this logically, the result of a shader should be a "patch" for the render target that can be plain copied there without further alpha blending.
The shader inputs:

  • sprite texture
  • render target
  • relative sprite texture offset

The shader outputs:

  • pixels how they ought to appear on render target.

After this shader we use blend mode that plain copies values instead of mixing, that is: (GL_FUNC_ADD, GL_ONE, GL_ZERO).

Does this make a sense? Or is it done differently?


EDIT:
I tried searching any information about a similar technique on the web, and so far from the results that I found, the above is not a recommended thing to do. Some claim that having same framebuffer for reading and writing into is not supported, others that it may be supported by the modern hardware but won't have a good performance. Although I may as well be reading an outdated information.

I may make a test, but so far this idea seems questionable.

@ivan-mogilko
Copy link
Contributor Author

I will close this, because this idea might have been a mistake.

@ivan-mogilko ivan-mogilko closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: graphics
Projects
None yet
Development

No branches or pull requests

2 participants