2014-09-16 1 views
0

조각 쉐이더에서 임의의 색상을 생성하려고하는데 컴파일러 오류가 발생합니다. 여기Math.random() 선언되지 않은 식별자

<!--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을, 그리고 자바 스크립트에 새로운 오전 나는 깨는 이유는 무엇 확실하지 않다. Math.random을 사용할 수없는 이유는 무엇입니까?

+0

중복 : http://stackoverflow.com/questions/10803176/three-js-webgl-glsl-utilizing-random-math – asimes

답변

1

Math은 JavaScript 객체이며 셰이더는 GLSL입니다.

GLSL에서 난수를 생성하려면 @asimes의 설명을 참조하십시오.