Diffuse and Specular Effect

Hi,

I am working on a 3D Graphics with light effect. I draw a plane with scaling(4,4,4). I set camera position at (1.0, 0.0, 10.0) and light at (0.0,0.0,5.0). Material diffuse color is (0.5,0.0,0.0,1.0) and specular color is (0.1,0.5,0.0,1.0). But there is no specular effect in result.

This is my shader source code :

Code.cpp


#version 300 es

in vec3 a_position;
in vec3 a_normal;
in vec2 texcoord;

uniform vec4 mat_ambient;
uniform vec4 mat_diffuse;
uniform vec4 mat_emission;
uniform vec4 mat_specular;

uniform mat4 u_mvp;
uniform mat4 u_world;
uniform mat4 u_view;

uniform vec3 u_lightPos;
uniform vec3 u_eyePos;

vec3 diffuse_effect, specular_effect;

void main() 
{


    gl_Position = u_mvp *  vec4(a_position,1.0);
    vec4 worldPos = u_world *  vec4(a_position,1.0);
    vec3 worldNormal = normalize(mat3(inverse(transpose(u_world))) * a_normal);
    vec3 viewDir = normalize(u_eyePos.xyz - worldPos.xyz); //also a unit vector


    lig[0].color = vec4(1.0,1.0,1.0,1.0);
    lig[0].position = vec3(0.0,5.0,10.0);

    lig[0].const_atten = 1.0f;
    lig[0].linear_atten = 0.0f;
    lig[0].quad_atten = 0.00111109f;
    lig[0].type = 1;

    float matShine = 50.0f;


    vec3 light_dir = (lig[0].position - worldPos.xyz);

    float diff_fac = max(0.0,dot(light_dir,worldNormal));

    float attn, spec_co_eff;

    diffuse_effect = lig[0].color.rgb * diff_fac * mat_diffuse.xyz;

    float dist = length(light_dir);

    light_dir = normalize(light_dir);

    attn = 1.0 / (lig[0].const_atten + lig[0].linear_atten * dist + lig[0].quad_atten  * dist * dist);

    if(dot(light_dir,worldNormal) < 0.0)
    {
        specular_effect = vec3(0.0,0.0,0.0);
    }
    else 
    {

        spec_co_eff = pow(max(0.0, dot(reflect(-light_dir, worldNormal), viewDir)), matShine);
        specular_effect = lig[0].color.rgb * attn * spec_co_eff * mat_specular.xyz;
    }

    linear_color = vec4((diffuse_effect + specular_effect ), 1.0);
}

Thanks in advance.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.