0
\$\begingroup\$

I have a "low poly" surface, where the color palette for polygons is low (e.g. 20 distinct colors). Is there a way to change the color (with a smooth transition) for all polygons painted with a certain color?

Maybe an analogy would be to smoothly make all polygons of a certain color transparent..

Background:

I have managed to get a 2D variant working: load a bitmap on a canvas and use a shader to change the color.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ That depends on what graphic API are you using and how exactly you are using it. \$\endgroup\$ – Philipp Feb 19 '18 at 12:27
1
\$\begingroup\$

I'd be tempted to do this like so:

  1. With each vertex, store a single numeric texture coordinate which will serve as your index into your colour palette (ie. "this vertex should be painted in colour 0, that one should be painted in colour 17")

  2. In your vertex shader, use this index to look up the colour from either a palette texture (where each pixel is 1 palette entry) or an array of colour uniforms. Pass this colour to the fragment shader to draw to the screen.

  3. To gradually change the colour in one or more palette entries, you can...

    • with a palette texture: write multiple rows into your palette, where row 1 is the first version of the palette, row 2 is the second version, etc...

      Use a uniform to select which palette to read from. Use Material.SetFloat() to gradually vary that uniform between two adjacent rows, using texture filtering to blend between any colour palette entries that are different on the two rows.

    • with an array of colour uniforms: use Material.SetColorArray() to update your array each frame as you vary the colours.

\$\endgroup\$
1
  • \$\begingroup\$ This looks quite feasible. The second option with the array of color uniforms sounds more appealing to me. I'll try it in the next couple of days. \$\endgroup\$ – Laur Ivan Feb 19 '18 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.