Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebGL and HTML shader-type

I declare my GLSL ES shader program within a HTML file, using this code:

<script id="shader-fs" type="x-shader/x-fragment">..shader-code..</script>

as seen in the learning WebGL examples. Everything works fine, but I dont understand why I should use the type attribute of the script tag. I want to know where the "x-shader/x-fragment" value is specified. Who does that.. the W3C, the Khronos Group or the browser developers? Can anybody help me? Tahnk you.

like image 293
Luca Hofmann Avatar asked Nov 05 '11 12:11

Luca Hofmann


People also ask

What is a WebGL shader?

WebGL is all about creating various shaders, supplying the data to those shaders and then calling gl. drawArrays or gl. drawElements to have WebGL process the vertices by calling the current vertex shader for each vertex and then render pixels by calling the current fragment shader for each pixel.

What shader language does WebGL use?

Shaders are the programs that run on GPU. Shaders are written in OpenGL ES Shader Language (known as ES SL). ES SL has variables of its own, data types, qualifiers, built-in inputs and outputs.

Does WebGL use GLSL?

WebGL 1.0 only supports GLSL 1.0. 17. (Remember that WebGL is based on OpenGL ES 2.0, which was designed for computing devices with low power and limited processing.)


1 Answers

There is no official organization who specified that GLSL code should be put within a <script> tag of type "x-shader/x-fragment".

The only reason the GLSL code is placed within that <script> tag is because the tutorial writer decided his code would be cleaner if he placed the GLSL code within a <script> tag rather than a normal string.

However since WebGL takes in GLSL code as a string value, the author had to write a helper function called getShader(gl, id) to grab the script tag from the page and convert it into a javascript string, before passing it to WebGL.

The reason the author chose a type value of "x-shader/x-fragment" is because "x-shader/x-fragment" is not a known script type by the browser and thus would be safely ignored by the browser.

like image 53
Anton Avatar answered Sep 20 '22 17:09

Anton