How to use a timer inside a vertex shader to animate point sizes in OpenGL

前端 未结 2 1020
[愿得一人]
[愿得一人] 2021-01-07 02:11

I\'m trying to implement a point cloud where the different points shall vary in size based on an uncertainty value associated with them. Let\'s say, if this value is zero, t

2条回答
  •  执笔经年
    2021-01-07 02:55

    You can pass a texture1D with the values for each point.Then use texelFetch() to retrieve the values.You can use an atomic counter (if using OpenGL 4.2) , or gl_vertexID to do this.Also take a look at this question and this one, the accepted answer also suggest additional solutions like UBOs. Though if your point cloud is pretty big then Buffer Textures is what you need.

    Let's take the Buffer textures approach:

    • You create a texture buffer and fill it with values that going to define your points target size.(Read in the links I put above how to set it up.
    • In the vertex shader you access those values via texelFetch sampling .As I said,you can use gl_VertexID to sample by current vertex,(something like this):

      uniform samplerBuffer pointsBuffer;

      void main() { float destSize = texelFetch(pointsBuffer, gl_VertexID).x; ... }

    • Now, you probably want to interpolate the point size from the default to the target size based on some amount.Yes timer input which ranges between 0 and 1 can do the job.Use mix() built-in method to interpolate the point size from the default the destination.For more fun pass sin() or cos() based time :)

    • As you have mentioned OpenGL superbible , it has a chapter that explains how texture buffers work.Read it again.What you are trying to do is not a rocket science but not a beginner level either.So be patient -which is always good tip when working with OpenGL.

提交回复
热议问题