Parcourir la source

Light : Added Type SfEnum.

Shiny*.lolfx : fixed Directional light calculation.
MV : Tweak for future camera behaviour encapsulation.
undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> il y a 11 ans
Parent
révision
066f131852
10 fichiers modifiés avec 642 ajouts et 518 suppressions
  1. +1
    -1
      src/easymesh/easymeshrender.cpp
  2. +1
    -1
      src/easymesh/easymeshrender.h
  3. +4
    -3
      src/easymesh/shiny.lolfx
  4. +5
    -4
      src/easymesh/shinyflat.lolfx
  5. +16
    -7
      src/light.cpp
  6. +56
    -5
      src/light.h
  7. +127
    -119
      test/generated/scenesetup-parser.cpp
  8. +362
    -351
      test/generated/scenesetup-parser.output
  9. +66
    -25
      test/meshviewer.cpp
  10. +4
    -2
      test/scenesetup-parser.y

+ 1
- 1
src/easymesh/easymeshrender.cpp Voir le fichier

@@ -159,7 +159,7 @@ void DefaultShaderData::SetupShaderDatas(mat4 const &model)
/* FIXME: the 4th component of the position can be used for other things */
/* FIXME: GetUniform("blabla") is costly */
for (int i = 0; i < lights.Count(); ++i)
light_data << lights[i]->GetPosition() << lights[i]->GetColor();
light_data << vec4(lights[i]->GetPosition(), lights[i]->GetType()) << lights[i]->GetColor();
while (light_data.Count() < 8)
light_data << vec4::zero << vec4::zero;



+ 1
- 1
src/easymesh/easymeshrender.h Voir le fichier

@@ -26,7 +26,7 @@ struct MeshRender
{
enum Value
{
NeedData,
NeedData = 0,
NeedConvert,
CanRender,
IgnoreRender,


+ 4
- 3
src/easymesh/shiny.lolfx Voir le fichier

@@ -79,18 +79,19 @@ void main(void)
{
vec4 pos = u_Lights[i * 2];
vec4 color = u_Lights[i * 2 + 1];
vec3 s, r;
vec3 s, r, p;

p = (in_View * pos).xyz;
if (pos.w > 0.0)
{
/* Point light -- no attenuation yet */
s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
s = normalize(p - pass_Vertex.xyz);
r = reflect(-s, TNormal);
}
else
{
/* Directional light */
s = normalize(-pos.xyz);
s = normalize(-p);
r = reflect(s, TNormal);
}



+ 5
- 4
src/easymesh/shinyflat.lolfx Voir le fichier

@@ -63,7 +63,7 @@ void main(void)
vec3 TNormal = pass_TNormal;
vec3 X = dFdx(pass_Vertex.xyz);
vec3 Y = dFdy(pass_Vertex.xyz);
TNormal = normalize(cross(X, Y) ) * length(normalize(pass_TNormal));
TNormal = normalize(cross(Y, X)) * length(normalize(pass_TNormal));

/* Material properties */
vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
@@ -82,18 +82,19 @@ void main(void)
{
vec4 pos = u_Lights[i * 2];
vec4 color = u_Lights[i * 2 + 1];
vec3 s, r;
vec3 s, r, p;

p = (in_View * pos).xyz;
if (pos.w > 0.0)
{
/* Point light -- no attenuation yet */
s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
s = normalize(p - pass_Vertex.xyz);
r = reflect(-s, TNormal);
}
else
{
/* Directional light */
s = normalize(-pos.xyz);
s = normalize(-p);
r = reflect(s, TNormal);
}



+ 16
- 7
src/light.cpp Voir le fichier

@@ -22,27 +22,36 @@ namespace lol

Light::Light()
: m_color(1.f),
m_directional(true)
m_type(LightType::Directional)
{
m_gamegroup = GAMEGROUP_BEFORE;
m_drawgroup = DRAWGROUP_CAMERA;

SetPosition(vec4::zero);
SetPosition(vec3::zero);
}

Light::~Light()
{
}

void Light::SetPosition(vec4 const &pos)
void Light::SetType(LightType const &type)
{
m_directional = (pos.w > 0.f);
m_position = pos.xyz;
m_type = type;
}

vec4 Light::GetPosition()
LightType Light::GetType()
{
return vec4(m_position, m_directional ? 1.f : 0.f);
return m_type;
}

void Light::SetPosition(vec3 const &pos)
{
m_position = pos;
}

vec3 Light::GetPosition()
{
return m_position;
}

void Light::SetColor(vec4 const &color)


+ 56
- 5
src/light.h Voir le fichier

@@ -21,6 +21,54 @@
namespace lol
{

struct LightType
{
enum Value
{
Directional = 0,
Point,

Max,
}
m_value;

static char const *GetName(Value v)
{
switch (v)
{
case Directional:
return "<Directional>";
case Point:
return "<Point>";
default:
return "<UNDEFINED>";
}
}

inline LightType(float v)
{
float top = FLT_MAX;
int iv = Directional;
for (int i = 0; i < Max; ++i)
{
LightType lv = LightType(i);
float nv = lv.f();
float ntop = lol::abs(nv - v);
if (ntop < top)
{
top = ntop;
iv = i;
}
}
m_value = LightType(iv);
}
inline LightType(int v) : m_value((Value)v) {}
inline LightType(Value v) : m_value(v) {}
inline LightType() : m_value(Directional) {}
inline operator Value() { return m_value; }
inline float f() { return ((float)m_value / (float)Max); }
};

class Light : public WorldEntity
{
public:
@@ -29,19 +77,22 @@ public:

char const *GetName() { return "<light>"; }

void SetColor(vec4 const &col);
void SetType(LightType const &type);
LightType GetType();

void SetColor(vec4 const &color);
vec4 GetColor();

void SetPosition(vec4 const &pos);
vec4 GetPosition();
void SetPosition(vec3 const &pos);
vec3 GetPosition();

protected:
virtual void TickGame(float seconds);
virtual void TickDraw(float seconds);

private:
vec4 m_color;
bool m_directional;
vec4 m_color;
LightType m_type;
};

} /* namespace lol */


+ 127
- 119
test/generated/scenesetup-parser.cpp Voir le fichier

@@ -447,15 +447,15 @@ namespace lol {
/* Line 677 of lalr1.cc */
#line 117 "scenesetup-parser.y"
{ uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, (yysemantic_stack_[(2) - (2)].fval))); }
uc.m_sstp.m_lights.Last()->SetType(LightType((yysemantic_stack_[(2) - (2)].fval))); }
break;

case 14:

/* Line 677 of lalr1.cc */
#line 122 "scenesetup-parser.y"
{ if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); }
#line 119 "scenesetup-parser.y"
{ uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(FindValue<LightType>((yysemantic_stack_[(2) - (2)].svval))); }
break;

case 15:
@@ -463,7 +463,7 @@ namespace lol {
/* Line 677 of lalr1.cc */
#line 124 "scenesetup-parser.y"
{ if (uc.m_last_cmd == "ADDLIGHT")
{ /* */ } }
uc.m_sstp.m_lights.Last()->SetPosition(vec3((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2])); }
break;

case 16:
@@ -471,13 +471,21 @@ namespace lol {
/* Line 677 of lalr1.cc */
#line 126 "scenesetup-parser.y"
{ if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3])); }
{ /* */ } }
break;

case 17:

/* Line 677 of lalr1.cc */
#line 128 "scenesetup-parser.y"
{ if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3])); }
break;

case 18:

/* Line 677 of lalr1.cc */
#line 130 "scenesetup-parser.y"
{ uint32_t x = (yysemantic_stack_[(2) - (2)].u32val);
ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
vec4 vv = vec4(v) * (1.f / 255.f);
@@ -485,175 +493,175 @@ namespace lol {
uc.m_sstp.m_lights.Last()->SetColor(vv); }
break;

case 18:
case 19:

/* Line 677 of lalr1.cc */
#line 136 "scenesetup-parser.y"
#line 138 "scenesetup-parser.y"
{ uc.m_sstp.m_clear_color = vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3]); }
break;

case 19:
case 20:

/* Line 677 of lalr1.cc */
#line 137 "scenesetup-parser.y"
#line 139 "scenesetup-parser.y"
{ uc.m_sstp.m_clear_color = vec4((yysemantic_stack_[(5) - (2)].vval)[0], (yysemantic_stack_[(5) - (2)].vval)[1], (yysemantic_stack_[(5) - (2)].vval)[2], 1.f); }
break;

case 20:
case 21:

/* Line 677 of lalr1.cc */
#line 138 "scenesetup-parser.y"
#line 140 "scenesetup-parser.y"
{ uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
uc.m_sstp.m_clear_color = vec4(v) * (1.f / 255.f); }
break;

case 21:
case 22:

/* Line 677 of lalr1.cc */
#line 140 "scenesetup-parser.y"
#line 142 "scenesetup-parser.y"
{ uc.m_sstp.m_show_gizmo = (yysemantic_stack_[(2) - (2)].bval); }
break;

case 22:
case 23:

/* Line 677 of lalr1.cc */
#line 141 "scenesetup-parser.y"
#line 143 "scenesetup-parser.y"
{ uc.m_sstp.m_show_lights = (yysemantic_stack_[(2) - (2)].bval); }
break;

case 23:
case 24:

/* Line 677 of lalr1.cc */
#line 145 "scenesetup-parser.y"
#line 147 "scenesetup-parser.y"
{ uc.m_sstp.m_custom_cmd.Push((yysemantic_stack_[(3) - (2)].svval), (yysemantic_stack_[(3) - (3)].sval)); }
break;

case 24:
case 25:

/* Line 677 of lalr1.cc */
#line 151 "scenesetup-parser.y"
#line 153 "scenesetup-parser.y"
{ (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); }
break;

case 25:
case 26:

/* Line 677 of lalr1.cc */
#line 152 "scenesetup-parser.y"
#line 154 "scenesetup-parser.y"
{ (yyval.fval) = -(yysemantic_stack_[(2) - (2)].fval); }
break;

case 26:
case 27:

/* Line 677 of lalr1.cc */
#line 153 "scenesetup-parser.y"
#line 155 "scenesetup-parser.y"
{ (yyval.fval) = (float)(yysemantic_stack_[(1) - (1)].ival); }
break;

case 27:
case 28:

/* Line 677 of lalr1.cc */
#line 154 "scenesetup-parser.y"
#line 156 "scenesetup-parser.y"
{ (yyval.fval) = -(float)(yysemantic_stack_[(2) - (2)].ival); }
break;

case 28:
case 29:

/* Line 677 of lalr1.cc */
#line 158 "scenesetup-parser.y"
#line 160 "scenesetup-parser.y"
{ (yyval.ival) = (yysemantic_stack_[(1) - (1)].ival); }
break;

case 29:
case 30:

/* Line 677 of lalr1.cc */
#line 159 "scenesetup-parser.y"
#line 161 "scenesetup-parser.y"
{ (yyval.ival) = -(yysemantic_stack_[(2) - (2)].ival); }
break;

case 30:
case 31:

/* Line 677 of lalr1.cc */
#line 160 "scenesetup-parser.y"
#line 162 "scenesetup-parser.y"
{ (yyval.ival) = (int)(yysemantic_stack_[(1) - (1)].fval); }
break;

case 31:
case 32:

/* Line 677 of lalr1.cc */
#line 161 "scenesetup-parser.y"
#line 163 "scenesetup-parser.y"
{ (yyval.ival) = -(int)(yysemantic_stack_[(2) - (2)].fval); }
break;

case 32:
case 33:

/* Line 677 of lalr1.cc */
#line 166 "scenesetup-parser.y"
#line 168 "scenesetup-parser.y"
{ (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); }
break;

case 33:
case 34:

/* Line 677 of lalr1.cc */
#line 167 "scenesetup-parser.y"
#line 169 "scenesetup-parser.y"
{ (yyval.vval)[0] = (yysemantic_stack_[(5) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(5) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(5) - (4)].fval); }
break;

case 34:
case 35:

/* Line 677 of lalr1.cc */
#line 176 "scenesetup-parser.y"
#line 178 "scenesetup-parser.y"
{ (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[3] = (yysemantic_stack_[(3) - (2)].fval); }
break;

case 35:
case 36:

/* Line 677 of lalr1.cc */
#line 177 "scenesetup-parser.y"
#line 179 "scenesetup-parser.y"
{ (yyval.vval)[0] = (yysemantic_stack_[(6) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(6) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(6) - (4)].fval); (yyval.vval)[3] = (yysemantic_stack_[(6) - (5)].fval); }
break;

case 36:
case 37:

/* Line 677 of lalr1.cc */
#line 182 "scenesetup-parser.y"
#line 184 "scenesetup-parser.y"
{ (yyval.bval) = (yysemantic_stack_[(1) - (1)].bval); }
break;

case 37:
case 38:

/* Line 677 of lalr1.cc */
#line 183 "scenesetup-parser.y"
#line 185 "scenesetup-parser.y"
{ (yyval.bval) = !!(yysemantic_stack_[(1) - (1)].ival); }
break;

case 38:
case 39:

/* Line 677 of lalr1.cc */
#line 184 "scenesetup-parser.y"
#line 186 "scenesetup-parser.y"
{ (yyval.bval) = !!(yysemantic_stack_[(1) - (1)].fval); }
break;

case 39:
case 40:

/* Line 677 of lalr1.cc */
#line 188 "scenesetup-parser.y"
#line 190 "scenesetup-parser.y"
{ (yyval.svval) = (yysemantic_stack_[(1) - (1)].svval); }
break;

case 40:
case 41:

/* Line 677 of lalr1.cc */
#line 192 "scenesetup-parser.y"
#line 194 "scenesetup-parser.y"
{ String t = (yysemantic_stack_[(1) - (1)].sval);
t.Replace('"', ' ', true);
free((yysemantic_stack_[(1) - (1)].sval));
(yyval.sval) = strdup((const char *)t.C()); }
break;

case 41:
case 42:

/* Line 677 of lalr1.cc */
#line 196 "scenesetup-parser.y"
#line 198 "scenesetup-parser.y"
{ String t = (yysemantic_stack_[(2) - (1)].sval);
t += (yysemantic_stack_[(2) - (2)].sval);
t.Replace('"', ' ', true);
@@ -665,7 +673,7 @@ namespace lol {


/* Line 677 of lalr1.cc */
#line 669 "generated/scenesetup-parser.cpp"
#line 677 "generated/scenesetup-parser.cpp"
default:
break;
}
@@ -870,17 +878,17 @@ namespace lol {

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
const signed char SceneSetupParser::yypact_ninf_ = -20;
const signed char SceneSetupParser::yypact_ninf_ = -21;
const signed char
SceneSetupParser::yypact_[] =
{
38, 4, -18, -18, -7, 14, 16, 16, -10, 15,
21, 38, 38, -20, -20, -20, -20, -20, -20, -20,
6, -20, 4, -20, -20, -20, 4, -20, -20, -20,
-20, -20, -20, -20, -20, -20, 7, -20, -20, -20,
-20, -20, -20, 6, -20, -20, -9, -5, 18, 7,
-20, -20, -20, -20, 4, -20, 4, -18, -20, 10,
4, -20, -20, 17, -20
38, 6, -18, -18, -6, -2, 37, 37, -13, 7,
21, 38, 38, -21, -21, -21, -21, -21, -21, -21,
-21, 17, -21, -21, 19, -21, -21, -21, 19, -21,
-21, -21, -21, -21, -21, -21, -21, 8, -21, -21,
-21, -21, -21, -21, 17, -21, -21, -8, -4, 18,
8, -21, -21, -21, -21, 19, -21, 19, -18, -21,
13, 19, -21, -21, 31, -21
};

/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
@@ -890,28 +898,28 @@ namespace lol {
SceneSetupParser::yydefact_[] =
{
0, 12, 0, 0, 0, 0, 0, 0, 0, 0,
0, 3, 5, 6, 8, 9, 10, 11, 24, 26,
0, 13, 0, 14, 15, 17, 0, 16, 20, 18,
38, 37, 36, 21, 22, 39, 0, 1, 2, 4,
7, 24, 26, 0, 25, 27, 0, 0, 0, 40,
23, 25, 27, 32, 0, 34, 0, 0, 41, 0,
0, 19, 33, 0, 35
0, 3, 5, 6, 8, 9, 10, 11, 25, 27,
40, 0, 13, 14, 0, 15, 16, 18, 0, 17,
21, 19, 39, 38, 37, 22, 23, 0, 1, 2,
4, 7, 25, 27, 0, 26, 28, 0, 0, 0,
41, 24, 26, 28, 33, 0, 35, 0, 0, 42,
0, 0, 20, 34, 0, 36
};

/* YYPGOTO[NTERM-NUM]. */
const signed char
SceneSetupParser::yypgoto_[] =
{
-20, -20, 25, -20, -20, 27, -20, -20, -20, -20,
-20, -19, 8, -3, 35, 43, -20, 3
-21, -21, 28, -21, -21, 41, -21, -21, -21, -21,
-21, -20, -15, -3, 35, 49, 50, 9
};

/* YYDEFGOTO[NTERM-NUM]. */
const signed char
SceneSetupParser::yydefgoto_[] =
{
-1, 9, 10, 11, 12, 13, 14, 15, 16, 48,
17, 21, 45, 23, 27, 33, 36, 50
-1, 9, 10, 11, 12, 13, 14, 15, 16, 49,
17, 22, 46, 25, 29, 35, 23, 51
};

/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@@ -921,24 +929,24 @@ namespace lol {
const unsigned char
SceneSetupParser::yytable_[] =
{
24, 44, 22, 46, 18, 19, 35, 47, 18, 19,
20, 25, 53, 26, 20, 37, 55, 18, 19, 41,
42, 38, 49, 20, 51, 43, 57, 54, 56, 30,
31, 62, 28, 32, 26, 59, 39, 60, 64, 40,
29, 63, 1, 2, 3, 4, 5, 6, 7, 8,
34, 52, 58, 0, 61
26, 45, 24, 20, 47, 18, 19, 38, 48, 18,
19, 21, 27, 54, 28, 21, 30, 56, 28, 18,
19, 39, 20, 50, 52, 21, 58, 55, 57, 53,
42, 43, 18, 19, 63, 60, 44, 61, 21, 40,
31, 64, 1, 2, 3, 4, 5, 6, 7, 8,
32, 33, 65, 41, 34, 62, 36, 0, 37, 59
};

/* YYCHECK. */
const signed char
SceneSetupParser::yycheck_[] =
{
3, 20, 20, 22, 13, 14, 16, 26, 13, 14,
19, 18, 21, 20, 19, 0, 21, 13, 14, 13,
14, 0, 15, 19, 43, 19, 8, 46, 47, 13,
14, 21, 18, 17, 20, 54, 11, 56, 21, 12,
5, 60, 4, 5, 6, 7, 8, 9, 10, 11,
7, 43, 49, -1, 57
3, 21, 20, 16, 24, 13, 14, 0, 28, 13,
14, 19, 18, 21, 20, 19, 18, 21, 20, 13,
14, 0, 16, 15, 44, 19, 8, 47, 48, 44,
13, 14, 13, 14, 21, 55, 19, 57, 19, 11,
5, 61, 4, 5, 6, 7, 8, 9, 10, 11,
13, 14, 21, 12, 17, 58, 7, -1, 8, 50
};

/* STOS_[STATE-NUM] -- The (internal number of the) accessing
@@ -948,11 +956,11 @@ namespace lol {
{
0, 4, 5, 6, 7, 8, 9, 10, 11, 23,
24, 25, 26, 27, 28, 29, 30, 32, 13, 14,
19, 33, 20, 35, 35, 18, 20, 36, 18, 36,
13, 14, 17, 37, 37, 16, 38, 0, 0, 24,
27, 13, 14, 19, 33, 34, 33, 33, 31, 15,
39, 33, 34, 21, 33, 21, 33, 8, 39, 33,
33, 35, 21, 33, 21
16, 19, 33, 38, 20, 35, 35, 18, 20, 36,
18, 36, 13, 14, 17, 37, 37, 38, 0, 0,
24, 27, 13, 14, 19, 33, 34, 33, 33, 31,
15, 39, 33, 34, 21, 33, 21, 33, 8, 39,
33, 33, 35, 21, 33, 21
};

#if YYDEBUG
@@ -972,10 +980,10 @@ namespace lol {
SceneSetupParser::yyr1_[] =
{
0, 22, 23, 24, 24, 25, 26, 26, 27, 27,
27, 27, 28, 28, 29, 29, 29, 29, 31, 30,
30, 30, 30, 32, 33, 33, 33, 33, 34, 34,
34, 34, 35, 35, 36, 36, 37, 37, 37, 38,
39, 39
27, 27, 28, 28, 28, 29, 29, 29, 29, 31,
30, 30, 30, 30, 32, 33, 33, 33, 33, 34,
34, 34, 34, 35, 35, 36, 36, 37, 37, 37,
38, 39, 39
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
@@ -983,10 +991,10 @@ namespace lol {
SceneSetupParser::yyr2_[] =
{
0, 2, 2, 1, 2, 1, 1, 2, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 0, 5,
2, 2, 2, 3, 1, 2, 1, 2, 1, 2,
1, 2, 3, 5, 3, 6, 1, 1, 1, 1,
1, 2
1, 1, 1, 2, 2, 2, 2, 2, 2, 0,
5, 2, 2, 2, 3, 1, 2, 1, 2, 1,
2, 1, 2, 3, 5, 3, 6, 1, 1, 1,
1, 1, 2
};

#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
@@ -1014,15 +1022,15 @@ namespace lol {
23, 0, -1, 24, 0, -1, 25, -1, 25, 24,
-1, 26, -1, 27, -1, 26, 27, -1, 28, -1,
29, -1, 30, -1, 32, -1, 4, -1, 4, 33,
-1, 5, 35, -1, 6, 35, -1, 7, 36, -1,
7, 18, -1, -1, 8, 36, 31, 8, 35, -1,
8, 18, -1, 9, 37, -1, 10, 37, -1, 11,
38, 39, -1, 13, -1, 19, 33, -1, 14, -1,
19, 34, -1, 14, -1, 19, 34, -1, 13, -1,
19, 33, -1, 20, 33, 21, -1, 20, 33, 33,
33, 21, -1, 20, 33, 21, -1, 20, 33, 33,
33, 33, 21, -1, 17, -1, 14, -1, 13, -1,
16, -1, 15, -1, 15, 39, -1
-1, 4, 38, -1, 5, 35, -1, 6, 35, -1,
7, 36, -1, 7, 18, -1, -1, 8, 36, 31,
8, 35, -1, 8, 18, -1, 9, 37, -1, 10,
37, -1, 11, 38, 39, -1, 13, -1, 19, 33,
-1, 14, -1, 19, 34, -1, 14, -1, 19, 34,
-1, 13, -1, 19, 33, -1, 20, 33, 21, -1,
20, 33, 33, 33, 21, -1, 20, 33, 21, -1,
20, 33, 33, 33, 33, 21, -1, 17, -1, 14,
-1, 13, -1, 16, -1, 15, -1, 15, 39, -1
};

/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
@@ -1031,10 +1039,10 @@ namespace lol {
SceneSetupParser::yyprhs_[] =
{
0, 0, 3, 6, 8, 11, 13, 15, 18, 20,
22, 24, 26, 28, 31, 34, 37, 40, 43, 44,
50, 53, 56, 59, 63, 65, 68, 70, 73, 75,
78, 80, 83, 87, 93, 97, 104, 106, 108, 110,
112, 114
22, 24, 26, 28, 31, 34, 37, 40, 43, 46,
47, 53, 56, 59, 62, 66, 68, 71, 73, 76,
78, 81, 83, 86, 90, 96, 100, 107, 109, 111,
113, 115, 117
};

/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
@@ -1042,10 +1050,10 @@ namespace lol {
SceneSetupParser::yyrline_[] =
{
0, 91, 91, 95, 96, 100, 104, 105, 109, 110,
111, 112, 116, 117, 122, 124, 126, 128, 136, 136,
138, 140, 141, 145, 151, 152, 153, 154, 158, 159,
160, 161, 166, 167, 176, 177, 182, 183, 184, 188,
192, 196
111, 112, 116, 117, 119, 124, 126, 128, 130, 138,
138, 140, 142, 143, 147, 153, 154, 155, 156, 160,
161, 162, 163, 168, 169, 178, 179, 184, 185, 186,
190, 194, 198
};

// Print the state stack on the debug stream.
@@ -1121,10 +1129,10 @@ namespace lol {
}

const int SceneSetupParser::yyeof_ = 0;
const int SceneSetupParser::yylast_ = 54;
const int SceneSetupParser::yylast_ = 59;
const int SceneSetupParser::yynnts_ = 18;
const int SceneSetupParser::yyempty_ = -2;
const int SceneSetupParser::yyfinal_ = 37;
const int SceneSetupParser::yyfinal_ = 38;
const int SceneSetupParser::yyterror_ = 1;
const int SceneSetupParser::yyerrcode_ = 256;
const int SceneSetupParser::yyntokens_ = 22;
@@ -1136,11 +1144,11 @@ namespace lol {
} // lol

/* Line 1053 of lalr1.cc */
#line 1140 "generated/scenesetup-parser.cpp"
#line 1148 "generated/scenesetup-parser.cpp"


/* Line 1055 of lalr1.cc */
#line 204 "scenesetup-parser.y"
#line 206 "scenesetup-parser.y"


void lol::SceneSetupParser::error(const SceneSetupParser::location_type& l,


+ 362
- 351
test/generated/scenesetup-parser.output
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 66
- 25
test/meshviewer.cpp Voir le fichier

@@ -39,9 +39,9 @@ static int const TEXTURE_WIDTH = 256;
#define WIDTH ((float)Video::GetSize().x)
#define HEIGHT ((float)Video::GetSize().y)
#define SCREEN_W (10.f / WIDTH)
#define SCREEN_LIMIT 1.4f
#define RATIO_HW (HEIGHT / WIDTH)
#define RATIO_WH (WIDTH / HEIGHT)
#define SCREEN_LIMIT 1.4f

#define RESET_TIMER .2f
#define ROT_SPEED vec2(50.f)
@@ -140,6 +140,34 @@ struct LightData
vec4 m_col;
};

class TargetCamera
{
public:
void EmptyTargets() { m_targets.Empty(); }
void AddTarget(vec3 new_target) { m_targets << new_target; }
//This considers the box usage A to B as top-left to bottom-right
void AddTarget(box3 new_target)
{
vec3 base_off = .5f * (new_target.B - new_target.A);
vec3 base_pos = new_target.A + base_off;
int pass = 0;
while (pass < 3)
{
int mask = 3 - max(0, pass - 1);
while (mask-- > 0)
{
ivec3 A((pass == 1 || (pass == 2 && mask == 1))?(1):(0));
ivec3 B((pass == 2)?(1):(0)); B[mask] = 1;
vec3 offset = vec3(ivec3((int)(!A.x != !B.x), (int)(!A.y != !B.y), (int)(!A.z != !B.z)));
AddTarget(base_pos + offset * base_off * 2.f - base_off);
}
pass++;
}
}

Array<vec3> m_targets;
};

class MeshViewer : public WorldEntity
{
public:
@@ -193,7 +221,7 @@ public:
m_hist_scale_speed = vec2(.0f);

m_mat_prev = mat4(quat::fromeuler_xyz(vec3::zero));
m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));
m_mat = mat4::translate(vec3(0.f));//mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));

m_build_timer = 0.1f;
m_build_time = -1.f;
@@ -312,7 +340,7 @@ public:
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]->SetPosition(vec3::zero);
m_ssetup->m_lights[i]->SetColor(vec4::zero);
}
}
@@ -358,13 +386,13 @@ public:
//Update light position & damping
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
{
vec3 pos = (m_mat * inverse(m_mat_prev) * vec4(m_ssetup->m_lights[i]->GetPosition().xyz, 1.f)).xyz;
vec3 pos = (m_mat * inverse(m_mat_prev) * vec4(m_ssetup->m_lights[i]->GetPosition(), 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]->SetPosition(new_pos);
m_ssetup->m_lights[i]->SetColor(new_col);
}

@@ -382,7 +410,7 @@ public:
{
tmpv += vec2(AxisValue(MSEX_CAM_Y), AxisValue(MSEX_CAM_X));
if (KeyDown(MSE_CAM_ROT))
tmpv *= 6.f;
tmpv *= vec2(1.f, 1.f) * 6.f;
if (KeyDown(MSE_CAM_POS))
tmpv *= vec2(1.f, -1.f) * 3.f;
if (KeyDown(MSE_CAM_FOV))
@@ -394,7 +422,7 @@ public:
#endif //NO_NACL_EM_INPUT

//Base data
vec2 rot = (!is_pos && !is_fov)?(tmpv):(vec2(.0f)); rot = vec2(rot.x, rot.y);
vec2 rot = (!is_pos && !is_fov)?(tmpv):(vec2(.0f)); rot = vec2(rot.x, -rot.y);
vec2 pos = ( is_pos && !is_fov)?(tmpv):(vec2(.0f)); pos = -vec2(pos.y, pos.x);
vec2 fov = (!is_pos && is_fov )?(tmpv):(vec2(.0f)); fov = vec2(-fov.x, fov.y);
vec2 hsc = (is_hsc)?(vec2(0.f)):(vec2(0.f));
@@ -460,13 +488,22 @@ public:

//Mesh mat calculation
m_mat_prev = m_mat;
m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));
m_mat = mat4::translate(vec3(0.f));//mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));

//Target List Setup
Array<vec3> target_list;
TargetCamera tc;
if (m_meshes.Count() && m_mesh_id >= 0)
for (int i = 0; i < m_meshes[m_mesh_id].m1->GetVertexCount(); i++)
target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz;
tc.AddTarget((m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz);
tc.AddTarget(box3(vec3::zero, vec3::one));
for (int k = 0; k < m_ssetup->m_lights.Count() && m_ssetup->m_show_lights; ++k)
{
vec3 light_pos = m_ssetup->m_lights[k]->GetPosition();
mat4 world_cam = m_camera->GetView();
light_pos = (inverse(world_cam) * vec4((world_cam * vec4(light_pos, 1.0f)).xyz * vec3::axis_z, 1.0f)).xyz;
tc.AddTarget(box3(vec3::mone, vec3::one) + light_pos *
((m_ssetup->m_lights[k]->GetType() == LightType::Directional)?(-1.f):(1.f)));
}

//--
//Update mesh screen location - Get the Min/Max needed
@@ -479,9 +516,9 @@ public:
mat4 cam_screen = m_camera->GetProjection();

//target on-screen computation
for (int i = 0; i < target_list.Count(); i++)
for (int i = 0; i < tc.m_targets.Count(); i++)
{
vec3 obj_loc = target_list[i];
vec3 obj_loc = tc.m_targets[i];
{
//Debug::DrawBox(obj_loc - vec3(4.f), obj_loc + vec3(4.f), vec4(1.f, 0.f, 0.f, 1.f));
mat4 target_mx = mat4::translate(obj_loc);
@@ -504,21 +541,25 @@ public:
cam_factor += 1.f;
}
}
float screen_ratio = max(max(lol::abs(local_min_max[0].x), lol::abs(local_min_max[0].y)),
max(lol::abs(local_min_max[1].x), lol::abs(local_min_max[1].y)));
float scale_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
float screen_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
float z_dist = length(m_camera->m_position) + max(local_min_max[0].z, local_min_max[1].z);

vec2 screen_offset = vec2(0.f, -(screen_min_max[1].y + screen_min_max[0].y) * .5f);
m_screen_offset = damp(m_screen_offset, screen_offset, .9f, seconds);
float z_pos = (inverse(world_cam) * mat4::translate(vec3(0.f, 0.f, max(local_min_max[0].z, local_min_max[1].z)))).v3.z;

if (cam_factor > 0.f)
{
vec2 new_screen_scale = m_camera->GetScreenScale();
m_camera->SetScreenScale(max(vec2(0.001f), new_screen_scale * ((1.0f + lol::max(0.f, m_zoom_mesh)) / (scale_ratio * (1.f + lol::max(0.f, -m_zoom_mesh)) * SCREEN_LIMIT))));
m_camera->SetPosition(vec3(vec2::zero, damp(m_camera->m_position.z, z_pos + screen_ratio * 2.f, .1f, seconds)), true);
float zoom_in = 1.f + lol::max(0.f, m_zoom_mesh);
float zoom_out = 1.f + lol::max(0.f, -m_zoom_mesh);
m_camera->SetScreenScale(max(vec2(0.001f), ((new_screen_scale * zoom_in) / (screen_ratio * zoom_out * SCREEN_LIMIT))));
m_camera->SetFov(m_fov_mesh);
m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio * (1.f + lol::max(0.f, -m_zoom_mesh))), 1.2f, seconds));
m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio * zoom_out), 1.2f, seconds));

vec3 posz = ((mat4::rotate(m_rot_mesh.y, vec3::axis_y) * mat4::rotate(-m_rot_mesh.x, vec3::axis_x) * vec4::axis_z)).xyz;
vec3 newpos = posz * damp(length(m_camera->m_position), z_dist * 1.2f, .1f, seconds);
m_camera->SetView(newpos, vec3(0.f), vec3::axis_y);
}

//--
@@ -537,7 +578,7 @@ public:
//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());
light_datas << LightData(m_ssetup->m_lights[i]->GetPosition(), m_ssetup->m_lights[i]->GetColor());

if (m_ssetup)
delete(m_ssetup);
@@ -549,7 +590,7 @@ public:
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
{
//Store local dst in current m_ld
LightData ltmp = LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor());
LightData ltmp = LightData(m_ssetup->m_lights[i]->GetPosition(), m_ssetup->m_lights[i]->GetColor());
if (i < m_light_datas.Count())
m_light_datas[i] = ltmp;
else
@@ -564,7 +605,7 @@ public:
}

//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]->SetPosition(loc);
m_ssetup->m_lights[i]->SetColor(col);
}
}
@@ -798,13 +839,13 @@ public:
for (int k = 0; k < m_ssetup->m_lights.Count(); ++k)
{
Light* ltmp = m_ssetup->m_lights[k];
mat4 world = mat4::translate(ltmp->GetPosition().xyz);
mat4 world = mat4::translate(ltmp->GetPosition());
mat4 local = mat4::translate((inverse(m_mat) * world).v3.xyz);
//dir light
if (ltmp->GetPosition().w == 0.f)
if (ltmp->GetType() == LightType::Directional)
{
m_gizmos[GZ_LightPos]->Render(m_mat * inverse(local));
m_gizmos[GZ_LightDir]->Render(inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition().xyz, vec3::axis_y)));
m_gizmos[GZ_LightDir]->Render(inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y)));
}
else //point light
{


+ 4
- 2
test/scenesetup-parser.y Voir le fichier

@@ -115,12 +115,14 @@ sstp_command:
light_command:
T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; }
| T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, $2)); }
uc.m_sstp.m_lights.Last()->SetType(LightType($2)); }
| T_ADDLIGHT svv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(FindValue<LightType>($2)); }
;

setup_command:
T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3($2[0], $2[1], $2[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); }
uc.m_sstp.m_lights.Last()->SetPosition(vec3($2[0], $2[1], $2[2])); }
| T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT")
{ /* */ } }
| T_OBJCOLOR v4 { if (uc.m_last_cmd == "ADDLIGHT")


Chargement…
Annuler
Enregistrer