   Need some help on this simple shader.
  Hi guys,I'm running into an opengl Invalid Operation error on my shader, and I'm very stuck. Any help at all would be greatly appreciated.The shader does three things:1) It retrieves the height of the vertex from a 2d texture2) It then retrieves the "index" from a 3d texture3) Using this "index" it retrieves the corresponding color in a 1d texture.I get the feeling that I'm doing to many texture reads. If I comment either step 2, or step 3, then everything works fine. Is there any way to work around this?Thanks a lot for your help  -Patrick<VERTEX SHADER>uniform sampler2D height;varying vec4 vertex;void main(){  vertex = gl_Vertex;  vertex.z = texture2D(height, vertex.xy).r; //read height from texture  gl_Position = gl_ModelViewProjectionMatrix * vertex;}<FRAGMENT SHADER>uniform sampler3D tex;uniform sampler1D palette;varying vec4 vertex;void main(){  float index = texture3D(tex, vertex.xyz).r; //read index from texture  gl_FragColor = texture1D(palette, index); //read color from palette}
  Okay I've narrowed down the problem to occur only when:Using 3 or more dependant texture reads.AND using a large display list ( > 50 vertexes )The shader has no problem if I'm not using a display list.And the display list has no problem if I don't try to do 3 dependant texture reads...This sounds like a opengl or graphics card bug. I'm going to try using vertex arrays to work around this.   ;I am new to GLSL and shader programming. I have few basic doubts.vertex.z = texture2D(height, vertex.xy).r; //read height from textureHere How can you lookup a texture, if the vertex values crosses the texture coordinates range [0 1]. I understand that  texture coordinates values should be between [0,1]. float index = texture3D(tex, vertex.xyz).r; //read index from textureTexture lookup returns color values and Why are you  using color values as indices?Please teach me, I am new to shader. ;  Hi Rajesh,I would be glad to answer your questions."Here How can you lookup a texture, if the vertex values crosses the texture coordinates range [0 1]. I understand that texture coordinates values should be between [0,1]. "For this shader, I specifically draw vertices only between 0 and 1. The goal of that line of code is to read the height of the vertex directly off of a texture, instead of in a glVertex3f call. It's a simple technique called Vertex Displacement Mapping,  which I need for the things I'm doing."float index = texture3D(tex, vertex.xyz).r; //read index from textureTexture lookup returns color values and Why are you using color values as indices?"This part is to emulate an indexed-color mode. My data is specified as a 3D texture of indices, with different indices corresponding to different colors, which is stored in another 1D texture. Now, by altering the 1D texture, I can animate the colors of the entire dataset.-Patrick   ;  I don't think that your number of independent texture reads is the problem. The glsl compiler are quite good, so commenting out code fragments will most likely result in unused code which will be ignored by the glsl compiler.A problem might be your texture access in the vertex shader. This is possible, but only on the right hardware (hmm... my guess would be >=G80, 8xxx nvidia series, but I'm not sure).--Ashaman;  I agree that texture lookup in a vertex shader is quite hasardous.You may have a look at geometry shader for displacement algorithm with GPU   ;  Try and narrow it down. What do you see with simple ps (color = 1.0) and wireframe? What do you see when you sample the texture in the pixel shader? Debug runtimes,logging, etc? Can you post info from gpu-z? Is there some other application/sdk you knows uses VTF (vertex texture fetch) that does work?   ;  I am so stuck. =(I know vertex texture mapping works on my chipset (9400m) because everything works fine so long as I don't use a display list.I've played around with the fragment shader some more. And I am more confused than ever.<Fragment Shader>uniform sampler3D tex;uniform sampler1D palette;varying vec4 vertex;void main(){   vec4 read1 = texture3D(tex, vertex.xyz);   //This line does nothing  vec4 read2 = texture1D(palette, vertex.x);  //and neither does this line.  gl_FragColor = gl_Color;}There are two independent texture read commands that don't do anything. But if I comment out either of them, then everything works fine. -Patrick   ;  After many hours of painful experimentation, I have finally given up on Display Lists. I switched over to using Vertex Buffer Objects and everything works like a charm.   