I am trying to generate random colors in my fragment shader, but I'm running into compiler errors. Here is my code:
<!--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-->
Here is the error I am getting:
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>
I am new to HMTL, WebGL, and Javascript and I'm not sure what is breaking and why. Why am I unable to use Math.random?