Skip to content

Commit

Permalink
Merge pull request #62 from parasti/mtrl
Browse files Browse the repository at this point in the history
Lighting tweaks + material caching and reloading
  • Loading branch information
parasti committed Apr 7, 2014
2 parents 64e25ab + b7cc4fb commit 2963f71
Show file tree
Hide file tree
Showing 245 changed files with 3,846 additions and 3,926 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -230,6 +230,7 @@ BALL_OBJS := \
share/solid_draw.o \
share/solid_cmd.o \
share/solid_all.o \
share/mtrl.o \
share/part.o \
share/geom.o \
share/item.o \
Expand Down Expand Up @@ -300,6 +301,7 @@ PUTT_OBJS := \
share/solid_draw.o \
share/solid_cmd.o \
share/solid_all.o \
share/mtrl.o \
share/part.o \
share/geom.o \
share/ball.o \
Expand Down
4 changes: 4 additions & 0 deletions ball/game_client.c
Expand Up @@ -433,6 +433,10 @@ int game_client_init(const char *file_name)
back_init(grad_name);
sol_load_full(&gd.back, back_name, 0);

/* Initialize lighting. */

light_reset();

return gd.state;
}

Expand Down
89 changes: 26 additions & 63 deletions ball/game_draw.c
Expand Up @@ -60,48 +60,26 @@ static void game_draw_items(struct s_rend *rend,
{
int hi;

int type = ITEM_NONE;
int value = 0;

sol_color_mtrl(rend, 1);
for (hi = 0; hi < vary->hc; hi++)
{
for (hi = 0; hi < vary->hc; hi++)
{
struct v_item *hp = &vary->hv[hi];
struct v_item *hp = &vary->hv[hi];

/* Skip picked up items. */
/* Skip picked up items. */

if (hp->t == ITEM_NONE)
continue;
if (hp->t == ITEM_NONE)
continue;

/* Lazily update color. */

if (hp->t != type || hp->n != value)
{
float c[4];
/* Draw model. */

item_color(hp, c);

glColor4f(c[0], c[1], c[2], c[3]);

type = hp->t;
value = hp->n;
}

/* Draw model. */

glPushMatrix();
{
glTranslatef(hp->p[0],
hp->p[1],
hp->p[2]);
item_draw(rend, hp, bill_M, t);
}
glPopMatrix();
glPushMatrix();
{
glTranslatef(hp->p[0],
hp->p[1],
hp->p[2]);
item_draw(rend, hp, bill_M, t);
}
glPopMatrix();
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
sol_color_mtrl(rend, 0);
}

static void game_draw_beams(struct s_rend *rend, const struct game_draw *gd)
Expand Down Expand Up @@ -195,38 +173,25 @@ static void game_refl_all(struct s_rend *rend, const struct game_draw *gd)

static void game_draw_light(const struct game_draw *gd, int d, float t)
{
const float light_p[2][4] = {
{ -8.0f, +32.0f, -8.0f, 0.0f },
{ +8.0f, +32.0f, +8.0f, 0.0f },
};
const float light_c[3][4] = {
{ 1.0f, 0.8f, 0.8f, 1.0f },
{ 0.8f, 1.0f, 0.8f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
};

GLfloat p[4];

/* Configure the lighting. */

light_conf();

/* Overrride light 2 position. */

p[0] = cosf(t);
p[1] = 0.0f;
p[2] = sinf(t);
p[3] = 0.0f;

/* Configure the lighting. */
glLightfv(GL_LIGHT2, GL_POSITION, p);

glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_p[0]);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_c[0]);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_c[0]);
/* Enable scene lights. */

glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT1, GL_POSITION, light_p[1]);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_c[1]);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_c[1]);

glLightfv(GL_LIGHT2, GL_POSITION, p);
glLightfv(GL_LIGHT2, GL_DIFFUSE, light_c[2]);
glLightfv(GL_LIGHT2, GL_SPECULAR, light_c[2]);
}

static void game_draw_back(struct s_rend *rend,
Expand Down Expand Up @@ -378,8 +343,6 @@ static void game_draw_fore(struct s_rend *rend,

game_draw_beams(rend, gd);
part_draw_coin(rend);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
glEnable(GL_LIGHTING);

Expand Down Expand Up @@ -453,7 +416,7 @@ void game_draw(struct game_draw *gd, int pose, float t)
gd->draw.shadow_ui = 0;

game_shadow_conf(pose, 1);
sol_draw_enable(&rend);
r_draw_enable(&rend);

video_push_persp(fov, 0.1f, FAR_DIST);
glPushMatrix();
Expand Down Expand Up @@ -532,13 +495,13 @@ void game_draw(struct game_draw *gd, int pose, float t)

if (gd->draw.reflective && !config_get_d(CONFIG_REFLECTION))
{
sol_color_mtrl(&rend, 1);
r_color_mtrl(&rend, 1);
{
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
game_refl_all(&rend, gd);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
sol_color_mtrl(&rend, 0);
r_color_mtrl(&rend, 0);
}

/* Draw the mirrors and the rest of the foreground. */
Expand All @@ -553,7 +516,7 @@ void game_draw(struct game_draw *gd, int pose, float t)

sol_fade(&gd->draw, &rend, gd->fade_k);

sol_draw_disable(&rend);
r_draw_disable(&rend);
game_shadow_conf(pose, 0);
}
}
Expand Down
24 changes: 15 additions & 9 deletions ball/main.c
Expand Up @@ -33,6 +33,8 @@
#include "fs.h"
#include "common.h"
#include "text.h"
#include "mtrl.h"
#include "geom.h"

#include "st_conf.h"
#include "st_title.h"
Expand Down Expand Up @@ -72,13 +74,6 @@ static void toggle_wire(void)
#endif
}

static void toggle_lerp(void)
{
extern int enable_interpolation;

enable_interpolation = !enable_interpolation;
}

/*---------------------------------------------------------------------------*/

static int handle_key_dn(SDL_Event *e)
Expand Down Expand Up @@ -108,9 +103,12 @@ static int handle_key_dn(SDL_Event *e)
if (config_cheat())
toggle_wire();
break;
case KEY_LERP:
case KEY_RESOURCES:
if (config_cheat())
toggle_lerp();
{
light_load();
mtrl_reload();
}
break;
case SDLK_RETURN:
d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
Expand Down Expand Up @@ -502,6 +500,12 @@ int main(int argc, char *argv[])
if (!video_init())
return 1;

/* Material system. */

mtrl_init();

/* Screen states. */

init_state(&st_null);

/* Initialize demo playback or load the level. */
Expand Down Expand Up @@ -569,6 +573,8 @@ int main(int argc, char *argv[])

config_save();

mtrl_quit();

if (joy)
SDL_JoystickClose(joy);

Expand Down
2 changes: 2 additions & 0 deletions ball/st_conf.c
Expand Up @@ -216,12 +216,14 @@ static int null_enter(struct state *st, struct state *prev)
ball_free();
shad_free();
part_free();
mtrl_free_objects();

return 0;
}

static void null_leave(struct state *st, struct state *next, int id)
{
mtrl_load_objects();
part_init();
shad_init();
ball_init();
Expand Down
2 changes: 1 addition & 1 deletion data/ball/atom/electron
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/atom/neutron
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/atom/proton
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
4 changes: 2 additions & 2 deletions data/ball/basic-ball/basic-ball
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 20.0
flags transparent
angle 45.0
4 changes: 2 additions & 2 deletions data/ball/blinky/blinky
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 0.75
diffuse 0.8 0.8 0.8 0.75
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 60.0
flags transparent
angle 45.0
4 changes: 2 additions & 2 deletions data/ball/diagonal-ball/diagonal-ball
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 20.0
flags transparent
angle 45.0
2 changes: 1 addition & 1 deletion data/ball/earth/earth-cloud
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/earth/earth-ocean
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.8 0.8 0.8 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/eyeball/eyeball
@@ -1,7 +1,7 @@
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.5 0.5 0.5 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 128.0
flags semi-opaque
angle 5.0
2 changes: 1 addition & 1 deletion data/ball/lava/lava-glow
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/lava/lava-inner
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 1.0 1.0 1.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/lava/lava-solid
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.4 0.4 0.4 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
4 changes: 2 additions & 2 deletions data/ball/magic-eightball/magic-eightball
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 20.0
flags transparent
angle 45.0
4 changes: 2 additions & 2 deletions data/ball/melon/melon
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 128.0
flags
angle 45.0
4 changes: 2 additions & 2 deletions data/ball/orange/orange
@@ -1,7 +1,7 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.3 0.3 0.3 1.0
emissive 0.2 0.2 0.2 1.0
emissive 0.0 0.0 0.0 1.0
shininess 90.0
flags
angle 45.0
2 changes: 1 addition & 1 deletion data/ball/reactor/reactor-surface
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/reactor/sparkle1
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.0 0.0 0.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/rift/rift
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 0.3 0.3 0.3 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down
2 changes: 1 addition & 1 deletion data/ball/saturn/saturn-ring
@@ -1,4 +1,4 @@
diffuse 1.0 1.0 1.0 1.0
diffuse 0.8 0.8 0.8 1.0
ambient 0.2 0.2 0.2 1.0
specular 1.0 1.0 1.0 1.0
emissive 0.0 0.0 0.0 1.0
Expand Down

0 comments on commit 2963f71

Please sign in to comment.