Home Technical Talk

Shader - Mutiple Gradient Ramps stacked Vertically

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Hey to all,

I was wondering if anyone knew a way I would be able to Gradient Map my model using a Mask, BUT at the same time, having it driven via the Lambert term?

Example of what I mean: http://technical-eden.blogspot.ca/2012/01/gradient-mapping-awesome-way-to-get.html

As you can see, mutiple vertically stacked ramps, and pending on the index, etc you can move it around as you see fit, however, my biggest issue is when I try and mix a Lambert term in it, I get derpy results, like edges of my model bleed neighboring colors and darkens everything around it.

Anyone has advice about this? Cheers!

Replies

  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Lambertian term should output a value of 0.0-1.0 depending on how the sampled point is being lit. Use that value and feed it into the V-coordinate(or U depending on ramp direciton) of the UV-lookup of your ramp. Your would probably get color artifacts where values near 0.0 and 1.0 are. Set the ramp texture on the sampler not to wrap here, instead clamp(?). Don't know the exact words, but you want the texture not too loop, but rather keep the colors at the extreme if the UV is out of the bounds. If this doesn't work you could probably clamp the lambertian term output before you feed it as an UV value, as to not go too near 0.0 or 1.0 if these values are problematic.

    With this method you should be able to feed through as many textures as you want. You could scale, shift and clamp the values as well to sample on diffrent ranges within a single ramp texture, etc.

    Can't say for certain how this holds up performance wise, but I'm fairly certain that this should be a possible way to do it.
  • Farfarer
    Options
    Offline / Send Message
    All you do is get half-lambert and feed it in as U coord, then get your other value (however you want to select the gradient you want from the stack) and feed it in as the V coord to your ramp look-up.
    float NdotL = dot ( lightDir, normal ); // Lambert - we'll make it half-lambert when we feed it in as the U coord (i.e. compress it from -1 to 1 range to the 0 - 1 range). That way it can be used as a proper texture coordinate.
    float rampSelector = texture2D ( rampSelectorTex, uvCoords ).r; // Or whatever it is you want to use to select the row you want from the gradient...
    float3 ramp = texture2D ( rampTex, float2 ( NdotL * 0.5 + 0.5, rampSelector ) );
    

    Ensure you set the ramp texture wrap mode to clamp and not repeat (otherwise you get some dark spots appearing at the top end and bright spots appearing at the bottom end). Sometimes turning off mips for the ramp texture can help, too.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Mucho thanks guys, cheers :D
  • Gestalt
    Options
    Offline / Send Message
    Gestalt polycounter lvl 11
    Keep in mind you DO NOT want to import your gradient map textures (the greyscale ones) with sRGB checked, that will throw off your values. You can leave it checked for the actual gradient though (the colors). Also keep in mind to make sure that you're not tiling (clamp the x and y) or using mips for the gradient, that could be where some of your bleeding problems are coming from, especially since you're stacking them, you don't want any mips on the gradients.

    Edit: oops some of this was already said, but hopefully there's some helpful troubleshooting
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, yes, totally forgot about SRGB, will keep the box open, cheers!
  • Bigjohn
    Options
    Offline / Send Message
    Bigjohn polycounter lvl 11
    Ace-Angel wrote: »
    Hey to all,

    I was wondering if anyone knew a way I would be able to Gradient Map my model using a Mask, BUT at the same time, having it driven via the Lambert term?

    Example of what I mean: http://technical-eden.blogspot.ca/2012/01/gradient-mapping-awesome-way-to-get.html

    As you can see, mutiple vertically stacked ramps, and pending on the index, etc you can move it around as you see fit, however, my biggest issue is when I try and mix a Lambert term in it, I get derpy results, like edges of my model bleed neighboring colors and darkens everything around it.

    Anyone has advice about this? Cheers!

    wow... this just blew my mind. Thanks for sharing that dude. It never occurred to me to use a texture as if it was one part of the UV coordinate. I feel like my brain just grew by 0.1%
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
Sign In or Register to comment.