User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Layer Rather Than Add?

  1. #1
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Layer Rather Than Add?

    Hi,

    I have been making a few simple HWA effects recently and one problem i have is combining multiple elements. I can get them to all show ok with something like this for the return -

    Code:
    return 
            tex2D(Part01,float2(In1.x,In1.y)) * Mix01 +
            tex2D(Part02,float2(In2.x,In2.y)) * Mix02 +
            tex2D(Part03,float2(In3.x,In3.y)) * Mix03 +
            tex2D(Part04,float2(In4.x,In4.y)) * Mix04;
    But then if they overlap it adds the colors so the lightness grows rather than just layering as normal over the last. I have tried a few things like without the + and just using , etc but i can't seem to be able to do this.

    Does anyone know how to do this and display each element/layer above the last correctly?

  2. #2
    Clicker Fusion 2.5 DeveloperSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,739
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Layer Rather Than Add?

    Well, there might be some handy functions available to do this, I'm not an HLSL dictionary - But you basically have to blend the foreground over the background based on the foreground's alpha.

    Something like this:
    PHP Code:
    //A: Lower, B: Upper
    float4 Mix(float4 Afloat4 B)
    {
     
    float4 Output;
     
    Output.rgb A.rgb+(B.rgb-A.rgb)*B.a;
     
    Output.A.a+B.a;
     return 
    Output;
    }

    float4 Col1 tex2D(Part01,In1);
    float4 Col2 tex2D(Part02,In2);

    //Col2 over Col1
    float4 NewCol Mix(Col1,Col2); 
    Honestly I'm not 100% sure that it will work, but it should.

    Why are you using multiple 'In' variables by the way? Are you sure that you need them?
    Also, float2(In2.x,In2.y) is the same as just writing In2!

  3. #3
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    Hi, thanks for the reply.

    I tried the code but it did not seem to work unfortunately. I use in like that because i have a X and Y offset for each image used. The code you have seems to use colors but this was image and 4 of them.

    Other than all the control inputs and the pixel width and height (and also changing the input names from part to image now also) the main code was -

    Code:
    float4 ps_main(in float2 In1 : TEXCOORD0, 
    in float2 In2 : TEXCOORD0, 
    in float2 In3 : TEXCOORD0, 
    in float2 In4 : TEXCOORD0) : COLOR0
    {
    	In1.x += fPixelWidth+OffsetX1;
    	In1.y += fPixelHeight+OffsetY1;
    
    	In2.x += fPixelWidth+OffsetX2;
    	In2.y += fPixelHeight+OffsetY2;
    
    	In3.x += fPixelWidth+OffsetX3;
    	In3.y += fPixelHeight+OffsetY3;
    
    	In4.x += fPixelWidth+OffsetX4;
    	In4.y += fPixelHeight+OffsetY4;
    
    	return 
                    tex2D(Image01,float2(In1.x,In1.y)) * Mix01 +
                    tex2D(Image02,float2(In2.x,In2.y)) * Mix02 +
                    tex2D(Image03,float2(In3.x,In3.y)) * Mix03 +
                    tex2D(Image04,float2(In4.x,In4.y)) * Mix04;
    }
    It works fine in terms of using them all but it adds the colors, the solution you post might work but that seems to be different for 2 inputs and also color based.

    I have only just started to code HWA effects recently though so probably making lots of mistakes in my coding but it's working just not fully how i want yet.

  4. #4
    No Products Registered

    Join Date
    Aug 2006
    Posts
    984
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    try dividing:
    Code:
    	return 
                    (tex2D(Image01,float2(In1.x,In1.y)) * Mix01 +
                    tex2D(Image02,float2(In2.x,In2.y)) * Mix02 +
                    tex2D(Image03,float2(In3.x,In3.y)) * Mix03 +
                    tex2D(Image04,float2(In4.x,In4.y)) * Mix04) / 4.0;

  5. #5
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    It sounds like you want Lerp(). Lerp takes three parameters, blending between two using the 3rd.

  6. #6
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    xyzzy -

    Thanks but that does not work, it just seems to set down the transparency for all the layers.

    Dynasoft -

    I don't think Lerp() is what is needed but i might be wrong, i don't to blend 2 layers and also i wanted to add a transparency setting for each layer (Mix01 etc). That and the offset for each layer is why this seems it would not be what i want but maybe there is a certain way it could do this?

    -----

    Just to give a better example of what i mean, say if the input images were all just circles with the same size and position but with a different color for each.

    Layer 1 - Red Circle
    Layer 2 - Blue Circle
    Layer 3 - Green Circle
    Layer 4 - Orange Circle

    So if they all had no offset and the mix set to 1 (fully visible) then you would just see a Orange Circle. Then if you set all to have a Mix of 0 but the first which had a 1 you would just see a Red Circle. Then if you set the mix of Blue Circle (Layer 2) to 0.5 you would see a purple like circle and then if you set it to 1 instead you would only see the Blue Circle.

    So basically each layer just goes over the top of the last with no mix or blending etc unless it was set for a layer. That is the reason i set it up like that but using + at the return part of the code doesn't seem to work for layering like how i want.

  7. #7
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    Lerp does that. You lerp each image over the one below, so that a lerp param of 0 gives you the one below, a lerp param of 1 gives you the image above, and a lerp param of 0.5 gives you a 50:50 blend.

  8. #8
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    Quote Originally Posted by Dynasoft
    Lerp does that. You lerp each image over the one below, so that a lerp param of 0 gives you the one below, a lerp param of 1 gives you the image above, and a lerp param of 0.5 gives you a 50:50 blend.
    Thanks, this works

  9. #9
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    Quote Originally Posted by Atom
    I am not sure how to use this correctly when i use -

    Code:
    O1 = lerp(tex2D(Image01,float2(In1.x,In1.y)), tex2D(Image02,float2(In2.x,In2.y)), 1.0);
    
    	return O1;
    It shows nothing, other attempts would show a single input but as white, if possible could you give a basic example of how to merge with lerp() to do what i need.
    That's correct, it should work.

    Perhaps your texture samples contain no alpha? Does just a texture sample alone work?

    EDIT: Ha you changed you post.

  10. #10
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Aug 2006
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Layer Rather Than Add?

    Yeah sorry you must have read it before i edited

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Layer Object: Moving X and Y of layer is very slow
    By Bipolar_Games in forum Android Export Module Version 2.0
    Replies: 0
    Last Post: 5th April 2013, 02:19 AM
  2. Creating a new Layer: Layer referrances
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 17th October 2012, 12:44 PM
  3. Position layer using Layer Object
    By Sumo in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 4th October 2012, 06:51 AM
  4. Layer Object can't move counters to specific layer
    By JoKa in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 20th November 2007, 12:11 PM
  5. Bug when moving a layer with layer object
    By BrashMonkey in forum Multimedia Fusion 2 - Technical Support
    Replies: 11
    Last Post: 3rd July 2006, 12:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •