Ignore:
Timestamp:
Aug 17, 2012, 1:33:06 PM (7 years ago)
Author:
sam
Message:

easymesh: fragment-based lighting.

File:
1 edited

Legend:

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

    r1693 r1765  
    1010uniform mat4 in_Proj;
    1111uniform mat3 in_NormalMat;
    12 // FIXME: the light direction should be passed in the code
    13 vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
    14 uniform float in_Damage;
    1512
     13varying vec4 pass_Eye;
     14varying vec3 pass_TNormal;
    1615varying vec4 pass_Color;
    1716
    1817void main(void)
    1918{
     19    vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);
     20    vec3 tnorm = normalize(in_NormalMat * in_Normal);
     21
     22    pass_Eye = eye;
     23    pass_TNormal = tnorm;
     24    pass_Color = in_Color;
     25
     26    gl_Position = in_Proj * eye;
     27}
     28
     29-- GLSL.Frag --
     30#version 120
     31
     32#if defined GL_ES
     33precision highp float;
     34#endif
     35
     36uniform float in_Damage;
     37
     38varying vec4 pass_Eye;
     39varying vec3 pass_TNormal;
     40varying vec4 pass_Color;
     41
     42// FIXME: the light direction should be passed in the code
     43vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
     44
     45void main(void) {
    2046    /* Material properties */
    2147    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
     
    2854    vec3 specular_color = vec3(1.0, 1.0, 0.6);
    2955
    30     vec3 tnorm = normalize(in_NormalMat * in_Normal);
    31     vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);
    32 
    33     vec3 s = normalize(in_LightDir); /* normalize(eye - lightpos); */
    34     vec3 v = normalize(-eye.xyz);
    35     vec3 r = reflect(-s, tnorm);
     56    vec3 s = normalize(in_LightDir); /* normalize(pass_Eye - lightpos); */
     57    vec3 v = normalize(-pass_Eye.xyz);
     58    vec3 r = reflect(-s, pass_TNormal);
    3659
    3760    vec3 ambient = ambient_color;
    38     float sdotn = max(dot(s, tnorm), 0.0);
     61    float sdotn = max(dot(s, pass_TNormal), 0.0);
    3962    vec3 diffuse = diffuse_color * sdotn;
    4063    vec3 specular = vec3(0.0, 0.0, 0.0);
     
    4568
    4669    vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0)
    47                     + (1.0 - in_Damage) * in_Color;
    48     pass_Color = real_color * vec4(light, 1.0);
    49     gl_Position = in_Proj * eye;
    50 }
    51 
    52 -- GLSL.Frag --
    53 #version 120
    54 
    55 #if defined GL_ES
    56 precision highp float;
    57 #endif
    58 varying vec4 pass_Color;
    59 
    60 void main(void) {
    61     gl_FragColor = pass_Color;
     70                    + (1.0 - in_Damage) * pass_Color;
     71    gl_FragColor = real_color * vec4(light, 1.0);
    6272}
    6373
Note: See TracChangeset for help on using the changeset viewer.