User Tag List

Results 1 to 8 of 8

Thread: Need help creating a "sharpen mask" shader.

  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)

    Need help creating a "sharpen mask" shader.

    Hey guys!

    I've been looking a shader like this. Basically I would apply it to an active object, and the shader would sharpen anything underneath it.
    I know one exists for "blur", so I'm sure it's possible for "sharpen" as well. I've been trying to create this shader but so far I haven't succeed.

    Though I'll admit, I'm not really good with shaders but hey, I'm learning!

    Anyways, this is a shader (.fx) code for "sharpen" by Sphax - Flavien Clermont!

    Code:
    // Pixel shader input structure
    struct PS_INPUT
    {
        float4 Position   : POSITION;
        float2 Texture    : TEXCOORD0;
    };
    
    // Pixel shader output structure
    struct PS_OUTPUT
    {
        float4 Color   : COLOR0;
    };
    
    // Global variables
    sampler2D Tex0;
    float fCoeff;
    
    PS_OUTPUT ps_main( in PS_INPUT In )
    {
        // Output pixel
        PS_OUTPUT Out;
    	
    	Out.Color = tex2D(Tex0, In.Texture.xy);
    	Out.Color -= tex2D(Tex0, In.Texture.xy+0.001)*fCoeff;
    	Out.Color += tex2D(Tex0, In.Texture.xy-0.001)*fCoeff;
    	
        return Out;
    }
    
    // Effect technique
    technique tech_main
    {
        pass P0
        {
            // shaders
            VertexShader = NULL;
            PixelShader  = compile ps_2_0 ps_main();
        }  
    }
    I would only use a single color active, so I wouldn't need a complex code. I've been playing with bkg; and img; but so far no luck.
    I'll keep trying, and I'll post here if I can figure it out. But, if any of you shader geeks sees this thread and the solution would be rather simple, I'd truly appreciate it if you could point it out!

    Cheers!

    Jesse

  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)
    I haven't figured this out yet, I'm sure it's doable though. :>
    Just bumping in case someone better with shaders could take a quick look.

  3. #3
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    There's room for improvement, but it should probably be good enough:
    http://onedrive.live.com/redir?resid...int=file%2czip
    (if the link doesn't work, just look for "SharpenMask.zip")

  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)
    MuddyHole you're my hero, did you write this?
    EDIT: Oh or was it Sketchy (based on "CS_Sharpen" shader by Sphax - Flavien Clermont)?

    Exactly what I was looking for. At first I couldn't get it to work though, but I noticed that if the object you apply the shader to isn't bigger than 256x256 it doesn't display correctly, a bug perhaps?
    But this is not an issue, I'll just use 256x256 active and scale it accordingly, thanks a million!

    Oh, I will take some time to study how this is done, really impressive. Thank you again!

  5. #5
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    MuddyMole (Clickteam forums) == Sketchy (The Daily Click)
    If you open up the shader, there are a couple of places where it uses a value of 0.002 - if you play around with that value, I'm guessing you should probably be able to get it to work how you want for any image/object size. Shaders are resolution independent, and for a sharpen filter (which deals with adjacent pixels) to work properly, it would need to know the dimensions of the texture, which would therefore need to be passed as parameters. It just seemed like a lot of hassle, and to be honest, I didn't test the shader very thoroughly, so I didn't notice the issue!

  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)
    Aah I see! Well brilliant job anyway, I'll most definitely test this properly on Monday but I'm pretty confident it will work for my purposes perfectly.

    Thanks again, you've been extremely helpful!

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Just updated it with a quick fix:
    https://onedrive.live.com/redir?resi...int=file%2czip
    Those values of 0.002 are now 1.0/width and 1.0/height, which must be passed as parameters. It appears to work okay, but again, I haven't tested it thoroughly...

    Shader language is actually super easy to work with, once you get your head around a few things.

  8. #8
    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)
    I'll update, thanks!

    Yeah I've been modifying some of the shaders (basically just including alpha parameter to control the "volume" of screen or color dodge) and I'm starting to understand how it works.
    I still lack the skill to create anything complex like that though, but after looking the code I can understand the most of it!

    Thanks man!

Similar Threads

  1. Replies: 4
    Last Post: 17th February 2016, 11:46 AM
  2. Does "sharpen mask" shader exist?
    By J3sseM in forum Fusion 2.5
    Replies: 2
    Last Post: 22nd June 2015, 01:42 PM
  3. 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, 02:45 AM
  4. Tilemap Pixel Shader (aka "texture atlas" shader)
    By MuddyMole in forum Hardware Accelerated Runtime
    Replies: 3
    Last Post: 10th May 2013, 09:21 PM
  5. Making shadows using the "Mask" effect
    By alxmrg in forum Hardware Accelerated Runtime
    Replies: 10
    Last Post: 15th June 2010, 02: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
  •