Shader: multiplying a sprite by another sprite that is somewhere in screen space. #2296
Unanswered
rudiHammad
asked this question in
Q&A
Replies: 1 comment 5 replies
-
You actually don't need a shader to perform this operation because OpenGL already does this for you, it's called blendfunc (Blend Function) you have to first make your spriteA above spriteB so that OpenGL can do color maths on the pixels behind. you can change the behaviour of blending function for a sprite using ax::BlendFunc f;
f.src = ax::backend::BlendFactor::SRC_COLOR;
f.dst = ax::backend::BlendFactor::DST_COLOR;
sprite->setBlendFunc(f); There are plenty of options that you should try out on both spriteA and spriteB to get your desired blending function. Here's a table of how these function operate on a per fragment (per pixel) basis https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am trying to make the following: I have spriteA and a spriteB. I want that when spriteA is on top of spriteB in screen space, the pixels of spriteA are multiplied by the pixels of spriteB that are overlaying. I have been trying this for a couple of day now without success. I did manage to do the following test.
2025-01-03.16-27-16.mp4
So as you can see, I am setting correctly the pixel in red when their position in screen space is bigger than half of the screen.
Here is the relevant part of the code:
and this is the fragment shader:
But here's where I got stuck. I have commented the lines that are supposed to take the second sprite and operate on it.
What I think I should do is mutiply spriteATxl by the spriteBTxl that is in the same position, but all my attempts didn't work.
How can I check for the screen position of the same pixel on both sprites to be able to multiply them?
thanks
Beta Was this translation helpful? Give feedback.
All reactions