Ignore:
Timestamp:
Aug 18, 2012, 12:53:24 PM (7 years ago)
Author:
sam
Message:

easymesh: per-fragment lighting in the HLSL shader (PS3, Xbox 360).

File:
1 edited

Legend:

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

    r1765 r1769  
    4343vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
    4444
    45 void main(void) {
     45void main(void)
     46{
    4647    /* Material properties */
    4748    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
     
    8081          uniform float4x4 in_Proj,
    8182          uniform float3x3 in_NormalMat,
     83          out float4 pass_Eye : TEXCOORD0,
     84          out float3 pass_TNormal : TEXCOORD1,
     85          out float4 pass_Color : COLOR,
     86          out float4 out_Position : POSITION)
     87{
     88    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
     89    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
     90
     91    pass_Eye = eye;
     92    pass_TNormal = tnorm;
     93#ifdef _XBOX
     94    pass_Color = in_Color.abgr;
     95#else
     96    pass_Color = in_Color;
     97#endif
     98
     99    out_Position = mul(in_Proj, eye);
     100}
     101
     102-- HLSL.Frag --
     103
     104void main(float4 pass_Eye : TEXCOORD0,
     105          float3 pass_TNormal : TEXCOORD1,
     106          float4 pass_Color : COLOR,
    82107          uniform float in_Damage,
    83           out float4 out_Position : POSITION,
    84           out float4 pass_Color : COLOR)
     108          out float4 out_FragColor : COLOR)
    85109{
    86     float3 in_LightDir = normalize(float3(0.3, 0.3, 0.7));
     110    float3 in_LightDir = float3(0.3, 0.3, 0.7);
    87111
     112    /* Material properties */
    88113    float3 specular_reflect = float3(0.8, 0.75, 0.4);
    89114    float specular_power = 60.0;
     115
     116    /* World properties */
    90117    float ambient_mul = 0.5;
    91118    float3 ambient_color = float3(0.25, 0.2, 0.35);
    92119    float3 diffuse_color = float3(1.0, 1.0, 0.6);
    93120    float3 specular_color = float3(1.0, 1.0, 0.6);
    94     float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
    95     float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
    96     float3 s = in_LightDir;
    97     float3 v = normalize(-eye.xyz);
    98     float3 r = reflect(-s, tnorm);
     121
     122    float3 s = normalize(in_LightDir); /* normalize(pass_Eye - lightpos); */
     123    float3 v = normalize(-pass_Eye.xyz);
     124    float3 r = reflect(-s, pass_TNormal);
     125
    99126    float3 ambient = ambient_color;
    100     float sdotn = max(dot(s, tnorm), 0.0);
     127    float sdotn = max(dot(s, pass_TNormal), 0.0);
    101128    float3 diffuse = diffuse_color * sdotn;
    102129    float3 specular = float3(0.0, 0.0, 0.0);
     
    105132                 * pow(max(dot(r, v), 0.0), specular_power);
    106133    float3 light = ambient + diffuse + specular;
    107 #ifdef _XBOX
    108     float4 real_color = in_Color.abgr;
    109 #else
    110     float4 real_color = in_Color;
    111 #endif
    112     real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
    113                + (1.0 - in_Damage) * real_color;
    114     pass_Color = real_color * float4(light, 1.0);
    115     out_Position = mul(in_Proj, eye);
     134
     135    float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
     136                      + (1.0 - in_Damage) * pass_Color;
     137    out_FragColor = real_color * float4(light, 1.0);
    116138}
    117139
    118 -- HLSL.Frag --
    119 
    120 void main(float4 pass_Color : COLOR,
    121           out float4 out_FragColor : COLOR)
    122 {
    123     out_FragColor = pass_Color;
    124 }
    125 
Note: See TracChangeset for help on using the changeset viewer.