James |
I have made various modules to use so far but there is one thing i have had problems doing which is multiple alphas. Basically what i want to know is how do you layer multiple things together without effecting the colors with multiply or additions etc?
Currently i having done things like return r, g, b, mask with the mask being generated before and as the alpha which works fine if you just want a single layer with a alpha mask but i have yet to work out how to do this with more than 1 layer. Things like - return ((r1+r2)+(r3+r4))/4, ((g1+g2)+(g3+g4))/4, ((b1+b2)+(b3+b4))/4, ((a1+a2)+(a3+a4))/4 and a load of other things don't seem to work correctly so if possible does anyone have any tips on how to do layering multiple images/inputs with alpha masks correctly? |
|||||
Posted: June 10, 2010 6:06 am | ||||||
Mike Blackney
![]() |
Bad answer, but it depends on what you want to do.
Your code there is doing an average. Add four layers and divide by four. So doing an average of the alpha seems to make sense. What you need is a rule set. Do you want something like Photoshop, where layer order matters? If so, then first you need to do the operations in order. If what you want is something like Photoshop's multiply layer (where A is the bottom layer and B is the top) then what it does is take pixel color A, multiply it by pixel color B and then call this color Result. Then interpolate between A and Result, using the alpha of layer B. |
|||||
Posted: June 10, 2010 7:37 am | ||||||
Vladimir Golovin
Administrator |
We're planning to expose Filter Forge's blend function, both HDR and LDR versions, with all available blending modes, but I don't know when it will happen. Most likely, we'll add it after the official release of v2.0. |
|||||
Posted: June 10, 2010 8:01 am | ||||||
James |
Well what i basically mean is just layer like photoshop etc would do but without a layer mode applied so basically to put one above the last yet keep a different alpha for each.
So a example would be if i had say a solid red circle over transparent. Doing this as a single thing would be simple and the return for example like - return r1, g1, b1, circlemask Then above that a different layer with a solid blue square over transparent that is scaled down to appear within the red circle. As a single thing would be like - return r2, g2, b2, squaremask So basically what i would want is to see a solid blue square over a solid red circle with a transparent background. I could easily make 2 separate scripts and blend them as nodes but i want to do it all within 1 basically. The problem is i can't figure it out to get these results as it's like how you say i am getting some sort of average like you suggest using code like i posted before and it effects the colors with any maths i try. I am guessing if it's possible i am just not sure on the maths needed to mix between them yet, what mike suggests seems like the thing needed but i am not sure about the correct code to do it. Reading what Vladimir just said though it seems blending/layering above the last is not possible right now? Maybe if it is possible someone could post a basic example of stacking 4 layers each with a input and alpha input or something as that would show me exactly what i need i am guessing. Thanks for the help everyone |
|||||
Posted: June 10, 2010 9:20 am | ||||||
Sphinx.
![]() |
hi James
According to http://en.wikipedia.org/wiki/Alpha_compositing: function get_sample(x, y) -- fetch inputs local O = get_sample_grayscale(x, y, OPACITY) local Ra, Ga, Ba, Aa = get_sample_map(x, y, FOREGROUND) local Rb, Gb, Bb, Ab = get_sample_map(x, y, BACKGROUND) -- combine foreground alpha and master opacity Aa = O * Aa -- blend individual channels local Ao = Aa + Ab * (1 - Aa) local Ro = (Ra * Aa + (Rb * Ab) * (1 - Aa)) / Ao local Go = (Ga * Aa + (Gb * Ab) * (1 - Aa)) / Ao local Bo = (Ba * Aa + (Bb * Ab) * (1 - Aa)) / Ao return Ro, Go, Bo, Ao end; not at all optimized or anything.. but there you have it, alpha preserving blending |
|||||
Posted: June 10, 2010 10:31 am | ||||||
James |
This code seems to work well and shows the method for Alpha compositing i needed. Thanks Sphinx
![]() Edit - By the way talking about optimizations i am just wondering how optimized is Lua in comparison to standard nodes? Would rendering times be cut when using lua code if it replaced a task needing many standard nodes or does it have not much effect on the time it takes to render? |
|||||
Posted: June 10, 2010 11:12 am | ||||||
Vladimir Golovin
Administrator |
Generally, standard components are much faster, but connections between them introduce a slight overhead. It is difficult to say which approach would work better -- it heavily depends on the task. |
|||||
Posted: June 10, 2010 11:22 am | ||||||
Sphinx.
![]() |
Indeed! For my test case (mixed alphas and opacity), native blend rendered at 0.17 secs and the above function rendered at 0.72 secs. I tried optimizing a few bits here and there, but the lua parser seem to do some tricks by its own.. I only managed to tweak out a few milisecs. Here is the "optimized" version:
|
|||||
Posted: June 10, 2010 11:51 am | ||||||
Sphinx.
![]() |
FYI if you end up here, check out the new build blend functions in FF 3:
http://www.filterforge.com/features/v...t-api.html |
|||||
Posted: May 9, 2012 3:43 pm |
Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!
33,711 Registered Users
+18 new in 30 days!
153,531 Posts
+39 new in 30 days!
15,347 Topics
+72 new in year!
20 unregistered users.