我试图在我的片段着色器中生成随机颜色,但我遇到了编译器错误。下面是我的代码:
<!--here is where the color is set-->
<script id="fragment-shader" type="x-shader/x-fragment">
precision mediump float;
void
main()
{
float red = Math.random();
float green = 0.5;
float blue = 0.7;
gl_FragColor = vec4( red, green, blue, 1.0 );
}
</script><!--here is where the color is set-->下面是我得到的错误:
Fragment shader failed to compile. The error log is:<pre>ERROR: 0:8: 'Math' : undeclared identifier
ERROR: 0:8: '' : methods are not supported
ERROR: 0:8: 'random' : no matching overloaded function found
</pre>我对HMTL、WebGL和Javascript都是新手,我不知道是什么破坏了它,也不知道为什么。为什么我无法使用Math.random?
发布于 2014-09-16 22:24:26
Math是一个JavaScript对象,着色器是用GLSL编写的。
要在GLSL中生成随机数,请参阅@asimes的评论。
https://stackoverflow.com/questions/25862006
复制相似问题