How to create multiple stop gradient fragment shader?

前端 未结 1 375
鱼传尺愫
鱼传尺愫 2021-02-08 06:07

I\'m trying to create an OpenGL ES 2.0 fragment shader that outputs multiple stop gradient along one axis. It should interpolate between multiple colors at points defined in per

1条回答
  •  盖世英雄少女心
    2021-02-08 06:52

    If you want to eliminate branches you can do following (taken from Heroku);

    color = mix(white, red, smoothstep(step1, step2, y));
    color = mix(color, blue, smoothstep(step2, step3, y));
    color = mix(color, green, smoothstep(step3, resolution.y, y));
    

    But I'm not sure at all whether this is any faster than if/elses or not.

    0 讨论(0)
提交回复
热议问题