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 4618298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:14:49+00:00 2026-05-22T02:14:49+00:00

Good day my dear community. I’m working on dynamic shadows for a game I

  • 0

Good day my dear community.

I’m working on dynamic shadows for a game I shall work on, but as it usually happens I bring you a problem, in hope (I’m certain actually) that someone will help.

This is where I am right now:enter image description here

Notice the red square, I want it to gradually fade away as the light source moves out of the sight. I do check if a point of a polygon is inside circle’s radius, but that of course doesn’t solve it; as I said I want it to fade gradually until it completely blacks out If the light is too far away.

There’s one idea on my mind but I hope for a better one. I will not talk about it since it’s really the last option and I find it to be a ‘brute force’ technique.

This is how I render my light:

    glBegin(GL_TRIANGLE_FAN);
    {
        Graphics::Instance()->SetColor(r_,g_,b_,intensity_);
        glVertex2f(posX_,posY_);

        glColor4f(0.f, 0.f, 0.f, 0.0f);

        for (angle_=0.0; angle_<=3.14159265*2; angle_+=((3.14159265*2)/64.0f) )
        {
            glVertex2f(range_*(float)cos(angle_) + posX_,
                       range_*(float)sin(angle_) + posY_);
        }

        glVertex2f(posX_+range_, posY_);
    }

And this is how I blend it:

glBlendFunc(GL_SRC_ALPHA, GL_ONE);
l0->Render();

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
l0->ProjectShadow(*mmm);
l0->ProjectShadow(*bb);

That is all. If I didn’t made myself clear or If I missed to post relevant code, please do say so and don’t downvote.

  • 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-05-22T02:14:50+00:00Added an answer on May 22, 2026 at 2:14 am

    How about calculating the range to the center of your red square from the light sources center? Normalise that value to a suitable range and adjust the transparency or colour of the red square? Something like this:

    double Range(double x1, double y1, double x2, double y2)
    {
        double xDist = x1-x2;
        double yDist = y1-y2;
        return math::sqrt(xDist*xDist+yDist*yDist);
    }
    
    double CalcIntensity(double lightX, double lightY, double lightRadius, double objectX, double objectY)
    {
        double range = Range(lightX, lightY, objectX, objectY);
        double intensity;
        if( range > lightRadius )
        {
            intensity = 0.0;
        }
        else
        {
            intensity = range/lightRadius;
        }
        return intensity;
    }
    

    Then just call CalcIntensity and feed in the reletive positions of the light and the square and the radius of the light.

    [Edit] …or this would be a slightly more optomised version if you’re not pre-checking it’s within the lights radius:

    double CalcIntensity(double lightX, double lightY, double lightRadius, double objectX, double objectY)
    {
        double intensity = 0.0;
        double xDist = lightX-objectX;
        if( xDist < lightRadius )
        {
            yDist = lightY-objectY;
            if( yDist < lightRadius )
            {
                double range = math::sqrt(xDist*xDist+yDist*yDist);
                intensity = range/lightRadius;
            }
        }
    
        return intensity;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have this problem with Html.DropDownListFor which I can't seem to work
Good day, I've been working on this project and learning how to place a
Good day lovely computer peoples! I've uploaded a .dmg file to my server, but
Good day good-looking computer people, I might be asking a bit too much, but
Good day, I am working on a Stratix III FPGA which contains M9K block
Good day dear colleagues, I decided to move some projects from MySQL to MongoDB
A good day dear developers. My name is Danny. This is my first post
Good day! How is the confirmation for deletion usually done in Web-based applications? I
Good day! I tried using JSTL in java but there's an error: exception javax.servlet.ServletException:
Good day everyone. I am creating a calendar component, and I'm working in the

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.