如何优化颜色渐变着色器? [英] How to optimize a color gradient shader?

查看:178
本文介绍了如何优化颜色渐变着色器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个简单的片段着色器,以实现垂直的颜色渐变效果. 但是我发现这对全屏移动设备来说是一个沉重的负担.

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?

这是代码的链接

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

推荐答案

您可以改为执行类似的操作.

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));

示例

您可以自己进一步更改颜色,我只是使用了随机颜色.

您甚至可以进一步消除计算x的可能性,但这有点过头了.

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)));

这篇关于如何优化颜色渐变着色器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆