How to optimize a color gradient shader?

ε祈祈猫儿з 提交于 2020-01-05 14:03:11

问题


I have created this simple fragment shader for achieving a vertical color gradient effect. But I find this to be taxing for my mobile device in full screen.

is there any way to optimize this?

here is the link to the code

http://glsl.heroku.com/e#13541.0


回答1:


You could do something like this instead.

vec2 position = (gl_FragCoord.xy / resolution.xy);

vec4 top = vec4(1.0, 0.0, 1.0, 1.0);
vec4 bottom = vec4(1.0, 1.0, 0.0, 1.0);

gl_FragColor = vec4(mix(bottom, top, position.y));

Example

You can further change the color yourself, I just used random colors.


You can even further eliminate calculating the x but that's kinda overkill.

vec4 top = vec4(1.0, 0.0, 1.0, 1.0);
vec4 bottom = vec4(1.0, 1.0, 0.0, 1.0);

gl_FragColor = vec4(mix(bottom, top, (gl_FragCoord.y / resolution.y)));


来源:https://stackoverflow.com/questions/21083462/how-to-optimize-a-color-gradient-shader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!