How to code a Colorlize filter by shader?

Discussion in 'Rendering Technology and APIs' started by kumayu, Jul 21, 2008.

  1. Novum

    Regular

    Joined:
    Jun 28, 2006
    Messages:
    335
    Likes Received:
    8
    Location:
    Germany
    Wrong.

    A good approximation is:
    brightness = 0.3*red + 0.6*green + 0.1*blue
     
  2. kumayu

    Newcomer

    Joined:
    Jan 1, 2008
    Messages:
    32
    Likes Received:
    0
    No.
    I already know that.....
    But I don't want to get the brightness value of the pixel A.
    I want to have another pixel B that have the same brightness as A.

    -----------------------------------------
    I have seen the codes of Ycocg from nvidia's site.
    The code is simple, but no artist tools for convert dds file from rgb to ycocg.
     
  3. ryan

    Newcomer

    Joined:
    Apr 9, 2007
    Messages:
    2
    Likes Received:
    0
    Try this:

    Code:
    	float intensity = tex2D(intensitySampler, texcoords);
    	float3 color = tex2D(colorSampler, texcoords);
    	
    	float3 hueAndSat = color - dot(color, float3(0.33333333, 0.3333333, 0.3333333));
    	return float4(hueAndSat + intensity.xxx, 1);
    
    It works by removing the intensity from the color texture and replacing it with the intensity texture. hueAndSat is the projection of the color onto the intensity=0 plane.
     
  4. kumayu

    Newcomer

    Joined:
    Jan 1, 2008
    Messages:
    32
    Likes Received:
    0
    Thanks a lot.

    First try to palette textures using texture lookup
    I think it's easier than color space tricks.

    //======================================
    uniform sampler2D idx; // image in gray color as index
    uniform sampler2D pal; // 256X4 Map as palletize map.
    // It's a grad map , white to black,
    // then colorize it in photoshop
    varying vec2 UV;
    void main(void)
    {
    float index = texture2D(idx, UV).y; //get index , a float between 0.0~1.0
    vec2 newUV = vec2(1.0-index , 0.0); //use index as UV.x
    newUV.x = clamp(newUV.x , 0.1 , 0.9);
    vec4 color = texture2D(pal,newUV); //get palletize color
    gl_FragColor = vec4(color.xyz, index.w); //done
    }
    //======================================
     
  5. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    17,884
    Likes Received:
    5,334
    enemy engaged comanche vs hokum uses the method of a colorised grey texture for its terrain
    its open source too
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...