Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:29:55+00:00 2026-06-14T20:29:55+00:00

Using the GLSL shader source code provided by Kenny Mitchell in GPU Gems 3

  • 0

Using the GLSL shader source code provided by Kenny Mitchell in GPU Gems 3, I’ve attempted to create some 2D god rays using SFML 2.0. Currently, whenever I compile and debug the project, the mask texture and sprite (“image.png” and “sprite”, respectively) disappear completely. The project I have currently set up is very crude, consisting of only one main.cpp file and the shader files, though I have a feeling that I would require more than I have currently. Any help would be much appreciated! Source code will be provided below.

main.cpp:

#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <iostream>

void main()
{
    sf::RenderWindow _window(sf::VideoMode(800, 480, 32), "Lighting Test");
    _window.setFramerateLimit(60);

    sf::Shader lightingShader;
    sf::RenderStates renderState;

    sf::Texture texture;
    texture.loadFromFile("image.png");

    sf::Sprite sprite;
    sprite.setTexture(texture);

    sf::Texture backgroundTexture;
    backgroundTexture.loadFromFile("light.png");

    sf::Sprite background;
    background.setTexture(backgroundTexture);

    while (_window.isOpen())
    {
        int x = sf::Mouse::getPosition(_window).x;
        int y = sf::Mouse::getPosition(_window).y;

        lightingShader.loadFromFile("lightingShader.vert", "lightingShader.frag");
        lightingShader.setParameter("exposure", 0.25f);
        lightingShader.setParameter("decay", 0.97f);
        lightingShader.setParameter("density", 0.97f);
        lightingShader.setParameter("weight", 0.5f);
        lightingShader.setParameter("lightPositionOnScreen", sf::Vector2f(0.5f, 0.5f));
        lightingShader.setParameter("myTexture", sf::Shader::CurrentTexture);
        renderState.shader = &lightingShader;

        _window.clear(sf::Color::Black);
        sprite.setPosition(x, y);
        //sprite.setColor(sf::Color::Black);
        //background.setPosition(400, 240);
        _window.draw(background);
        _window.draw(sprite, renderState);
        _window.display();
    }
}

lightingShader.vert:

void main() 
{

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
}

lightingShader.frag:

uniform float exposure;
uniform float decay;
uniform float density;
uniform float weight;
uniform vec2 lightPositionOnScreen;
uniform sampler2D myTexture;
const int NUM_SAMPLES = 100 ;
void main()
{   
    vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
    vec2 textCoord = gl_TexCoord[0].st;
    deltaTextCoord *= 1.0 /  float(NUM_SAMPLES) * density;
    float illuminationDecay = 1.0;


    for(int i=0; i < NUM_SAMPLES ; i++)
    {
            textCoord -= deltaTextCoord;
            vec4 sample = texture2D(myTexture, textCoord);

            sample *= illuminationDecay * weight;

            gl_FragColor += sample;

            illuminationDecay *= decay;
    }


    gl_FragColor *= exposure;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:29:56+00:00Added an answer on June 14, 2026 at 8:29 pm

    I’ve finally solved the problem on my own. Turns out the vertex shader I created was unnecessary, and all I had to do was replace:

    lightingShader.loadFromFile("lightingShader.vert", "lightingShader.frag");

    With:

    lightingShader.loadFromFile("lightingShader.frag", sf::Shader::Type::Fragment);.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using this code to check if my glsl shader compiled fine. glGetObjectParameterivARB(obj,
I declare my GLSL ES shader program within a HTML file, using this code:
I've seen this done long ago with hlsl/glsl shader code -- using an #include
I have successfully implemented a cel shader using glsl. But my problem is about
What is a good way to load a GLSL shader using C/C++ without using
I am using openGL ES 2.0 and GLSL shader and working on FBO with
When using GLSL vertex shaders, a way to let the shader work as a
I'm using GLSL. I have a simple fragment shader here: uniform sampler2D backBuffer;, uniform
I've dabbled with basic shader programming before, using the GLSL way. Now I've come
So on my program, I draw 2D rectangle using GLSL shader. The rectangle is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.