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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:12:36+00:00 2026-06-07T23:12:36+00:00

How can I get this shader to have a smooth edge on the spot

  • 0

How can I get this shader to have a smooth edge on the spot light instead of a hard one? In addition, the shader has to cope with a variable value of GL_SPOT_CUTOFF. Note that not all the lights are spot lights — GL_LIGHT0 is a point light.

varying vec3 N;
varying vec3 v;
#define MAX_LIGHTS 2 
void main (void)  
{  
    vec4 finalColour;
    float spotEffect;

    for (int i=0; i<MAX_LIGHTS; i++)
    {
        vec3 L = normalize(gl_LightSource[i].position.xyz - v);   
        vec3 E = normalize(-v);
        vec3 R = normalize(-reflect(L,N));

        spotEffect = dot(normalize(gl_LightSource[i].spotDirection), 
                         normalize(-L));
        if (spotEffect > gl_LightSource[i].spotCosCutoff) {
            vec4 Iamb = gl_FrontLightProduct[i].ambient;    
            vec4 Idiff = gl_FrontLightProduct[i].diffuse * max(dot(N,L), 0.0);
            Idiff = clamp(Idiff, 0.0, 1.0);     
            vec4 Ispec = gl_FrontLightProduct[i].specular 
                         * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
            Ispec = clamp(Ispec, 0.0, 1.0);
            finalColour += Iamb + Idiff + Ispec;
        }
    }
    gl_FragColor = gl_FrontLightModelProduct.sceneColor + finalColour;

}

The scene looks like this:

enter image description here

  • 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-07T23:12:39+00:00Added an answer on June 7, 2026 at 11:12 pm

    This shader from http://www.ozone3d.net/tutorials/glsl_lighting_phong_p3.php produces the soft edges to the spotlight you are after.

    [Pixel_Shader]
    
    varying vec3 normal, lightDir, eyeVec;
    
    const float cos_outer_cone_angle = 0.8; // 36 degrees
    
    void main (void)
    {
        vec4 final_color =
        (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) +
        (gl_LightSource[0].ambient * gl_FrontMaterial.ambient);
    
        vec3 L = normalize(lightDir);
        vec3 D = normalize(gl_LightSource[0].spotDirection);
    
        float cos_cur_angle = dot(-L, D);
    
        float cos_inner_cone_angle = gl_LightSource[0].spotCosCutoff;
    
        float cos_inner_minus_outer_angle = 
              cos_inner_cone_angle - cos_outer_cone_angle;
    
        //****************************************************
        // Don't need dynamic branching at all, precompute 
        // falloff(i will call it spot)
        float spot = 0.0;
        spot = clamp((cos_cur_angle - cos_outer_cone_angle) / 
               cos_inner_minus_outer_angle, 0.0, 1.0);
        //****************************************************
    
        vec3 N = normalize(normal);
    
        float lambertTerm = max( dot(N,L), 0.0);
        if(lambertTerm > 0.0)
        {
            final_color += gl_LightSource[0].diffuse *
                gl_FrontMaterial.diffuse *
                lambertTerm * spot;
    
            vec3 E = normalize(eyeVec);
            vec3 R = reflect(-L, N);
    
            float specular = pow( max(dot(R, E), 0.0),
                gl_FrontMaterial.shininess );
    
            final_color += gl_LightSource[0].specular *
                gl_FrontMaterial.specular *
                specular * spot;
        }
        gl_FragColor = final_color;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any way I can get this working? I have a block of code: <p><a
I screwed up my last post. Lets see if I can get this one
I can get this to work: [<DllImport(user32.dll)>] extern bool GetClientRect(nativeint, RECT*) let getClientRect hwnd
im new at javascript and i can get this slider to work but not
Is there a way I can get this array walk with my anonymous function
How can I get this in Yii framework using Chtml::link <a href=# title=Movie 1
I can't get this putty to handle alt + left/right properly. (Edit: By properly,
I can't get this code to work. Declared playpauseButton just above the given below
How can I get this to compile? The error is when I start using
I can't get this working for the life of me. Here is a snippet

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.