Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Android OpenGL es 2.0 specular light

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2

    Android OpenGL es 2.0 specular light

    I'm trying to add specular lightning to my android OpenGL project, but the light is only projected on a part of my object, as you can see in my example:
    (cant insert image.. )

    In my fragment shader, I calculate the color as following:

    Code :
    float dot(vec3 v1, vec3 v2)
    {
        return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
    }
     
    void main()
    {
        float distSqr = dot(lightDir, lightDir);
        float att = clamp(1.0 - 0.001 * sqrt(distSqr), 0.0, 1.0);
        vec3 L = lightDir * inversesqrt(distSqr);
     
        vec4 baseColor = texture2D(texture1, tCoord);
     
        vec3 N = normalize(baseColor.xyz * 2.0 - 1.0);
     
        vec3 E = normalize(eyeVec);
     
        vec3 reflectV = reflect(-L, N);
     
        vec4 ambientTerm = baseColor;
     
        // base * diffuse * max(dot(N, L), 0.0)
        vec4 diffuseTerm = baseColor * matDiffuse * max(dot(N, L), 0.0);
        //vec4 diffuseTerm = baseColor * gl_FrontMaterial.diffuse * max(dot(N, L), 0.0);
     
        // spec * pow(max(dot(reflectV, E), 0.0), shininess)
        vec4 specularTerm = matSpecular * pow(max(dot(reflectV, E), 0.0), 5.0);
        //vec4 specularTerm = vec4(1.0, 1.0, 1.0, 1.0) * pow(max(dot(reflectV, E), 0.0), 5.0);
     
        gl_FragColor = (ambientTerm + diffuseTerm + specularTerm) * att;
    }

    The light position is: 0, 2, 2

    If you need more info, please ask for it.

  2. #2
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2
    Post is also posted on stack overflow, with the same title (and image)

Posting Permissions

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