User Tag List

Results 1 to 5 of 5

Thread: Help with a shader code, trying to create "Invert Blend Mask".

  1. #1
    Clicker

    Fusion 2.5 Developer
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    J3sseM's Avatar
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    868
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Help with a shader code, trying to create "Invert Blend Mask".

    Hey guys,

    I'm using Looki's "Invert Blend" shader, love it!

    However, I've several layers and I can't use it for each layer separately.
    Also I can't use it for "frame effect" as it would alter my interface.

    I was planning to use an "Active" object, set its effect to "Invert Blend Mask" and alter anything beneath it.
    Similar to Saturation Mask for example. I'm trying to create this shader by combining these two shaders:

    This is the code for Invert Blend:
    Code:
    // Global variables
    sampler2D fg;
    sampler2D bg : register(s1);
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    	float4 src = tex2D(fg,In);
    	float3 inv = 1.0-src.rgb;
    	float4 bck = tex2D(bg,In);
    	//Blend between src and inv based on |fore-back|
    	return float4(inv+(src.rgb-inv)*abs(src.rgb-bck.rgb),src.a);
    }
    
    technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}
    And for reference Saturation Mask:
    Code:
    sampler2D img;
    sampler2D bkd : register(s1);
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0	{
    	float4 srcPixel = tex2D(img,In);
    	float4 bgPixel = tex2D(bkd,In);
    	float fGrey = dot(bgPixel, float3(0.3, 0.59, 0.11));
     	bgPixel.rgb = lerp(fGrey, bgPixel, (srcPixel.r+srcPixel.g+srcPixel.b)/3.0).rgb;
    	return bgPixel;
    }
    
    technique tech_main	{ pass P0 { PixelShader = compile ps_2_0 ps_main(); }  }
    I suck with shaders. I've been trying to combine the "anything under" functionality from the Saturation Mask, but I'm not getting very far.
    Any idea? Is this even possible?

    Thanks!

  2. #2
    Clicker

    Fusion 2.5 Developer
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    J3sseM's Avatar
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    868
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Okay, my brain is malfunctioning. I thought I figured it out, but I'm not sure this is even doable.

  3. #3
    Clicker

    Fusion 2.5 Developer
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    J3sseM's Avatar
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    868
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Managed to do it, it was possible!

    Here's the code for "Invert Blend Mask":
    Code:
    sampler2D bkd;
    sampler2D bg : register(s1);
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    	float4 src = tex2D(bg,In);
    	float3 inv = 1.0-src.rgb;
    	float4 bck = tex2D(bkd,In);
    	return float4(inv+(src.rgb-inv)*abs(src.rgb-bck.rgb),src.a);
    }
    
    technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}
    That was quite educating couple of hours.

    EDIT: Btw, any way to add support for Alpha there?

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haven't touched shaders myself yet, but very curious as to how this effect would look

  5. #5
    Clicker

    Fusion 2.5 Developer
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    J3sseM's Avatar
    Join Date
    Feb 2013
    Location
    Finland
    Posts
    868
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It looks great, use black active, or white with rgb 0,0,0.

    I only need to figure how to enable "fade in and out" for it. Can't use RGB for it, so I somehow need to add support for alpha to it. I'm sure it's possible somehow.

Similar Threads

  1. Does "sharpen mask" shader exist?
    By J3sseM in forum Fusion 2.5
    Replies: 2
    Last Post: 22nd June 2015, 12:42 PM
  2. Limitation: "You can not make holes in the mask of collisions"
    By flyoffacliff in forum SWF/Flash Export Module Version 2.0
    Replies: 13
    Last Post: 21st November 2013, 01:45 AM
  3. Tilemap Pixel Shader (aka "texture atlas" shader)
    By MuddyMole in forum Hardware Accelerated Runtime
    Replies: 3
    Last Post: 10th May 2013, 08:21 PM
  4. Platform Movement Object - Invert Gravity : not "Standing on Ground"?
    By Oreo in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 4th April 2013, 04:29 PM
  5. Making shadows using the "Mask" effect
    By alxmrg in forum Hardware Accelerated Runtime
    Replies: 10
    Last Post: 15th June 2010, 01:01 PM

Posting Permissions

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