Browse Source

first commit in a while, small test in ShinyLol

legacy
Benjamin ‘Touky’ Huet touky 12 years ago
parent
commit
8cde92fd2e
3 changed files with 40 additions and 10 deletions
  1. +2
    -0
      src/easymesh/easymesh.cpp
  2. +1
    -1
      src/easymesh/easymesh.h
  3. +37
    -9
      src/easymesh/shiny.lolfx

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

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

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

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


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

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


+ 37
- 9
src/easymesh/shiny.lolfx View File

@@ -7,11 +7,13 @@ attribute vec3 in_Normal;
attribute vec4 in_Color;

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

varying vec4 pass_Eye;
varying vec3 pass_TNormal;
varying vec4 pass_TPos;
varying vec4 pass_Color;

void main(void)
@@ -21,6 +23,7 @@ void main(void)

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

gl_Position = in_Proj * eye;
@@ -37,10 +40,12 @@ uniform float in_Damage;

varying vec4 pass_Eye;
varying vec3 pass_TNormal;
varying vec4 pass_TPos;
varying vec4 pass_Color;

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

void main(void)
{
@@ -50,21 +55,43 @@ void main(void)

/* World properties */
float ambient_mul = 0.5;
vec3 ambient_color = vec3(0.25, 0.2, 0.35);
vec3 ambient_color = vec3(0.0, 0.0, 0.0);
vec3 diffuse_color = vec3(1.0, 1.0, 0.6);
vec3 specular_color = vec3(1.0, 1.0, 0.6);

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

vec3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
vec3 diffuse = diffuse_color * sdotn;
vec3 specular = vec3(0.0, 0.0, 0.0);
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);
v = normalize(-pass_Eye.xyz);
r = reflect(-s, pass_TNormal);

sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += diffuse_color * sdotn;
if (sdotn > 0.0)
specular = specular_color * specular_reflect
specular += specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
*/

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

sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += diffuse_color * sdotn;
//if (sdotn > 0.0)
// specular += specular_color * specular_reflect
// * pow(max(dot(r, v), 0.0), specular_power);


vec3 light = ambient + diffuse + specular;

vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0)
@@ -78,6 +105,7 @@ void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Eye : TEXCOORD0,


Loading…
Cancel
Save