• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders i cant get the shader to work ;c

FoufaDjo

Member
i fond a very good shader from a web site but when i put in my object the object become invisible xd can some one show me were is the problem or if u have better glow shader for sprites let me know ^^ :

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform float sigma; // The sigma value for the gaussian function: higher value means more blur
// A good value for 9x9 is around 3 to 5
// A good value for 7x7 is around 2.5 to 4
// A good value for 5x5 is around 2 to 3.5
// ... play around with this based on what you need :)

uniform float blurSize; // This should usually be equal to
// 1.0f / texture_pixel_width for a horizontal blur, and
// 1.0f / texture_pixel_height for a vertical blur.

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

void main() {
// Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
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;

// Take the central sample first...
avgValue += texture2D(gm_BaseTexture, v_vTexcoord.xy) * incrementalGaussian.x;
coefficientSum += incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;

// Go through the remaining 8 vertical samples (4 on each side of the center)
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;

}
 
You'll need to make sure that blurMultiplyVec is equal to the texel size of the current image being drawn.

You'll need to get the texture using sprite_get_texture(sprite,sub) (or surface_get_texture(surf) if drawing a surface).

Then to get the texl width and height, use texel_get_width(tex), and texel_get_height(tex). texel width and height are also equal to 1/(width of texture) and 1/(height of texture).

You'll need to also check that you are setting your other uniforms correctly.
 

FoufaDjo

Member
idk too mush about shader but i did this and i got a black box aound my sprite ;c

global.gles_Gaussian_sigma = shader_get_uniform(sglow2,"sigma");
global.gles_Gaussian_size = shader_get_uniform(sglow2,"blurSize");
texh = texture_get_texel_height(sprite_get_texture(sprite_index,0));
texw = texture_get_texel_width(sprite_get_texture(sprite_index,0));

shader_set(sglow2);
shader_set_uniform_f(global.gles_Gaussian_sigma,texh);
shader_set_uniform_f(global.gles_Gaussian_size,texw);
draw_self();
shader_reset();
 
Top