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

前端 未结 2 1023
[愿得一人]
[愿得一人] 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 03:05

    First of all...thanks for your answer. I've worked things out using just a vertex shader. I guess this was the solution I was hoping to get. Maybe folks with the same problem can benefit from this:

    Part of my vertex shader looks like this:

     ... 
     "  float standardPointSize = 100.0;"
     "  float timeScale = standardPointSize / my_loopDuration;"
     "  float currentTime = mod(my_time, my_loopDuration);"
     "  float offset = currentTime * timeScale * in_uncertainty;"
     "  if(currentTime < my_loopDuration / 4)"
     "  {"
     "      gl_PointSize = standardPointSize - 4 * offset;"
     "  }"
     "  else if(currentTime >= my_loopDuration / 4 && currentTime < my_loopDuration / 2)"
     "  {"
     "      gl_PointSize = standardPointSize - standardPointSize * in_uncertainty + 4 * offset - 1 * in_uncertainty * standardPointSize;"
     "  }"
     "  else if(currentTime >= my_loopDuration / 2 && currentTime < 3 * my_loopDuration / 4)"
     "  {"
     "      gl_PointSize = standardPointSize + 4 * offset - 2 * in_uncertainty * standardPointSize;"
     "  }"
     "  else if(currentTime >= 3 * my_loopDuration / 4 && currentTime <= my_loopDuration)"
     "  {"
     "      gl_PointSize = standardPointSize + standardPointSize * in_uncertainty - 4 * offset + 3 * in_uncertainty * standardPointSize;"
     "  }"
     ...
    

    my_time and my_loopDuration are uniform variables. The first one is set with glutGet(GLUT_ELASED_TIME) and the second one is an arbitrary number.

提交回复
热议问题