• I need fast help with a glsl glow shader
    1 replies, posted
Hi, sorry if I sound rude but I need to do this very fast. I basically know nothing about the subject. I need someone to help me write or possibly (thanks in advance for that) try to write a glsl shader for me. I need to use it in a SFML app that needs to be done in a few hours so time is running short. This is the code of a sample shader taken from the sfml tutorial about postFX. [cpp]texture framebuffer vec3 color effect { // Get the value of the current screen pixel vec4 pixel = framebuffer(_in); // Compute its gray level float gray = pixel.r * 2. + pixel.g * 0.50 + pixel.b * 0.11; // Finally write the output pixel using 50% of the source pixel and 50% of its colored version _out = vec4(gray * color, 1.0) * 0.5 + pixel * 0.5; } [/cpp] Could you please write the code for me if possible? It needs to compute a short glow (5 px) vertical and horizontal Thanks in advance
[cpp]// The original texture uniform sampler2D referenceTex; // The width and height of each pixel in texture coordinates uniform float pixelWidth; uniform float pixelHeight; void main() { // Current texture coordinate vec2 texel = vec2(gl_TexCoord[0]); vec4 pixel = vec4(texture2D(referenceTex, texel)); // Larger constant = bigger glow float glow = 4.0 * ((pixelWidth + pixelHeight) / 2.0); // The vector to contain the new, "bloomed" colour values vec4 bloom = vec4(0); // Loop over all the pixels on the texture in the area given by the constant in glow int count = 0; for(float x = texel.x - glow; x < texel.x + glow; x += pixelWidth) { for(float y = texel.y - glow; y < texel.y + glow; y += pixelHeight) { // Add that pixel's value to the bloom vector bloom += (texture2D(referenceTex, vec2(x, y)) - 0.4) * 30.0; // Add 1 to the number of pixels sampled count++; } } // Divide by the number of pixels sampled to average out the value // The constant being multiplied with count here will dim the bloom effect a bit, with higher values // Clamp the value between a 0.0 to 1.0 range bloom = clamp(bloom / (count * 30), 0.0, 1.0); // Set the current fragment to the original texture pixel, with our bloom value added on gl_FragColor = pixel + bloom; }[/cpp] Had this lying around on one of my old projects. Not terribly efficient and you'll need to tweak it but... it works.
Sorry, you need to Log In to post a reply to this thread.