Sfoglia il codice sorgente

the stupidest idea of the day : the cube light, specular still missing.

legacy
Benjamin ‘Touky’ Huet touky 12 anni fa
parent
commit
924a2afbbe
4 ha cambiato i file con 37 aggiunte e 6 eliminazioni
  1. +2
    -0
      src/easymesh/easymesh.cpp
  2. +1
    -1
      src/easymesh/easymesh.h
  3. +33
    -4
      src/easymesh/shiny.lolfx
  4. +1
    -1
      test/Physics/Src/BulletCharacterController.cpp

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

@@ -68,6 +68,7 @@ void EasyMesh::MeshConvert()

m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView");
m_gpu.view = m_gpu.shader->GetUniformLocation("in_View");
m_gpu.invview = m_gpu.shader->GetUniformLocation("in_Inv_View");
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");
@@ -119,6 +120,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.view, Scene::GetDefault()->GetViewMatrix());
m_gpu.shader->SetUniform(m_gpu.invview, inverse(Scene::GetDefault()->GetViewMatrix()));
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 Vedi File

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


+ 33
- 4
src/easymesh/shiny.lolfx Vedi File

@@ -36,17 +36,27 @@ precision highp float;

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

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

// FIXME: the light direction should be passed in the code
// FIXME: all the light parameters should be passed in the code
//Dir Light
vec3 in_LightDir = vec3(-0.3, -0.3, -0.7);
vec4 in_Light2_Pos = vec4(0.0, 10.0, 0.0, 1.0);

//Point Light
vec4 in_Light2_Pos = vec4(20.0, 10.0, 0.0, 1.0);
float in_Light2_Radius = 20.0;
vec3 in_Light2_diffuse = vec3(0.4, 0.4, 1.0);

//Cube Light
vec4 in_Light3_Pos = vec4(-10.0, 10.0, 5.0, 1.0);
vec3 in_Light3_Size_Inner = vec3(1.0, 1.0, 1.0);
vec3 in_Light3_Size_Outer = vec3(10.0, 10.0, 10.0);
vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4);

void main(void)
{
/* Material properties */
@@ -66,6 +76,7 @@ void main(void)
vec3 v = vec3(0.0, 0.0, 0.0);
vec3 r = vec3(0.0, 0.0, 0.0);
float sdotn = 0.0;
float light_radius_mod = 0.0;

//Light calculation for directional light
s = normalize(-in_LightDir);
@@ -77,11 +88,11 @@ void main(void)
if (sdotn > 0.0)
specular += specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
//----------
//Light calculation for point light
vec3 tmpLightDir = (in_View * in_Light2_Pos).xyz - pass_Vertex.xyz;
float light_radius_mod = max(0.0, 1.0 - (length(tmpLightDir) / in_Light2_Radius));
light_radius_mod = max(0.0, 1.0 - (length(tmpLightDir) / in_Light2_Radius));
s = normalize(tmpLightDir);
v = normalize(-pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);
@@ -91,7 +102,25 @@ void main(void)
if (sdotn > 0.0 && light_radius_mod > 0.0)
specular += specular_color * min(specular_reflect, light_radius_mod)
* pow(max(dot(r, v), 0.0), specular_power);
//----------
//Light calculation for cube light
vec3 Local_Vertex = (in_Inv_View * pass_Vertex).xyz - (in_Light3_Pos).xyz;
vec3 Proj_Vertex = clamp(Local_Vertex.xyz, -in_Light3_Size_Inner, in_Light3_Size_Inner);
vec3 new_LightDir = Local_Vertex - Proj_Vertex;

vec3 light_radius = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0) - abs(new_LightDir / in_Light3_Size_Outer));
light_radius_mod = min(light_radius.x, min(light_radius.y, light_radius.z));

if (length(new_LightDir) == 0.0)
sdotn = 1.0;
else
{
new_LightDir = (in_View * vec4(Proj_Vertex + in_Light3_Pos.xyz,1.0)).xyz - pass_Vertex.xyz;
sdotn = max(dot(normalize(new_LightDir), pass_TNormal), 0.0);
}
diffuse += in_Light3_diffuse * min(sdotn, light_radius_mod);
//----------

vec3 light = ambient + diffuse + specular;



+ 1
- 1
test/Physics/Src/BulletCharacterController.cpp Vedi File

@@ -175,7 +175,7 @@ void BulletKinematicCharacterController::DoMove(btCollisionWorld* CollisionWorld
}
}

//The PreStepis done in order to recover from any HasPenetration.
//The PreStep is done in order to recover from any HasPenetration.
void BulletKinematicCharacterController::PreStep(btCollisionWorld* CollisionWorld)
{
int MaxPenetrationLoop = 0;


Caricamento…
Annulla
Salva