Ignore:
Timestamp:
Dec 18, 2012, 8:48:08 PM (7 years ago)
Author:
touky
Message:

shiny.lolfx now has a PointLight & a DirectionalLight.
Sorry for all the fine projects that use this shader !

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/shiny.lolfx

    r2145 r2146  
    4343
    4444// FIXME: the light direction should be passed in the code
    45 vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
    46 vec4 in_Light2_Pos = vec4(-100.0, 100.0, -100.0, 1.0);
     45vec3 in_LightDir = vec3(-0.3, -0.3, -0.7);
     46vec4 in_Light2_Pos = vec4(0.0, 10.0, 0.0, 1.0);
     47float in_Light2_Radius = 20.0;
     48vec3 in_Light2_diffuse = vec3(0.4, 0.4, 1.0);
    4749
    4850void main(void)
     
    5557    float ambient_mul = 0.5;
    5658    vec3 ambient_color = vec3(0.0, 0.0, 0.0);
    57     vec3 diffuse_color = vec3(1.0, 1.0, 0.6);
     59    vec3 diffuse_color = vec3(0.4, 0.4, 0.4);
    5860    vec3 specular_color = vec3(1.0, 1.0, 0.6);
    5961
     
    6668    float sdotn = 0.0;
    6769
    68     /*
    6970    //Light calculation for directional light
    70     s = normalize(in_LightDir);
     71    s = normalize(-in_LightDir);
    7172    v = normalize(-pass_Vertex.xyz);
    72     r = reflect(-s, pass_TNormal);
     73    r = reflect(s, pass_TNormal);
    7374
    7475    sdotn = max(dot(s, pass_TNormal), 0.0);
     
    7778        specular += specular_color * specular_reflect
    7879                 * pow(max(dot(r, v), 0.0), specular_power);
    79     */
    8080
     81   
    8182    //Light calculation for point light
    82     s = normalize((in_View * in_Light2_Pos).xyz - pass_Vertex.xyz);
     83        vec3 tmpLightDir = (in_View * in_Light2_Pos).xyz - pass_Vertex.xyz;
     84        float light_radius_mod = max(0.0, 1.0 - (length(tmpLightDir) / in_Light2_Radius));
     85    s = normalize(tmpLightDir);
    8386    v = normalize(-pass_Vertex.xyz);
    8487    r = reflect(-s, pass_TNormal);
    8588
    8689    sdotn = max(dot(s, pass_TNormal), 0.0);
    87     diffuse += diffuse_color * sdotn;
    88     //if (sdotn > 0.0)
    89     //    specular += specular_color * specular_reflect
    90     //             * pow(max(dot(r, v), 0.0), specular_power);
    91 
     90    diffuse += in_Light2_diffuse * min(sdotn, light_radius_mod);
     91    if (sdotn > 0.0 && light_radius_mod > 0.0)
     92        specular += specular_color * min(specular_reflect, light_radius_mod)
     93                 * pow(max(dot(r, v), 0.0), specular_power);
     94   
    9295
    9396    vec3 light = ambient + diffuse + specular;
Note: See TracChangeset for help on using the changeset viewer.