Changeset 1267


Ignore:
Timestamp:
Apr 22, 2012, 12:32:28 AM (8 years ago)
Author:
sam
Message:

orbital: implement the generic effect shader; doesn't seem to work as
expected yet, maybe because of Z or Y/Z inversions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/mesh.h

    r1263 r1267  
    4040            "varying vec4 pass_Color;"
    4141            ""
    42             "vec4 Light = vec4(3.0, 3.0, 1.0, 1.0);"
    43             "vec3 Kd = vec3(1.0, 0.8, 0.8);"
    44             "vec3 Ld = vec3(1.0, 0.8, 0.8);"
    45             ""
    46             "void main(void) {"
    47             "    vec3 tnorm = normalize(in_NormalMat * in_Normal);"
    48             "    vec4 Eye = in_ModelView * vec4(in_Vertex, 1.0);"
    49             "    vec3 s = normalize((Light - Eye).xyz);"
    50             ""
    51             "    pass_Color = vec4(Ld * Kd * max(dot(s, tnorm), 0.0), 1.0);"
    52             "    gl_Position = in_Proj * Eye;"
     42            "void main(void)"
     43            "{"
     44                 /* Diffuse information -- the level decides this */
     45
     46                 /* Global shit */
     47            "    float alpha_mul = 1.0f;"
     48
     49                 /* Ambient: global constant */
     50            "    float ambient_mul = 0.5f;"
     51
     52                 /* Diffuse: the level should decide of these values */
     53            "    vec3 diffuse_dir = normalize(vec3(-0.7, -0.7, -0.4));"
     54            "    vec4 frontColor = vec4(1.0, 1.0, 1.0, 1.0);"
     55            "    vec4 backColor = vec4(0.3, 0.2, 0.0, 1.0);"
     56
     57            "    vec3 world_normal = normalize(in_NormalMat * in_Normal);"
     58            "    float d = dot(world_normal, diffuse_dir);"
     59            "    vec2 diffuse_mul = max(vec2(-d, d), 0.0);"
     60            "    diffuse_mul[0] = min(diffuse_mul[0] + ambient_mul, 1.0);"
     61
     62                 /* Specular: global settings */
     63            "    vec4 spec_col = vec4(0.8, 0.85, 0.4, 1.0);"
     64            "    vec3 spec_dir = normalize(vec3(-0.7, -0.7, 0.4));"
     65            "    float spec_exp = 60.0f;"
     66
     67            "    float spec_mul = max(-dot(world_normal, spec_dir), 0.0);"
     68            "    spec_mul = clamp(pow(spec_mul, spec_exp), 0.0, 1.0);"
     69
     70
     71            "    vec4 TmpColor = frontColor * in_Color;"
     72                 /* NOTE: use saturate() in HLSL */
     73            "    pass_Color = clamp(diffuse_mul[0] * TmpColor"
     74            "                        + diffuse_mul[1] * backColor"
     75            "                        + spec_mul * spec_col, 0.0, 1.0);"
     76            "    pass_Color.a *= alpha_mul;"
     77
     78            "    vec4 viewPosition = in_ModelView * vec4(in_Vertex, 1.0);"
     79            "    gl_Position = in_Proj * viewPosition;"
    5380            "}",
    5481
Note: See TracChangeset for help on using the changeset viewer.