Преглед изворни кода

MViewer : Added Stupid light blending

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> пре 11 година
родитељ
комит
9b04264845
3 измењених фајлова са 61 додато и 6 уклоњено
  1. +2
    -1
      test/data/mesh-buffer.txt
  2. +59
    -4
      test/meshviewer.cpp
  3. +0
    -1
      test/scenesetup.h

+ 2
- 1
test/data/mesh-buffer.txt Прегледај датотеку

@@ -1,7 +1,8 @@
//addlight 0.0 position (0.6 0.5 1) color #ddf
addlight 0.0 position (1 0 1) color #0ff
addlight 0.0 position (-0.2 -1 -0.5) color (.0 .2 .5 1)

custom setmesh "sc#fff ab 2 ty 1.5 ab 2"
//splt 0
//test
//[sc#f8f ab 1 splt 4 twy 90]


+ 59
- 4
test/meshviewer.cpp Прегледај датотеку

@@ -119,6 +119,18 @@ enum MessageType
MSG_MAX
};

struct LightData
{
LightData(vec3 pos, vec4 col)
{
m_pos = pos;
m_col = col;
}

vec3 m_pos;
vec4 m_col;
};

class MeshViewer : public WorldEntity
{
public:
@@ -275,6 +287,12 @@ public:
// " custom setmesh \"sc#fff ab 1\""
m_ssetup->Startup();
#endif //NO_SC_SETUP
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
{
m_light_datas << LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor());
m_ssetup->m_lights[i]->SetPosition(vec4(vec3::zero, m_ssetup->m_lights[i]->GetPosition().w));
m_ssetup->m_lights[i]->SetColor(vec4::zero);
}
}

virtual void TickGame(float seconds)
@@ -308,11 +326,18 @@ public:
m_mesh_id1 = damp(m_mesh_id1, (float)m_mesh_id, .2f, seconds);

#if ALL_FEATURES
//Update light position

//Update light position & damping
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
{
vec4 v = m_ssetup->m_lights[i]->GetPosition();
m_ssetup->m_lights[i]->SetPosition(vec4((m_mat * inverse(m_mat_prev) * vec4(v.xyz, 1.f)).xyz, v.w));
vec3 pos = (m_mat * inverse(m_mat_prev) * vec4(m_ssetup->m_lights[i]->GetPosition().xyz, 1.f)).xyz;
vec3 tgt = (m_mat * vec4(m_light_datas[i].m_pos, 1.f)).xyz;

vec3 new_pos = damp(pos, tgt, .3f, seconds);
vec4 new_col = damp(m_ssetup->m_lights[i]->GetColor(), m_light_datas[i].m_col, .3f, seconds);

m_ssetup->m_lights[i]->SetPosition(vec4(new_pos, m_ssetup->m_lights[i]->GetPosition().w));
m_ssetup->m_lights[i]->SetColor(new_col);
}

//Camera update
@@ -481,11 +506,39 @@ public:
SceneSetup* new_ssetup = new SceneSetup();
if (new_ssetup->Compile(mesh.C()) && new_ssetup->GetLightNb())
{
//Store current light datas, in World
Array<LightData> light_datas;
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
light_datas << LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor());

if (m_ssetup)
delete(m_ssetup);
m_ssetup = new_ssetup;
m_ssetup->Startup();
m_mat_prev = mat4(quat::fromeuler_xyz(vec3::zero));

//Restore all light datas so blend can occur
mat4 light_mat = m_mat * inverse(mat4(quat::fromeuler_xyz(vec3::zero)));
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
{
//Store local dst in current m_ld
LightData tmp = LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor());
if (i < m_light_datas.Count())
m_light_datas[i] = tmp;
else
m_light_datas << tmp;

vec3 loc = vec3::zero;
vec4 col = vec4::zero;
if (i < light_datas.Count())
{
loc = light_datas[i].m_pos;
col = light_datas[i].m_col;
}

//Restore old light datas in new lights
m_ssetup->m_lights[i]->SetPosition(vec4(loc, m_ssetup->m_lights[i]->GetPosition().w));
m_ssetup->m_lights[i]->SetColor(col);
}
}
else
{
@@ -494,6 +547,7 @@ public:
}
}
}

//Check the custom cmd even if we don't have new messages.
for (int i = 0; m_ssetup && i < m_ssetup->m_custom_cmd.Count(); ++i)
{
@@ -643,6 +697,7 @@ public:

private:
SceneSetup* m_ssetup;
Array<LightData> m_light_datas;
Controller* m_controller;
short m_input_usage;
mat4 m_mat;


+ 0
- 1
test/scenesetup.h Прегледај датотеку

@@ -41,7 +41,6 @@ public:
//--
int GetLightNb() { return m_lights.Count(); }

//private:
Array<Light *> m_lights;
Array<String, String> m_custom_cmd;
};


Loading…
Откажи
Сачувај