Browse Source

easymesh: fix point light handling.

legacy
Sam Hocevar sam 12 years ago
parent
commit
573c5053d9
3 changed files with 31 additions and 34 deletions
  1. +2
    -2
      src/easymesh/easymesh.cpp
  2. +1
    -1
      src/easymesh/easymesh.h
  3. +28
    -31
      src/easymesh/shiny.lolfx

+ 2
- 2
src/easymesh/easymesh.cpp View File

@@ -67,7 +67,7 @@ void EasyMesh::MeshConvert()
m_gpu.shader = Shader::Create(lolfx_shiny); m_gpu.shader = Shader::Create(lolfx_shiny);


m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView"); m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView");
m_gpu.model = m_gpu.shader->GetUniformLocation("in_Model");
m_gpu.view = m_gpu.shader->GetUniformLocation("in_View");
m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj"); m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj");
m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat"); m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat");
m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage"); m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage");
@@ -118,7 +118,7 @@ void EasyMesh::Render(mat4 const &model, float damage)


m_gpu.shader->Bind(); m_gpu.shader->Bind();
m_gpu.shader->SetUniform(m_gpu.modelview, modelview); m_gpu.shader->SetUniform(m_gpu.modelview, modelview);
m_gpu.shader->SetUniform(m_gpu.model, Scene::GetDefault()->GetViewMatrix());
m_gpu.shader->SetUniform(m_gpu.view, Scene::GetDefault()->GetViewMatrix());
m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix()); m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix());
m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat); m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat);
m_gpu.shader->SetUniform(m_gpu.damage, damage); m_gpu.shader->SetUniform(m_gpu.damage, damage);


+ 1
- 1
src/easymesh/easymesh.h View File

@@ -101,7 +101,7 @@ private:
{ {
Shader *shader; Shader *shader;
ShaderAttrib coord, norm, color; ShaderAttrib coord, norm, color;
ShaderUniform modelview, model, proj, normalmat, damage;
ShaderUniform modelview, view, proj, normalmat, damage;
VertexDeclaration *vdecl; VertexDeclaration *vdecl;
VertexBuffer *vbo; VertexBuffer *vbo;
IndexBuffer *ibo; IndexBuffer *ibo;


+ 28
- 31
src/easymesh/shiny.lolfx View File

@@ -7,26 +7,24 @@ attribute vec3 in_Normal;
attribute vec4 in_Color; attribute vec4 in_Color;


uniform mat4 in_ModelView; uniform mat4 in_ModelView;
uniform mat4 in_Model;
uniform mat4 in_View;
uniform mat4 in_Proj; uniform mat4 in_Proj;
uniform mat3 in_NormalMat; uniform mat3 in_NormalMat;


varying vec4 pass_Eye;
varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal; varying vec3 pass_TNormal;
varying vec4 pass_TPos;
varying vec4 pass_Color; varying vec4 pass_Color;


void main(void) void main(void)
{ {
vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_NormalMat * in_Normal); vec3 tnorm = normalize(in_NormalMat * in_Normal);


pass_Eye = eye;
pass_Vertex = vertex;
pass_TNormal = tnorm; pass_TNormal = tnorm;
pass_TPos = in_Model * vec4(in_Vertex, 1.0);
pass_Color = in_Color; pass_Color = in_Color;


gl_Position = in_Proj * eye;
gl_Position = in_Proj * vertex;
} }


[frag.glsl] [frag.glsl]
@@ -37,16 +35,15 @@ precision highp float;
#endif #endif


uniform float in_Damage; uniform float in_Damage;
uniform mat4 in_Model;
uniform mat4 in_View;


varying vec4 pass_Eye;
varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal; varying vec3 pass_TNormal;
varying vec4 pass_TPos;
varying vec4 pass_Color; varying vec4 pass_Color;


// FIXME: the light direction should be passed in the code // FIXME: the light direction should be passed in the code
vec3 in_LightDir = vec3(0.3, 0.3, 0.7); vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
vec4 in_Light2_Pos = in_Model * vec4(0.0, 0.0, 0.0, 1.0);
vec4 in_Light2_Pos = vec4(-100.0, 100.0, -100.0, 1.0);


void main(void) void main(void)
{ {
@@ -61,17 +58,17 @@ void main(void)
vec3 specular_color = vec3(1.0, 1.0, 0.6); vec3 specular_color = vec3(1.0, 1.0, 0.6);


vec3 ambient = ambient_color; vec3 ambient = ambient_color;
vec3 specular = vec3(0.0, 0.0, 0.0);
vec3 diffuse = vec3(0.0, 0.0, 0.0);
vec3 s = vec3(0.0, 0.0, 0.0);
vec3 v = vec3(0.0, 0.0, 0.0);
vec3 r = vec3(0.0, 0.0, 0.0);
float sdotn = 0.0;
/*
//Light calculation for directional light
vec3 specular = vec3(0.0, 0.0, 0.0);
vec3 diffuse = vec3(0.0, 0.0, 0.0);
vec3 s = vec3(0.0, 0.0, 0.0);
vec3 v = vec3(0.0, 0.0, 0.0);
vec3 r = vec3(0.0, 0.0, 0.0);
float sdotn = 0.0;
/*
//Light calculation for directional light
s = normalize(in_LightDir); s = normalize(in_LightDir);
v = normalize(-pass_Eye.xyz);
v = normalize(-pass_Vertex.xyz);
r = reflect(-s, pass_TNormal); r = reflect(-s, pass_TNormal);


sdotn = max(dot(s, pass_TNormal), 0.0); sdotn = max(dot(s, pass_TNormal), 0.0);
@@ -79,11 +76,11 @@ void main(void)
if (sdotn > 0.0) if (sdotn > 0.0)
specular += specular_color * specular_reflect specular += specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power); * pow(max(dot(r, v), 0.0), specular_power);
*/
*/


//Light calculation for point light
s = normalize(pass_Eye.xyz - in_Light2_Pos.xyz); //(pass_TPos.xyz - in_Light2_Pos);
v = normalize(-pass_Eye.xyz);
//Light calculation for point light
s = normalize((in_View * in_Light2_Pos).xyz - pass_Vertex.xyz);
v = normalize(-pass_Vertex.xyz);
r = reflect(-s, pass_TNormal); r = reflect(-s, pass_TNormal);


sdotn = max(dot(s, pass_TNormal), 0.0); sdotn = max(dot(s, pass_TNormal), 0.0);
@@ -106,10 +103,10 @@ void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL, float3 in_Normal : NORMAL,
float4 in_Color : COLOR, float4 in_Color : COLOR,
uniform float4x4 in_ModelView, uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Model,
uniform float4x4 in_Proj, uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat, uniform float3x3 in_NormalMat,
out float4 pass_Eye : TEXCOORD0,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1, out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR, out float4 pass_Color : COLOR,
out float4 out_Position : POSITION) out float4 out_Position : POSITION)
@@ -117,7 +114,7 @@ void main(float3 in_Vertex : POSITION,
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); float3 tnorm = normalize(mul(in_NormalMat, in_Normal));


pass_Eye = eye;
pass_Vertex = eye;
pass_TNormal = tnorm; pass_TNormal = tnorm;
#ifdef _XBOX #ifdef _XBOX
pass_Color = in_Color.abgr; pass_Color = in_Color.abgr;
@@ -130,7 +127,7 @@ void main(float3 in_Vertex : POSITION,


[frag.hlsl] [frag.hlsl]


void main(float4 pass_Eye : TEXCOORD0,
void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1, float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR, float4 pass_Color : COLOR,
uniform float in_Damage, uniform float in_Damage,
@@ -148,8 +145,8 @@ void main(float4 pass_Eye : TEXCOORD0,
float3 diffuse_color = float3(1.0, 1.0, 0.6); float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6); float3 specular_color = float3(1.0, 1.0, 0.6);


float3 s = normalize(in_LightDir); /* normalize(pass_Eye - lightpos); */
float3 v = normalize(-pass_Eye.xyz);
float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal); float3 r = reflect(-s, pass_TNormal);


float3 ambient = ambient_color; float3 ambient = ambient_color;


Loading…
Cancel
Save