Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Spot light issue

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2018

    Spot light issue

    Now i am working in spotlight lighting. Spotlight does not light my object correctly. I have placed my light at position (0.0,0.0,9.0,1.0), and my spot light cone direction(0.0,0.0,-1.0) and spot cut off angle 16.80, and spot exponent value is 0.15. I have render plane at (0,0,-5) and cube at (0,0,0). It should render as small spot light over my plane and cube, but my spot light only light up the cube. When i increase spot cut off angle to 50.00. But it is a big spot over plane. This is my shader code.

    vertex shader :

    Code glsl:
    #version 300 es
    in vec3 a_position;
    in vec3 a_normal;
    in vec2 texcoord;
    uniform mat4 u_mvp;
    uniform mat4 u_lightMVP;
    uniform mat4 u_world;
    uniform vec3 u_lightPos;
    uniform vec3 u_eyePos;
    /***************  material data **********/
    uniform vec4 mat_ambient;
    uniform vec4 mat_diffuse;
    uniform vec4 mat_emission;
    uniform vec4 mat_specular;
    out float v_diffuse;
    out vec2 frag_tex;
    out vec3 rgb;
    out vec3 linearColor;
    uniform vec4 u_lightColor;
    vec3 incidence_vector;
    vec3 reflectionVector;
    vec3 surfaceToCamera;
    /*** light uniform ***/
    struct param
        vec4 color;
            vec4 position;
        vec4 spot;
        //float const_atten;
        float quad_atten;
        //float linear_atten;
        /*float fall_off_angle;
        float fall_off_exp;*/
    layout(std140) uniform light_block
        param light_par[1];
    uniform bool texturing;
    uniform bool point_light;
    uniform bool spot_light;
    uniform bool sun_direct_light;
    vec4 light_pos = vec4(0.0,0.0,9.0,1.0);
    float attenuation;
    vec3 cone_dir = vec3(0.0,0.0,-1.0);
    float angle = 50.80002f;
    float spot_cut_off,spot_attn;
    spot_expo = 0.15f;
    void main() 
        gl_Position = u_mvp *  vec4(a_position,1.0);
        frag_tex = texcoord;
        vec4 worldPos = u_world *  vec4(a_position,1.0);
        vec3 lightDir = normalize( -;
        vec3 worldNormal = normalize(mat3(u_world) * a_normal);
    /* calculate diffuse component */
        v_diffuse = max(0.0,dot(lightDir, worldNormal));
        rgb = light_par[0] *;
    /* calculate attenuation */
        float distanceToLight = length( -;
        attenuation = 1.0 / (1.0 + (0.001111 *  distanceToLight * distanceToLight) + (0.0 *  distanceToLight) );
                  float clampedCosine1 = max(0.0,dot(-lightDir, normalize(vec3(cone_dir))));
                          if (clampedCosine1 < cos(radians(angle))) // outside of spotlight cone
                          attenuation = 0.0;
                        spot_attn = pow(clampedCosine1,spot_expo);
                        attenuation = attenuation ;
        linearColor = (attenuation * (rgb));

    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	123.jpg 
Views:	6 
Size:	5.5 KB 
ID:	2753  
    Last edited by Dark Photon; 05-08-2018 at 05:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts