【发布时间】:2016-09-14 20:52:11
【问题描述】:
我正在寻找在 WEBGL 着色器中创建一些噪点的方法。着色器本身内部的顶点位移或颜色随机化的一些噪声。我想将它放在着色器中,以便不考虑我正在渲染的内容。只是为了使当前片段颜色随机化或顶点位置移动一点。
您可以在此处查看我的着色器代码: https://github.com/rantiev/webgl-learning/blob/master/stars/index.html
这是简单明了的着色器:
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec3 uColor;
void main(void) {
vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
</script>
【问题讨论】:
-
“GLSL 噪音”的快速谷歌搜索带来了很多。 These ones on stackoverflow for example。 This article from the Book of Shaders。搜索 shadertoy.com 也会弹出lots of examples
-
Here 是一个很棒的存储库,具有多种不需要纹理或其他统一输入的噪声函数。每个文件都是完全自给自足的。只需将整个文件复制粘贴到您的着色器中即可享受。
-
谢谢大家。我说的是 WEBGL,看着你提出的这些链接(我以前看过)我有更多的问题。什么是 .glsl 文件等。我想在 HTML 的着色器脚本中添加噪音。我认为没有任何 .glsl 文件 c++ 示例和其他疯狂的东西是可能的。我可能错了 - WEBGL 新手。
-
谢谢,现在我知道我可以使用 .glsl 了,以为它与 WEBGL 无关。