   Optimizations for my shader?
  Hi there!This isn't really a problem as such, but I just wondered if anyone can see any *obvious* optimizations I can make to this shader?But please don't rack your brain too hard ;) As my graphics card being old is probably the reason it is slow.(it's supposed to be a simple bloom shader. the pixel shader does horizontal blurring, with vertical in another pass with blurOffset being the only difference)Vertex:varying vec2 texCoord02D;void main(void){    gl_Position = vec4(gl_Vertex.xy, 0.0, 1.0);    texCoord02D = vec2(gl_MultiTexCoord0);}Fragment:uniform sampler2D texture0;varying vec2 texCoord02D;const float CUTOFF = 0.5;const int BLUR_SAMPLES = 4;const float BLUR_STEP = 0.003;const vec2 blurOffset = vec2(BLUR_STEP, 0.0);vec4 brightFilter(vec4 col){return max(vec4(0.0), col - CUTOFF);}void main(void){const float pixelWeight = 1.0 / (1.0 + 2.0 * float(BLUR_SAMPLES));gl_FragColor = brightFilter( texture2D(texture0, texCoord02D) );for (int i = 1; i < BLUR_SAMPLES+1; i ++){float fi = float(i);float c = 2.0/fi;gl_FragColor+= brightFilter( texture2D(texture0, texCoord02D + blurOffset*fi) *c )+ brightFilter( texture2D(texture0, texCoord02D - blurOffset*fi) *c );}gl_FragColor *= pixelWeight;vec4 inc = 1.0 + gl_FragColor;gl_FragColor *= inc*inc*inc;}Cheers :)   
  Remove the "vec4 brightFilter(vec4 col)" function, and just write the code out in the places you use it.Function calls are expensive in fragment shaders.   ;  Hmm... I figure the compiler should inline that function call (hopefully).I'd try using hardware interpolation and 2 texture fetches rather than 4 texture fetches and interpolating in software. If you sample between two texels, the hardware will interpolate them for free, and will have one less texture fetch (which is expensive).   ;  gl_FragColor *= pixelWeight;This assumes you have read access to gl_FragColorusually you pass gl_FragColor.a = pixelWeight and enable blending with glBlendFunc(GL_ONE,GL_ONE); to sum up the color valuesin you loop you use += you should do the summation with a temporary variableSome drivers produce issues with the += *= -= ... operators on gl_FragColor & gl_FragDatasuch as compling it as a pure assignment or they throw linker errors ....   ;Quote:Original post by samothI'd try using hardware interpolation and 2 texture fetches rather than 4 texture fetches and interpolating in software. If you sample between two texels, the hardware will interpolate them for free, and will have one less texture fetch (which is expensive).Sorry, could you explain this some more? How would I do this in my shader?(I'm new to OpenGL and shaders)   ;  If you sample one texel, you get just that, one texel. You can sample two of them and perform a weighted average, as you did. However, this involves getting two samples and doing some math.If you sample in between two texels (by using a texture coordinate that is off by a small amount), the texture hardware will fetch both of them and performa an average (make sure texture filtering is turned on).If you sample exactly in the middle between two texels, you will get a value (color) that is exactly the average of the values (colors) of the two texels.If your texture coordinate is not exactly in the middle, it will be a weighted average (having greater weight on the texel which is closer).Since your blur pixels should not all have the same "strength", you might try sampling for example at position 1.25 to catch both the texels at position 1 and 2, and having a greater weight on the first (similarly, sample at 3.25 to sample between 3 and 4, and since these samples are "far out", multiply the result with a scale factor to account for their lower total strength).You may need to play a bit with the weights/scale factors to get the best result, but you got the idea. Like this, you do 2 samples to the left, and 2 to the right, and you catch 8 texels with only 4 fetches (and fewer math).   ;  Ah, I see. Thanks :)   