   GLSL and looping
  Hey everyone. I'm writing a shader for parallax occlusion mapping and am having an issue with a while loop. I'm raycasting trying to find the proper offset into the heightmap, and want to do it in a while loop to make it easier to read through and have a dynamic number of samples. However, whenever I run it, my computer just seizes up for a few minutes while I try to kill my program.  If I manually unroll the loop for a fixed sample rate, everything works as expected. The only thing I do inside the while loop is increment some vec2s, and use texture2D() to get my new values in the height/normal map. Can you not sample a texture inside a while loop or something? I don't know why else it would do this...   
  I'll suggest that you post your shader.   ;  Okay, here's the pixel shader, currently hard coded to take 8 samples:varying vec3  pos;varying vec3  tanInv, biInv, nInv, eyeTan;uniform sampler2D tex1, normalMap;void main(){  float height   = 1.0;  vec2 parOffset = normalize(eyeTan.xy) * (length(eyeTan.xy)/-eyeTan.z) * 0.05;  float step= (1.0 / 8.0);   vec2 delta = parOffset * step;  vec2 coord = gl_TexCoord[0].st;  vec4 curPt = texture2D(normalMap, gl_TexCoord[0].st);  while (curPt.a < height)  {    height -= step;    coord += delta;    curPt = texture2D(normalMap, coord);  }  vec4 n = normalize(texture2D(normalMap, coord) * 2.0 - 1.0);   vec3 norm;  norm.x = dot(n1.xyz, tanInv);  norm.y = dot(n1.xyz, biInv);  norm.z = dot(n1.xyz, nInv);  vec4 p;  p.xyz = pos;  p.w = gl_FrontMaterial.shininess;  gl_FragData[0] = (gl_FrontMaterial.diffuse);  gl_FragData[1] = texture2D(tex1, coord);  gl_FragData[2] = vec4(normalize(norm), pos.z / -1000.0);  gl_FragData[3] = p;}I know it's to do with the loop, because if I just change it to a bunch of ifs, it will work.;  Should be perfectly fine to do it in a loop.Sounds like you get stuck in the loop. Are you sure you break out of it correctly?   ;  I thought that too at first, Shintah, but even when I hard coded the sample size it doesn't work. The height will go negative after 8 iterations, and the sampled value will never be negative.   ;Quote:Original post by WellAdjustedManHowever, whenever I run it, my computer just seizes up for a few minutes while I try to kill my program.  If I manually unroll the loop for a fixed sample rate, everything works as expected. Check if your shader fallback to software mode. What hardware/driver are you using ? Try out a fix for-loop instead of your while-loop:for(i=0;i<8;i++){...}