Difference Blend

BlitzMax Forums/BlitzMax Programming/Difference Blend

Retimer(Posted 2008) [#1]
Is there a way to emulate 'difference' blending? We have lightblend, shade, alpha, but what about some other effects (that run well during real-time)? I did a quick search but didn't find anything useful.

Example of some effects I would like to achieve:




Perturbatio(Posted 2008) [#2]
I suspect shaders are your fastest route.


ImaginaryHuman(Posted 2008) [#3]
There are some blends you can do, for example by setting the blend mode in OpenGL, which are not currently implemented in Max2D. You could try playing around with that. For example you can make an image draw `bright` by adding it to itself or multiplying its color values by its own color values. You can also multiply colors in the source by colors in the dest, for what it's worth. There is also a possibility of using GL_COLOR_LOGIC_OP which lets you do logic operations at the end of the pipeline - like inverse, and, or, xor, not, etc. You can't easily do a subtract but you can do inverse + add. Isn't different just a subtraction of one value from another? Some of the more advanced blend modes you'll probably have to resort to some clever tricks or use shaders. It looks like most of the color changes in the image above are to do with altering the color values, like a hue shift or a color overlay.


Perturbatio(Posted 2008) [#4]
Although I get reasonable speeds from this using 64x64 image over a 640x480 (have yet to try larger):



Retimer(Posted 2008) [#5]
Thanks Perturbatio. Unfortunately i've decided to support multi-os and lower end pcs in my engine, so shaders are out of the question for this project :-(, although i'll definitely mess around with them in my next.

I remember doing something similar in vb6 and directx, but I couldn't say how things would come out in bmax trying to use the same effect with optional opengl&dx. I'll give it a run though, thanks imaginary.


tonyg(Posted 2008) [#6]
You can get a copy of mfctex or D3DMulTex for DX or OGLMultex for OGL. These tools allow you to visualise different blend modes and then produce the code you would need (at a DX/OGL level) to create that blend.
You would then need to change the code to match the Bmax driver syntax :
d3d7graphicsdriver().direct3ddevice7().SetTextureStageState(

There is an example of using different blend modes here