Ignore:
Timestamp:
Dec 18, 2012, 4:07:02 PM (7 years ago)
Author:
sam
Message:

easymesh: fix point light handling.

Location:
trunk/src/easymesh
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/easymesh.cpp

    r2144 r2145  
    6868
    6969    m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView");
    70     m_gpu.model = m_gpu.shader->GetUniformLocation("in_Model");
     70    m_gpu.view = m_gpu.shader->GetUniformLocation("in_View");
    7171    m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj");
    7272    m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat");
     
    119119    m_gpu.shader->Bind();
    120120    m_gpu.shader->SetUniform(m_gpu.modelview, modelview);
    121     m_gpu.shader->SetUniform(m_gpu.model, Scene::GetDefault()->GetViewMatrix());
     121    m_gpu.shader->SetUniform(m_gpu.view, Scene::GetDefault()->GetViewMatrix());
    122122    m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix());
    123123    m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat);
  • trunk/src/easymesh/easymesh.h

    r2143 r2145  
    102102        Shader *shader;
    103103        ShaderAttrib coord, norm, color;
    104         ShaderUniform modelview, model, proj, normalmat, damage;
     104        ShaderUniform modelview, view, proj, normalmat, damage;
    105105        VertexDeclaration *vdecl;
    106106        VertexBuffer *vbo;
  • trunk/src/easymesh/shiny.lolfx

    r2144 r2145  
    88
    99uniform mat4 in_ModelView;
    10 uniform mat4 in_Model;
     10uniform mat4 in_View;
    1111uniform mat4 in_Proj;
    1212uniform mat3 in_NormalMat;
    1313
    14 varying vec4 pass_Eye;
     14varying vec4 pass_Vertex; /* View space */
    1515varying vec3 pass_TNormal;
    16 varying vec4 pass_TPos;
    1716varying vec4 pass_Color;
    1817
    1918void main(void)
    2019{
    21     vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);
     20    vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
    2221    vec3 tnorm = normalize(in_NormalMat * in_Normal);
    2322
    24     pass_Eye = eye;
     23    pass_Vertex = vertex;
    2524    pass_TNormal = tnorm;
    26         pass_TPos = in_Model * vec4(in_Vertex, 1.0);
    2725    pass_Color = in_Color;
    2826
    29     gl_Position = in_Proj * eye;
     27    gl_Position = in_Proj * vertex;
    3028}
    3129
     
    3836
    3937uniform float in_Damage;
    40 uniform mat4 in_Model;
     38uniform mat4 in_View;
    4139
    42 varying vec4 pass_Eye;
     40varying vec4 pass_Vertex; /* View space */
    4341varying vec3 pass_TNormal;
    44 varying vec4 pass_TPos;
    4542varying vec4 pass_Color;
    4643
    4744// FIXME: the light direction should be passed in the code
    4845vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
    49 vec4 in_Light2_Pos = in_Model * vec4(0.0, 0.0, 0.0, 1.0);
     46vec4 in_Light2_Pos = vec4(-100.0, 100.0, -100.0, 1.0);
    5047
    5148void main(void)
     
    6259
    6360    vec3 ambient = ambient_color;
    64         vec3 specular = vec3(0.0, 0.0, 0.0);
    65         vec3 diffuse = vec3(0.0, 0.0, 0.0);
    66         vec3 s = vec3(0.0, 0.0, 0.0);
    67         vec3 v = vec3(0.0, 0.0, 0.0);
    68         vec3 r = vec3(0.0, 0.0, 0.0);
    69         float sdotn = 0.0;
     61    vec3 specular = vec3(0.0, 0.0, 0.0);
     62    vec3 diffuse = vec3(0.0, 0.0, 0.0);
     63    vec3 s = vec3(0.0, 0.0, 0.0);
     64    vec3 v = vec3(0.0, 0.0, 0.0);
     65    vec3 r = vec3(0.0, 0.0, 0.0);
     66    float sdotn = 0.0;
    7067
    71         /*
    72         //Light calculation for directional light
     68    /*
     69    //Light calculation for directional light
    7370    s = normalize(in_LightDir);
    74     v = normalize(-pass_Eye.xyz);
     71    v = normalize(-pass_Vertex.xyz);
    7572    r = reflect(-s, pass_TNormal);
    7673
     
    8077        specular += specular_color * specular_reflect
    8178                 * pow(max(dot(r, v), 0.0), specular_power);
    82         */
     79    */
    8380
    84         //Light calculation for point light
    85     s = normalize(pass_Eye.xyz - in_Light2_Pos.xyz); //(pass_TPos.xyz - in_Light2_Pos);
    86     v = normalize(-pass_Eye.xyz);
     81    //Light calculation for point light
     82    s = normalize((in_View * in_Light2_Pos).xyz - pass_Vertex.xyz);
     83    v = normalize(-pass_Vertex.xyz);
    8784    r = reflect(-s, pass_TNormal);
    8885
     
    107104          float4 in_Color : COLOR,
    108105          uniform float4x4 in_ModelView,
    109                   uniform float4x4 in_Model,
     106          uniform float4x4 in_Model,
    110107          uniform float4x4 in_Proj,
    111108          uniform float3x3 in_NormalMat,
    112           out float4 pass_Eye : TEXCOORD0,
     109          out float4 pass_Vertex : TEXCOORD0,
    113110          out float3 pass_TNormal : TEXCOORD1,
    114111          out float4 pass_Color : COLOR,
     
    118115    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
    119116
    120     pass_Eye = eye;
     117    pass_Vertex = eye;
    121118    pass_TNormal = tnorm;
    122119#ifdef _XBOX
     
    131128[frag.hlsl]
    132129
    133 void main(float4 pass_Eye : TEXCOORD0,
     130void main(float4 pass_Vertex : TEXCOORD0,
    134131          float3 pass_TNormal : TEXCOORD1,
    135132          float4 pass_Color : COLOR,
     
    149146    float3 specular_color = float3(1.0, 1.0, 0.6);
    150147
    151     float3 s = normalize(in_LightDir); /* normalize(pass_Eye - lightpos); */
    152     float3 v = normalize(-pass_Eye.xyz);
     148    float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
     149    float3 v = normalize(-pass_Vertex.xyz);
    153150    float3 r = reflect(-s, pass_TNormal);
    154151
Note: See TracChangeset for help on using the changeset viewer.