Is it possible to read from a texture in a vertex shader with WebGL?
I wrote a WebGL page (just to try it out) and used Chrome 7 to test it. As soon as I upgraded to Chrome 8, it stopped working. I double checked that webgl is enabled. The error is:
'texture2D': no matching overloaded function found
When I replace the call to texture2D with a constant, it works. Texture access in a fragment shader using the same texture also works.
Anyone have any ideas? I'm particularly thrown by the fact that upgrading Chrome caused it to break.
Update: It works in firefox 4 beta. I reported a bug with Chrome - issue 65340
Update 2: It now works in Firefox and Chrome
The most common way to read matrix in the vertex shader is by using textures. Although textures are most commonly used to store color information (albedo, roughness map, specular map, tint map, etc.) textures can also be used to store any kind of information (e.g. normal map).
WebGL runs on the GPU on your computer. As such you need to provide the code that runs on that GPU. You provide that code in the form of pairs of functions. Those 2 functions are called a vertex shader and a fragment shader and they are each written in a very strictly typed C/C++ like language called GLSL.
Vertex Shaders don't actually change the type of data; they simply change the values of the data, so that a vertex emerges with a different color, different textures, or a different position in space.
In WebGL, texture coordinates are usually input to the vertex shader as an attribute of type vec2. They are communicated to the fragment shader in a varying variable. Often, the vertex shader will simply copy the value of the attribute into the varying variable.
Its not really a 'bug' in Chrome.
Vertex texture access is not a required feature of Open GL ES 2, which is the basis of the WebGL specification. I suspect what might be happening is that although your underlying GL driver supports vertex texture access, now you've switched to Chrome its using Angle, and Angle doesn't report that vertex texture access as available.
You can compare your FF and Chrome versions by using Thatcher Ulrich's
http://webgl-bench.appspot.com/
This has the MAX_VERTEX_TEXTURE_IMAGE_UNITS parameter (near the end) Chrome/Angle always reports 0.t
Another thing to check is that you are using the correct texture2D syntax - the spec changed and it may be that FF is stil supporting the older syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With