User Tag List

Results 1 to 7 of 7

Thread: Issue: shader won't replace darker colors?

  1. #1
    Clicker Fusion 2.5 DeveloperMac Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Issue: shader won't replace darker colors?

    Based upon Looki's "Keep Color" shader I wrote a shader that takes 3 colors and replaces them with 3 new ones. (Or how many you put in the code)

    It works fine for almost all colors except for darker shades of gray? I noticed this happened with Looki's shader, too.

    For example, it will replace RGB (188,188,188), but it won't replace (119,119,119) or black (0,0,0)

    Here's the code for the shader:

    Code:
    sampler2D source;
    
    float4 replaceThis1, replaceWith1,replaceThis2, replaceWith2,replaceThis3, replaceWith3;
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
    {
    	float4 color = tex2D(source,In);
    
    	if(color.r == replaceThis1.r && color.g == replaceThis1.g && color.b == replaceThis1.b)
    		color.rgb = replaceWith1.rgb;
    
                          if(color.r == replaceThis2.r && color.g == replaceThis2.g && color.b == replaceThis2.b)
    		color.rgb = replaceWith2.rgb;
    
                          if(color.r == replaceThis3.r && color.g == replaceThis3.g && color.b == replaceThis3.b)
    		color.rgb = replaceWith3.rgb;
    
    	return color;
    }
    
    technique tech_main
    {
    	pass P0
    	{
    		PixelShader = compile ps_2_0 ps_main();
    	}
    }

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Ah, I always wondered if the fact that colors are floats would cause any trouble. I'm sure that's the problem here... rounding errors.

    Essentially you'll need a threshold to compensate that. There are 255 colors, and color values are from 0 to 1... so if a color is 1 unit brighter, the value increases by 1/255 ~= 0.0039

    The straight-foward, unelegant solution would be this: if (abs(color.r - replaceThis1.r) < 1/255.0 && .......same for g and b)

    It'd probably be a good idea to decrease the threshold though, because you don't want (0,0,0) to match (1,0,0) which might happen if you use 1/255... instead, 1/100 = 0.01 should be enough I think.

    But you can also shorten it by using some vector math. Just compare to the length of the vector that contains the color difference.
    if (length(color.rgb - replaceThis.rgb) < 0.015)
    No idea if 0.01 is a good threshold tbh, it's close to the length of the vector (0.01, 0.01, 0.01):
    sqrt(3 * (0.01^2)) = 0.0173205081

    Try it out and tell me if it works

  3. #3
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Looki View Post
    There are 255 colors
    Common mistake; there are actually 256
    Working as fast as I can on Fusion 3

  4. #4
    Clicker Fusion 2.5 DeveloperMac Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the "if (abs(color.r - replaceThis1.r) < 1/255.0 && .......same for g and b)" thing and it works now Thanks a lot.

  5. #5
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by LB View Post
    Common mistake; there are actually 256
    Ah, of course.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleInstall Creator ProPatch Maker
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Crian's Avatar
    Join Date
    Oct 2009
    Posts
    415
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Solgryn, I'm very interested in this, please can you share this shader?

  7. #7
    Clicker Fusion 2.5Android Export Module
    henryhissagames's Avatar
    Join Date
    Dec 2014
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    666 views. Illuminati confirmed

Similar Threads

  1. Replace colors not working
    By MattKapa in forum iOS Export Module Version 2.0
    Replies: 4
    Last Post: 27th April 2012, 01:15 AM
  2. Problem: Replace Colors
    By Hazzow in forum iOS Export Module Version 2.0
    Replies: 3
    Last Post: 1st December 2011, 08:17 AM
  3. FPS keeps dropping when I replace colors?
    By N64Mario in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 7th December 2008, 11:46 PM
  4. Replace a range of colors?
    By pinacoladaxb in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 12th January 2008, 01:07 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
  •