Changeset 1338


Ignore:
Timestamp:
May 4, 2012, 1:00:30 AM (11 years ago)
Author:
sam
Message:

orbital: rewrite the shader once again.

Location:
trunk/orbital
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/mesh.h

    r1332 r1338  
    9191            "void main(void)"
    9292            "{"
    93                  /* Global shit */
    94             "    float alpha_mul = 1.0f;"
    95 
    96                  /* Ambient: global constant */
     93                 /* Material properties */
     94            "    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);"
     95            "    float specular_power = 60.f;"
     96
     97                 /* World properties */
    9798            "    float ambient_mul = 0.5f;"
    98 
    99                  /* Diffuse: the level should decide of these values */
    100             "    vec3 diffuse_dir = normalize(vec3(-0.7, -0.7, -0.4));"
    101             "    vec4 frontColor = vec4(1.0, 1.0, 1.0, 1.0);"
    102             "    vec4 backColor = vec4(0.3, 0.2, 0.0, 1.0);"
    103 
    104             "    vec3 world_normal = normalize(in_NormalMat * in_Normal);"
    105             "    float d = dot(world_normal, diffuse_dir);"
    106             "    vec2 diffuse_mul = max(vec2(-d, d), 0.0);"
    107             "    diffuse_mul[0] = min(diffuse_mul[0] + ambient_mul, 1.0);"
    108 
    109                  /* Specular: global settings */
    110             "    vec4 spec_col = vec4(0.8, 0.75, 0.4, 1.0);"
    111             "    vec3 spec_dir = normalize(vec3(-0.3, -0.3, -1.8));"
    112             "    float spec_exp = 60.f;"
    113 
    114             "    float spec_mul = max(-dot(world_normal, spec_dir), 0.0);"
    115             "    spec_mul = clamp(pow(spec_mul, spec_exp), 0.0, 1.0);"
    116 
    117 
    118             "    vec4 tmpColor = frontColor * in_Color;"
    119             "    pass_Color = clamp(diffuse_mul[0] * tmpColor"
    120             "                        + diffuse_mul[1] * backColor"
    121             "                        + spec_mul * spec_col, 0.0, 1.0);"
    122             "    pass_Color.a *= alpha_mul;"
    123 
    124             "    vec4 viewPosition = in_ModelView * vec4(in_Vertex, 1.0);"
    125             "    gl_Position = in_Proj * viewPosition;"
     99            "    vec3 light_dir = normalize(vec3(0.3, 0.3, 0.7));"
     100            "    vec3 ambient_color = vec3(0.25, 0.2, 0.35);"
     101            "    vec3 diffuse_color = vec3(1.0, 1.0, 0.6);"
     102            "    vec3 specular_color = vec3(1.0, 1.0, 0.6);"
     103
     104            "    vec3 tnorm = normalize(in_NormalMat * in_Normal);"
     105            "    vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);"
     106
     107            "    vec3 s = light_dir;" /* normalize(eye - lightpos); */
     108            "    vec3 v = normalize(-eye.xyz);"
     109            "    vec3 r = reflect(-s, tnorm);"
     110
     111            "    vec3 ambient = ambient_color;"
     112            "    float sdotn = max(dot(s, tnorm), 0.0);"
     113            "    vec3 diffuse = diffuse_color * sdotn;"
     114            "    vec3 specular = vec3(0.0);"
     115            "    if (sdotn > 0.0)"
     116            "        specular = specular_color * specular_reflect"
     117            "                 * pow(max(dot(r, v), 0.0), specular_power);"
     118            "    vec3 light = ambient + diffuse + specular;"
     119
     120            "    pass_Color = in_Color * vec4(light, 1.0);"
     121            "    gl_Position = in_Proj * eye;"
    126122            "}",
    127123
     
    142138            "          out float4 pass_Color : COLOR)"
    143139            "{"
    144             "    float alpha_mul = 1.0f;"
     140            "    float3 specular_reflect = float3(0.8, 0.75, 0.4);"
     141            "    float specular_power = 60.f;"
    145142            "    float ambient_mul = 0.5f;"
    146             "    float3 diffuse_dir = normalize(float3(-0.7, -0.7, -0.4));"
    147             "    float4 frontColor = float4(1.0, 1.0, 1.0, 1.0);"
    148             "    float4 backColor = float4(0.3, 0.2, 0.0, 1.0);"
    149             "    float3 world_normal = normalize(mul(in_NormalMat, in_Normal));"
    150             "    float d = dot(world_normal, diffuse_dir);"
    151             "    float2 diffuse_mul = max(float2(-d, d), 0.0);"
    152             "    diffuse_mul[0] = min(diffuse_mul[0] + ambient_mul, 1.0);"
    153             "    float4 spec_col = float4(0.8, 0.85, 0.4, 1.0);"
    154             "    float3 spec_dir = normalize(float3(-0.7, -0.7, 0.4));"
    155             "    float spec_exp = 60.0f;"
    156             "    float spec_mul = max(-dot(world_normal, spec_dir), 0.0);"
    157             "    spec_mul = saturate(pow(spec_mul, spec_exp));"
    158             "    float4 tmpColor = frontColor * in_Color;"
    159             "    pass_Color = saturate(diffuse_mul[0] * tmpColor"
    160             "                           + diffuse_mul[1] * backColor"
    161             "                           + spec_mul * spec_col);"
    162             "    pass_Color.a *= alpha_mul;"
    163             "    float4 viewPosition = mul(in_ModelView, float4(in_Vertex, 1.0));"
    164             "    out_Position = mul(in_Proj, viewPosition);"
     143            "    float3 light_dir = normalize(float3(0.3, 0.3, 0.7));"
     144            "    float3 ambient_color = float3(0.25, 0.2, 0.35);"
     145            "    float3 diffuse_color = float3(1.0, 1.0, 0.6);"
     146            "    float3 specular_color = float3(1.0, 1.0, 0.6);"
     147            "    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));"
     148            "    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));"
     149            "    float3 s = light_dir;"
     150            "    float3 v = normalize(-eye.xyz);"
     151            "    float3 r = reflect(-s, tnorm);"
     152            "    float3 ambient = ambient_color;"
     153            "    float sdotn = max(dot(s, tnorm), 0.0);"
     154            "    float3 diffuse = diffuse_color * sdotn;"
     155            "    float3 specular = float3(0.0);"
     156            "    if (sdotn > 0.0)"
     157            "        specular = specular_color * specular_reflect"
     158            "                 * pow(max(dot(r, v), 0.0), specular_power);"
     159            "    float3 light = ambient + diffuse + specular;"
     160            "    pass_Color = in_Color * float4(light, 1.0);"
     161            "    out_Position = mul(in_Proj, eye);"
    165162            "}",
    166163
  • trunk/orbital/orbital.cpp

    r1336 r1338  
    4242    /* Yellow sphere */
    4343    m.SendCommand("sc1,1,0,1,asph10,30,20,24");
    44     m.SendCommand("t0,0,-60,fl");
     44    m.SendCommand("t0,0,60,fl");
    4545
    4646    /* Pink box */
    4747    m.SendCommand("sc1,0,1,1,afcb10,10,10,1,rx45,rz45");
    48     m.SendCommand("t-20,-20,0,fl");
     48    m.SendCommand("t-20,20,0,fl");
    4949
    5050    /* Large meteor */
     
    7171    /* Orange fire */
    7272    m.SendCommand("sc1,1,0,1,scb1,0,0,0,at4,1,s1.5,1,4,tz-13,ad6,5.8,1");
    73     m.SendCommand("t-40,-40,0,fl");
     73    m.SendCommand("t-40,40,0,fl");
    7474
    7575    /* Lasers */
     
    8383    Ticker::Ref(m_particlesystem);
    8484
    85     m_camera = new Camera(vec3(0, 200, 300),
     85    m_camera = new Camera(vec3(0, 200, 200),
    8686                          vec3(0, 0, 0),
    8787                          vec3(0, 1, 0));
  • trunk/orbital/particlesystem.h

    r1333 r1338  
    1717        m_ready(false)
    1818    {
    19         m_mesh.SendCommand("sc.8,.8,.8,1,acg8,2,5,5,1.5,1.5,.1,0,rx15");
     19        m_mesh.SendCommand("sc.8,.8,.8,1,acg4,2,5,5,1.5,1.5,.1,0,rx15");
    2020        m_mesh.SendCommand("t0,-100,-30,fl");
    2121
Note: See TracChangeset for help on using the changeset viewer.