0

I am trying to shade a surface with a sequence of colors to achieve certain visual effects. One effect is a gradient from one color to another. Assume I have a lookup texture with a black and a white texel. I apply the colors to the whole surface by selecting [0,1] of the color sequence. Linear interpolation creates a nice gradient. Now I want to repeat that sequence. Intuitively I would like to use a range of [0,2] and the gradient should be drawn twice along the surface.

But that creates a hard edge in the middle because each gradient takes up 50% of the surface. (a general issue, not GL specific) I could squeeze in a "hidden" texel and use some additional space to interpolate between the last and first color of the sequence. But then the scaling becomes ugly. A sequence applied to [0,1] along the surface would be slightly more than twice as long as each of the repeated sequences applied to [0,2].

Another effect is a repeated pattern to create stripes. There I do not need additional space between repeated sequences. E.g. a surface with b,w,b,w stripe shading would be broken if I squeeze anything between the first and second b,w sequence.

If I repeat b,w to b,w,b,w I get working stripes with NN but the hard edge in the middle for gradients. If I repeat b,w,b to b,w,b,b,w,b it works with linear ip but NN messes up the size of the stripes.

So it looks like I have to make sure that a color sequence starts and ends with the same color, if i want a smooth repetition. And I have to switch interpolation behaviour (call GL or manually interpolate in shader) if I want to create distinguishable stripes instead of gradients? Can somebody wrap their head around all that and tell me if i am on the right track or missing something. Feeling a bit in the dark right now.

J-S
  • 425
  • 3
  • 17
  • I'm not exactly sure what you are trying to do, but how about this: Create an array of n colors and for each fragment, figure out which colors to interpolate between. This way you can wrap from color n-1 to color 0 smoothly, and you can use any amount of colors and any range you want. Making stripes is easy aswell, simply clamp your gradient. If you insist on using a texture, consider working out the colors the same way as above, but using texelFetch instead of texture2D to avoid the interpolation of the sampler. – Henk De Boer Sep 10 '15 at 17:47
  • That is what I am doing. But its not that easy with the wrapping calculation. As I said, if you repeat a bw gradient on a surface you migth want interpolation int the middle between the two gradients as well. But for that you would need extra space. And that breaks your calculation for the wrapping. Also I am using a texture/texture2D because i implement against GLES20 and have a lot of color scales in a single image. – J-S Sep 11 '15 at 10:15
  • well image you have range [0,2] and 2 colors, and you are currently rendering a fragment at position 1,2. You can just do floor(1.2) to find color 1, then do (floor(1.2)+1)%2 for color 0. A repeating pattern will emerge in ranges [1 + k*2] for nat. num. k. – Henk De Boer Sep 11 '15 at 11:00
  • That is exactly what I described. And it has the problem of creating additional space between the repeated sequences to interpolate between the last color and the first. That means if i shade a range of [0,2] the two repeated sequences will take up less than half of the surface because of the space needed for interpolation between them. I am ok with making sequences "wrapable" by having the same start and end color. But this won't work for stripes. If i have a single b,w pattern with range [0,1] then i want a double pattern "b,w,b,w" defined by range [0,2] without the extra space. – J-S Sep 11 '15 at 15:46

0 Answers0