Shaders Shader Error [SOLVED]

H

Humphrey M

Guest
Hey!

I keep getting an error when I compile my game to HTML5. It says:


The purpose of the shader is so when the game is paused, it draws a blurred screenshot of the game behind the pause screen.

This is my code (this actually isn't my code I found it on the forums, I've got no idea how to code for shaders lol)
(fragment code part) shader name: shade_blur


varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform float sigma;

uniform float blurSize;

float pii = 3.14159265;
float numBlurPixelsPerSide = 8.0;
vec2 blurMultiplyVec = vec2(1.0, 0.0);


void main()
{
vec3 incrementalGaussian;
incrementalGaussian.x = 1.0 / (sqrt(2.0 * pii) * sigma);
incrementalGaussian.y = exp(-0.5 / (sigma * sigma));
incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;

vec4 avgValue = vec4(0.0, 0.0, 0.0, 0.0);
float coefficientSum = 0.0;

avgValue += texture2D(gm_BaseTexture, v_vTexcoord.xy) * incrementalGaussian.x;
coefficientSum += incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;

for (float i = 1.0; i <= numBlurPixelsPerSide; i++)
{
avgValue += texture2D(gm_BaseTexture, v_vTexcoord.xy - i * blurSize * blurMultiplyVec) * incrementalGaussian.x;
avgValue += texture2D(gm_BaseTexture, v_vTexcoord.xy + i * blurSize * blurMultiplyVec) * incrementalGaussian.x;
coefficientSum += 2.0 * incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
}

gl_FragColor = avgValue / coefficientSum;

}



Any help would be really appreciated, I've published my game but there's that annoying pop-up whenever you enter the game and the shader doesn't work properly (it works [shows background behind pause menu] but the blur does not work). I have made sure Web Gl is activated. Thanks!!
 
Obviously you should try to understand code that you are using.

What have you tried to fix it so far?

A quick internet search for that error message yields many possible solutions. Have you tried any of them?

Ok, apart from that scolding, try this:

Change this line:
float numBlurPixelsPerSide = 8.0;

To This:
const float numBlurPixelsPerSide = 8.0;

The loop needs to be compared to a constant value, so this might fix it.

I got that tip from this page : WebGL: Loop index cannot be compared with non-constant expression
 
H

Humphrey M

Guest
Obviously you should try to understand code that you are using.

What have you tried to fix it so far?

A quick internet search for that error message yields many possible solutions. Have you tried any of them?

Ok, apart from that scolding, try this:

Change this line:
float numBlurPixelsPerSide = 8.0;

To This:
const float numBlurPixelsPerSide = 8.0;

The loop needs to be compared to a constant value, so this might fix it.

I got that tip from this page : WebGL: Loop index cannot be compared with non-constant expression
Thanks a lot! It works. I made a temporary solution by commenting out the for loop, which just disabled the blur. This fixes the error though and blur now works, ty
 
Top