User Tag List

Results 1 to 10 of 10

Thread: Reflection filter, can it support shape?

  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)

    Reflection filter, can it support shape?

    Hey guys!

    I'm trying to create a small puddles. Reflection filter would be perfect for my purposes, unfortunately though I can't modify it to support the alpha channel of it's own image.
    Say I have an active object with circle image in it, I'd like Reflection Filter to only reflect inside this area. Or alternatively use black and white colors instead of an alpha channel.

    Here is the code for Reflection Filter made by Pixelthief.

    Code:
    sampler2D bg : register(s1);
    float fCoeff, fBlend;
    int Mode;
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    	if (Mode == 1){
    		if (In.y < fCoeff){
    			In.y = (- In.y / fCoeff) + In.y + 1;
    		}
    	}
    	else if (Mode == 2){
    		if (In.x < fCoeff){
    			In.x = (- In.x / fCoeff) + In.x + 1;
    		}
    	}
    	else if (Mode == 3){
    		if (In.x > fCoeff){
    			In.x = ((In.x - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	else {
    		if (In.y > fCoeff){
    			In.y = ((In.y - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	return float4(tex2D(bg,In).rgb,1.0-fBlend);
    }
    
    technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}
    Any idea how to achieve this?

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,299
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I haven't tested this, but it should be very easy...

    Firstly, you need to prepare it to sample the image (this goes at the very top).
    Code:
    sampler2D img;
    Next, somewhere inside the ps_main function, you sample the image to get the alpha value.
    Code:
    float4 alpha = tex2D( img, In );
    Finally, you multiply the calculated alpha by the sampled alpha (you could actually just remove all references to "fBlend", as you don't need it any more).
    Code:
    return float4(tex2D(bg,In).rgb,(1.0-fBlend)*alpha);

    If you're interested, there's a brief discussion on reflection effects over here:
    http://create-games.com/forum_post.asp?id=302442

  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)
    Thanks MuddyMole!

    I did a few steps right earlier it seems, so close.
    Thanks again, I will try this in hour or two and report back!

  4. #4
    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)
    Tried it and I was able to make it work!

    I haven't done a proper testing yet, but with a quick look it seems to work. This will be very useful for small detail, thanks MuddyMole!

    Here's the code in case someone wants to try:

    Code:
    sampler2D img;
    sampler2D bg : register(s1);
    float fCoeff, fBlend;
    int Mode;
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    float4 alpha = tex2D( img, In );
    	if (Mode == 1){
    		if (In.y < fCoeff){
    			In.y = (- In.y / fCoeff) + In.y + 1;
    		}
    	}
    	else if (Mode == 2){
    		if (In.x < fCoeff){
    			In.x = (- In.x / fCoeff) + In.x + 1;
    		}
    	}
    	else if (Mode == 3){
    		if (In.x > fCoeff){
    			In.x = ((In.x - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	else {
    		if (In.y > fCoeff){
    			In.y = ((In.y - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	return float4(tex2D(bg,In).rgb,1.0-fBlend)*alpha;
    }
    
    technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}
    Thanks!

  5. #5
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,299
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I think you need a couple more brackets in that return statement. Right now it's calculating "float4(tex2D(bg,In).rgb,1.0-fBlend)" and then multiplying all of that (the r, g, b and a components) by "alpha" - but you only want to multiply "(1.0 - fBlend)" (ie. the a component). As long as the alpha is either 0 or 1, it won't actually make any difference, but if it's anywhere in between you'll find that as pixels get more transparent, they also get darker.

    There was a slight mistake in what I wrote before - it should be this:
    Code:
    return float4(tex2D(bg,In).rgb,(1.0-fBlend)*alpha.a);
    (I forgot the ".a")

  6. #6
    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)
    Hey MuddyMole,

    Ah that makes sense. I thought there were something funny with the result earlier, though it seemed to work just fine.
    I updated the last line with your code and I can confirm it works beautifully!

    Thanks again mate, you're a real shader-wizard!

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    Wow those look wonderful guys
    Great job!

  8. #8
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    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)
    Wodjanoi's Avatar
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    650
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    The modified code of the shader effect is included here. You need to download Reflection filter shader and then you can easily setup the shader for your own use.

  9. #9
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    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)
    Wodjanoi's Avatar
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    650
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Download here: https://sites.google.com/site/mmf2stuff/shaders

    And here is the full code again with new alpha support(praise Pixelthief, MuddyMole and J3sseM):

    Code:
    sampler2D img;
    sampler2D bg : register(s1);
    float fCoeff, fBlend;
    int Mode;
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    float4 alpha = tex2D( img, In );
    	if (Mode == 1){
    		if (In.y < fCoeff){
    			In.y = (- In.y / fCoeff) + In.y + 1;
    		}
    	}
    	else if (Mode == 2){
    		if (In.x < fCoeff){
    			In.x = (- In.x / fCoeff) + In.x + 1;
    		}
    	}
    	else if (Mode == 3){
    		if (In.x > fCoeff){
    			In.x = ((In.x - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	else {
    		if (In.y > fCoeff){
    			In.y = ((In.y - 1) * fCoeff) / (fCoeff - 1);
    		}
    	}
    	return float4(tex2D(bg,In).rgb,(1.0-fBlend)*alpha.a);
    }
    
    technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}

  10. #10
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    bybyblue's Avatar
    Join Date
    Sep 2011
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This was extremely helpful thanks for coming up with this!

Similar Threads

  1. Graphics Filter, Audio Filter, and Transition SDK
    By kraminator in forum Extension Development
    Replies: 7
    Last Post: 27th March 2011, 08:40 PM
  2. Horizon reflection
    By EdibleWare in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 10th January 2011, 09:35 PM
  3. [Suggestion] Extra shape for Window Shape object
    By LIJI in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 5th March 2007, 06:32 AM
  4. car reflection effect
    By thewreck in forum File Archive
    Replies: 13
    Last Post: 12th February 2007, 06:39 PM
  5. Water reflection
    By AsparagusTrev in forum File Archive
    Replies: 16
    Last Post: 6th November 2006, 08:49 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
  •