Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Interpolating color over multiple nodes  (Read 2030 times)

0 Members and 1 Guest are viewing this topic.

brfsmn

  • Newbie
  • *
  • Posts: 2
    • View Profile
Interpolating color over multiple nodes
« on: May 16, 2020, 04:05:28 pm »
I have a mesh or a drawing with multiple connected triangles and every node or vertex of these triangles in the mesh has a certain value (stress, strain etc.) and I want to draw a heat map for these values over my mesh.

In SFML tutorial, it was demonstrated that you could assign a color to every vertex in triangle native type, then color of triangle would be interpolated over color of the 3 nodes.

Is there's a way to get color interpolation to use specified 'neighboring nodes' and not just nodes in its own set of shape?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Interpolating color over multiple nodes
« Reply #1 on: May 17, 2020, 06:50:25 pm »
For anything beyond the simple color gradient between vertices, you may want to pick a shader, that will allow you to do a lot more.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Interpolating color over multiple nodes
« Reply #2 on: May 17, 2020, 06:54:37 pm »
You could manually interpolate the colours between the ones you wish to interpolate for each of the vertices between those two. Looks like it might be a simple task. Depends on what you mean specifically and if I've fully understood what you meant.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

brfsmn

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Interpolating color over multiple nodes
« Reply #3 on: May 17, 2020, 10:03:32 pm »
You could manually interpolate the colours between the ones you wish to interpolate for each of the vertices between those two. Looks like it might be a simple task. Depends on what you mean specifically and if I've fully understood what you meant.


This is an example of what I am trying to accomplish.

https://i.imgur.com/KUfK76H.png

The difference here is that he is using rectangular elements and I am using triangles but that's irrelevant.
On second thought, I think color interpolation for every triangle on its own might do job but if it didn't and I want to implement it myself, I would have to use shaders as eXpl0it3r suggested?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Interpolating color over multiple nodes
« Reply #4 on: May 17, 2020, 11:02:44 pm »
There is more detail required than just those rectangles. Each rectangle has more than just a simple interpolation of colours.

It's likely a good idea to subdivide that grid many times and the quads used would be a lot smaller. The grid would just be overlaid if required.

Another option would be to use texture(s) for each quad. The texture can be created "live" by using a render texture. For example, drawing the shapes onto the render texture and then using that texture for the quads.

That said, if you want the graphics card to do the processing for you, you can use a shader, but the shader will need to have all of the information with which to make the map.

And yes, of course, triangles are no different. In fact, quads (when distorted like in the image) don't interpolate colours as reliably as triangles. ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything