There is such HTML code:

<script> var some = 1; </script> <script id="2d-vertex-shader" type="notjs"> void main() { } </script> <script id="2d-fragment-shader" type="notjs"> void main() { } </script> 

Can I access the JS some variable in a fragment or vertex shader? If so, in what way?

    1 answer 1

    in shaders, you can only get its value by passing through the webGL API through uniform .

    In general, in js code you need this

    glUniform1i(glGetUniformLocation(program, "some"), some);

    and in shaders (you can transfer to both fragment and vertex) define it as uniform

     precision highp float; uniform int some; void main() { gl_FragColor = //... } 

    And what is the program I hope to explain is not necessary?