Skip to main content
gamedev.net
🔒 Locked

Problem with glsl loop

Started by cubicwang 3 replies 3.6k views
Original Post
cubicwang
cubicwang
I write a glsl for gauss blur.My code below: uniform sampler2D postSrc; uniform vec4 gaussParam[16]; varying vec4 gl_TexCoord[1]; void main(void) { vec4 sample = vec4(0.0,0.0,0.0,0.0); sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[0].xy)) * gaussParam[8].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[0].wz)) * gaussParam[8].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[1].xy)) * gaussParam[9].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[1].wz)) * gaussParam[9].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[2].xy)) * gaussParam[10].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[2].wz)) * gaussParam[10].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[3].xy)) * gaussParam[11].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[3].wz)) * gaussParam[11].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[4].xy)) * gaussParam[12].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[4].wz)) * gaussParam[12].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[5].xy)) * gaussParam[13].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[5].wz)) * gaussParam[13].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[6].xy)) * gaussParam[14].x; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[6].wz)) * gaussParam[14].y; sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[7].xy)) * gaussParam[15].x; /* int i; for(i=0; i<7; i++) { sample += texture2D( postSrc, gl_TexCoord[0].xy + gaussParam.xy) * gaussParam[i+8].x; sample += texture2D( postSrc, gl_TexCoord[0].xy + gaussParam.wz) * gaussParam[i+8].y; } sample += texture2D( postSrc, (gl_TexCoord[0].xy + gaussParam[7].xy)) * gaussParam[15].x; */ gl_FragColor = sample; } The comment part is the same meaning of the code on top of it.But the "for loop" can only run well on nvidia card but will crash down on ATI card. The problem is the gaussParam[i+8].x and gaussParam[i+8].y will cause crash. If I remove it from the code, the shader will run on ATI card. I find that on ATI card the loop iter can not be given any comput, such as I use a float point as the bone index and use it to acce the bone array in uniform, the index is a float, I use the int(boneIdx) to convert it to a int and try to acce the array, but the result is only acce the [0] element. If I use a const such as bone[3], the result is ok, So is there any special place on ATI card for glsl? I change a lot of drivers but it seems no different. Can someone give me some help? Thank you a lot!
bassman
bassman
I have heard that only the if-statement is supported by most current video cards. Hope this helps a bit :)
cubicwang
cubicwang
Thank you!
That really a bad news for me.
So do you know the problem of the array acce?
Why I can't do array acce with the int(boneIdx) iter?
If I remove the loop, use if statement instead, can the iter work?
I will try, can any opengl developer give me some more exactly explain?
Thank you a lot!!!
relpats_eht
relpats_eht
With the code given, I don't see any problem with removing the loop and simply copying its contents seven times and writing in the values for the index variable.
relpats_eht
cubicwang
cubicwang
Yes, there realy no different to run the code on NVidia card, but if it run on ATI card, the loop will crash

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.