Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprite blend mode - Similar to Multiply on Unity

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Nov 2014 06:53 Edited at: 19th Nov 2014 11:43
Hi guys, does anyone know how to make a blend shader for sprites similar to additive blending but that will work on the dark and light parts of the image? Additive currently adds anything over 0,0,0. What I want is a shader that adds anything over 128 and subtracts anything under so that it can be used to shade dark and light areas using one image.

Any help would be much appreciated. I've scoured the forum for an old post by Paul where he shared the additive blend shader to use as a reference but I can't find it.

EDIT: Added image
EDIT: DOWNLOAD EXAMPLE PROJECT

Attachments

Login to view attachments
Ched80
13
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 12th Nov 2014 07:46
Would you be doing this on individual sprites or applying it to the whole screen?

Sprite shaders only support a single image, but the screen Quad can support up to 7. That's the reason for my question. I.e. Writing a screen shader to do this might be easier.

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th Nov 2014 11:08
I'd love to see this particular area expanded. Additive blending is good but I'd like to see many more. As an expansion, I'd like these blend modes to include using one sprite to cut away other sprites or the opposite.

Perhaps V3?
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 12th Nov 2014 13:46
Quote: "As an expansion, I'd like these blend modes to include using one sprite to cut away other sprites or the opposite."


I noticed a command a couple of days ago, something like SetSpriteMask() which takes an image I think. May not be what you need but you should check it out if you have not already.

@baxslash - I have been writing some blending shaders recently so I will take a look at what you are requesting, do you have a test project setup or anything you could share?

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 12th Nov 2014 18:06
I honestly expected more than just an additive blending mode when V2 features promoted "Sprite Blending Modes" and still feel this is one of the biggest missing pieces of AGK. Most other GL-based engines support, at a minimum:

Quote: "GL_ZERO
GL_ONE
GL_DST_COLOR
GL_SRC_COLOR
GL_ONE_MINUS_DST_COLOR
GL_ONE_MINUS_SRC_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
GL_SRC_ALPHA_SATURATE"


And many have Photoshop-style blendmodes as well, including:

Quote: "Normal
Multiply
Screen
Overlay
Darken
Lighten
ColorDodge
ColorBurn
SoftLight
HardLight
Difference
Exclusion
Hue
Saturation
Color
Luminosity"


A lot more could be achieved in AppGameKit with proper blend mode support.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Nov 2014 22:14 Edited at: 18th Nov 2014 13:35
Quote: "Would you be doing this on individual sprites or applying it to the whole screen? "

Fullscreen would work fine for what I have in mind...

Quote: "@baxslash - I have been writing some blending shaders recently so I will take a look at what you are requesting, do you have a test project setup or anything you could share?"

Not yet but I could whip something up as an example... I'll post something soon...

I agree that a range of blend modes would be great even if on a sprite by sprite basis.

EDIT: added image

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Nov 2014 13:33 Edited at: 19th Nov 2014 11:42
I couldn't find a good example of using those GL blend modes so I hacked my own fullscreen shader which will be more than adequate for what I wanted to do.

Attached is a full example of 3 fullscreen shaders Additive, Subtractive and the one I wanted Multiplicative. It's a hack based on the fullscreen shader examples that come with AppGameKit but it works just right for me. I hope others find it usefull!

The secondary image will subtract and add to the scene colours so you can easily 'fake' lighting in a 2D scene by drawing lit areas in lighter colours and shadows as darker areas. Here I am using a pure white "light" on a pure black background but ambient light could be done as a lighter base colour and "lights" could be any colour you like.

Here are example images:


[img]http://[/img]

EDIT: new download - 19th Nov 2014

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Nov 2014 13:36 Edited at: 18th Nov 2014 13:36

Attachments

Login to view attachments
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 18th Nov 2014 14:58
Great ! thank you very much.
Do you think it's possible to use this as an eraser for example ?

(I'm developping a little paint appli, and I look for the method to have an eraser)

http://www.dracaena-studio.com
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Nov 2014 15:10
Not really as it is. You'd be better perhaps making something specific for the purpose. I was going to write one for a paint app I've been working on but never considered using a shader. If I get time I'll post an example but in the meantime here's a sepia shader I wrote for another thread:
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 18th Nov 2014 18:49
Thanks.

I'm very interested by your example of an eraser. For the moment, I will tried to use the shader Multiplicative to see if I can use it as an eraser (temporary).

http://www.dracaena-studio.com
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Nov 2014 20:20 Edited at: 25th Nov 2014 11:45
I've made some improvements to subtractive and multiplicative which I'll share when I get a chance... much better effect.

EDIT: Uploaded image

Attachments

Login to view attachments
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 19th Nov 2014 08:16
My brand new computer, complained about missing something, and only the first effect appeared, at 3000 FPS. The other two were all black screens, but still at 3000 FPS

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Nov 2014 11:38 Edited at: 19th Nov 2014 12:15
Ok, thanks guys. Can someone post what the error is? Might help a little...?

Here is a screenshot from a simple lighting system I'm starting for a future project 100 'lights' at a pretty decent framerate, although I think I can improve on the framerate still and I'll never be using that many lights in one scene! EDIT: Got the framerate up to nearly 300fps for the same scene now!

I've updated the shaders in the original project and added a sepia tone shader (not used in the project):


DOWNLOAD

My new engine using this system has a simple main file that looks like this:


The example shown above looks like this in my game file:


The engine takes care of the rest. I'm looking forward to adding some clever tricks I have been desperate to come up with once I got this shader working. watch this space...

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Nov 2014 11:39 Edited at: 25th Nov 2014 11:46
Here's the improved multiply shader in action on one of my WIP's:


Without the shader:

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-28 14:51:27
Your offset time is: 2024-03-28 14:51:27