Skip to content

Commit

Permalink
Light Decorations: Parse light decoration stages from Material defs
Browse files Browse the repository at this point in the history
At present only the first stage is the animation used. The next step
is to extend MaterialVariant and MaterialSnapshot to animate and
capture/interpolate light decoration states respectively.
  • Loading branch information
danij-deng committed Jan 13, 2013
1 parent 39a40b2 commit 6378c03
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 383 deletions.
14 changes: 10 additions & 4 deletions doomsday/engine/include/def_data.h
Expand Up @@ -420,18 +420,23 @@ typedef struct ded_ptcgen_s {
ded_count_t stageCount;
} ded_ptcgen_t;

typedef struct ded_decorlight_s {
typedef struct ded_decorlight_stage_s {
float pos[2]; // Coordinates on the surface.
float elevation; // Distance from the surface.
float color[3]; // Light color.
float radius; // Dynamic light radius (-1 = no light).
float haloRadius; // Halo radius (zero = no halo).
int patternOffset[2];
int patternSkip[2];
float lightLevels[2]; // Fade by sector lightlevel.
int flareTexture;
Uri* up, *down, *sides;
Uri* flare; // Overrides flare_texture
} ded_decorlight_stage_t;

typedef struct ded_decorlight_s {
int patternOffset[2];
int patternSkip[2];
ded_decorlight_stage_t *stages;
ded_count_t stageCount;
} ded_decorlight_t;

// There is a fixed number of light decorations in each decoration.
Expand Down Expand Up @@ -644,7 +649,7 @@ int DED_AddState(ded_t* ded, char const* id);
int DED_AddSprite(ded_t* ded, char const* name);
int DED_AddLight(ded_t* ded, char const* stateID);
int DED_AddMaterial(ded_t* ded, char const* uri);
int DED_AddMaterialLayerStage(ded_material_layer_t* ml);
int DED_AddMaterialLayerStage(ded_material_layer_t *ml);
int DED_AddModel(ded_t* ded, char const* spr);
int DED_AddSky(ded_t* ded, char const* id);
int DED_AddSound(ded_t* ded, char const* id);
Expand All @@ -658,6 +663,7 @@ int DED_AddPtcGen(ded_t* ded, char const* state);
int DED_AddPtcGenStage(ded_ptcgen_t* gen);
int DED_AddFinale(ded_t* ded);
int DED_AddDecoration(ded_t* ded);
int DED_AddDecorLightStage(ded_decorlight_t *li);
int DED_AddReflection(ded_t* ded);
int DED_AddGroup(ded_t* ded);
int DED_AddGroupMember(ded_group_t* grp);
Expand Down
72 changes: 40 additions & 32 deletions doomsday/engine/include/render/rend_decor.h
@@ -1,50 +1,58 @@
/**\file rend_decor.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
/** @file rend_decor.h Surface Decoration Projection.
*
*\author Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

/**
* Surface Decorations.
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG_RENDER_DECOR_H
#define LIBDENG_RENDER_DECOR_H

#include <de/libdeng1.h>

DENG_EXTERN_C byte useLightDecorations;
DENG_EXTERN_C float decorMaxDist; ///< No decorations are visible beyond this.
DENG_EXTERN_C float decorLightBrightFactor;
DENG_EXTERN_C float decorLightFadeAngle;

#ifdef __cplusplus
extern "C" {
#endif

extern byte useLightDecorations;
extern float decorMaxDist; // No decorations are visible beyond this.
extern float decorLightBrightFactor;
extern float decorLightFadeAngle;
void Rend_DecorRegister(void);

void Rend_DecorRegister(void);
/**
* Re-initialize the decoration source tracking (might be called during a map
* load or othersuch situation).
*/
void Rend_DecorInit(void);

void Rend_DecorInit(void);
/**
* Decorations are generated for each frame.
*/
void Rend_InitDecorationsForFrame(void);

void Rend_InitDecorationsForFrame(void);
void Rend_AddLuminousDecorations(void);
void Rend_ProjectDecorations(void);
/**
* Create lumobjs for all decorations who want them.
*/
void Rend_AddLuminousDecorations(void);

/**
* Project all the non-clipped decorations. They become regular vissprites.
*/
void Rend_ProjectDecorations(void);

#ifdef __cplusplus
} // extern "C"
Expand Down
35 changes: 34 additions & 1 deletion doomsday/engine/include/resource/material.h
Expand Up @@ -74,6 +74,8 @@ class Material

struct Decoration
{
ded_decorlight_t *def;
/*
float pos[2]; // Coordinates in material space.
float elevation; // Distance from the surface.
float color[3]; // Light color.
Expand All @@ -85,6 +87,37 @@ class Material
int flareTexture;
de::Uri up, down, sides;
de::Uri flare; // Overrides flare_texture
*/

Decoration(ded_decorlight_t &_def) : def(&_def)
{
/*
std::memcpy(decor->pos, def->pos, sizeof(decor->pos));
decor->elevation = def->elevation;
std::memcpy(decor->color, def->color, sizeof(decor->color));
decor->radius = def->radius;
decor->haloRadius = def->haloRadius;
std::memcpy(decor->patternOffset, def->patternOffset, sizeof(decor->patternOffset));
std::memcpy(decor->patternSkip, def->patternSkip, sizeof(decor->patternSkip));
std::memcpy(decor->lightLevels, def->lightLevels, sizeof(decor->lightLevels));
decor->flareTexture = def->flareTexture;
if(def->up)
{
decor->up = *reinterpret_cast<de::Uri const *>(def->up);
}
if(def->down)
{
decor->down = *reinterpret_cast<de::Uri const *>(def->down);
}
if(def->sides)
{
decor->sides = *reinterpret_cast<de::Uri const *>(def->sides);
}
if(def->flare)
{
decor->flare = *reinterpret_cast<de::Uri const *>(def->flare);
}*/
}
};

/// A list of decorations.
Expand Down Expand Up @@ -113,7 +146,7 @@ material_t *Material_New(short flags, ded_material_t *def, Size2Raw *dimensions,

void Material_Delete(material_t *mat);

void Material_AddDecoration(material_t *mat, ded_decorlight_t const *def);
void Material_AddDecoration(material_t *mat, ded_decorlight_t *def);

int Material_DecorationCount(material_t const *mat);

Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -1123,6 +1123,8 @@ static int DD_ActivateGameWorker(void* parameters)
R_InitCompositeTextures();
R_InitFlatTextures();
R_InitSpriteTextures();
App_Textures()->scheme("Lightmaps").clear();
App_Textures()->scheme("Flaremaps").clear();

if(p->initiatedBusyMode)
Con_SetProgress(50);
Expand Down Expand Up @@ -1967,6 +1969,8 @@ boolean DD_Init(void)
R_InitCompositeTextures();
R_InitFlatTextures();
R_InitSpriteTextures();
App_Textures()->scheme("Lightmaps").clear();
App_Textures()->scheme("Flaremaps").clear();

Def_Read();

Expand Down
75 changes: 41 additions & 34 deletions doomsday/engine/src/def_data.c
Expand Up @@ -257,26 +257,30 @@ void DED_Clear(ded_t* ded)
for(i = 0; i < ded->count.materials.num; ++i)
{
ded_material_t* mat = &ded->materials[i];

if(mat->uri) Uri_Delete(mat->uri);

for(j = 0; j < DED_MAX_MATERIAL_LAYERS; ++j)
{
for(k = 0; k < mat->layers[j].stageCount.num; ++k)
ded_material_layer_t *layer = &mat->layers[j];
for(k = 0; k < layer->stageCount.num; ++k)
{
if(mat->layers[j].stages[k].texture) Uri_Delete(mat->layers[j].stages[k].texture);
if(layer->stages[k].texture) Uri_Delete(layer->stages[k].texture);
}
M_Free(mat->layers[j].stages);
M_Free(layer->stages);
}

for(j = 0; j < DED_DECOR_NUM_LIGHTS; ++j)
{
ded_decorlight_t* li = &mat->lights[j];

if(li->up) Uri_Delete(li->up);
if(li->down) Uri_Delete(li->down);
if(li->sides) Uri_Delete(li->sides);
if(li->flare) Uri_Delete(li->flare);
ded_decorlight_t *light = &mat->lights[j];
for(k = 0; k < light->stageCount.num; ++k)
{
ded_decorlight_stage_t *stage = &light->stages[k];
if(stage->up) Uri_Delete(stage->up);
if(stage->down) Uri_Delete(stage->down);
if(stage->sides) Uri_Delete(stage->sides);
if(stage->flare) Uri_Delete(stage->flare);
}
M_Free(light->stages);
}
}
M_Free(ded->materials);
Expand Down Expand Up @@ -343,21 +347,25 @@ void DED_Clear(ded_t* ded)

if(ded->decorations)
{
int i, j;
int i, j, k;
for(i = 0; i < ded->count.decorations.num; ++i)
{
ded_decor_t* dec = &ded->decorations[i];
ded_decor_t *dec = &ded->decorations[i];

if(dec->material) Uri_Delete(dec->material);

for(j = 0; j < DED_DECOR_NUM_LIGHTS; ++j)
{
ded_decorlight_t* li = &dec->lights[j];

if(li->up) Uri_Delete(li->up);
if(li->down) Uri_Delete(li->down);
if(li->sides) Uri_Delete(li->sides);
if(li->flare) Uri_Delete(li->flare);
ded_decorlight_t *light = &dec->lights[j];
for(k = 0; k < light->stageCount.num; ++k)
{
ded_decorlight_stage_t *stage = &light->stages[k];
if(stage->up) Uri_Delete(stage->up);
if(stage->down) Uri_Delete(stage->down);
if(stage->sides) Uri_Delete(stage->sides);
if(stage->flare) Uri_Delete(stage->flare);
}
M_Free(light->stages);
}
}
M_Free(ded->decorations);
Expand Down Expand Up @@ -574,22 +582,12 @@ int DED_AddMaterial(ded_t* ded, char const* uri)
{
ded_material_t* mat = DED_NewEntry((void**) &ded->materials, &ded->count.materials, sizeof(ded_material_t));
if(uri) mat->uri = Uri_NewWithPath2(uri, RC_NULL);

// Init some default values.
{ int i;
for(i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
{
// The color (0,0,0) means the light is not active.
mat->lights[i].elevation = 1;
mat->lights[i].radius = 1;
}}

return mat - ded->materials;
}

int DED_AddMaterialLayerStage(ded_material_layer_t* ml)
int DED_AddMaterialLayerStage(ded_material_layer_t *ml)
{
ded_material_layer_stage_t* stage = DED_NewEntry((void**) &ml->stages, &ml->stageCount, sizeof(*stage));
ded_material_layer_stage_t *stage = DED_NewEntry((void**) &ml->stages, &ml->stageCount, sizeof(*stage));
return stage - ml->stages;
}

Expand Down Expand Up @@ -805,12 +803,10 @@ int DED_AddDecoration(ded_t* ded)
ded_decor_t* decor = DED_NewEntry((void**) &ded->decorations, &ded->count.decorations, sizeof(ded_decor_t));
int i;

// Init some default values.
// Each decorlight supports only one stage.
for(i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
{
// The color (0,0,0) means the light is not active.
decor->lights[i].elevation = 1;
decor->lights[i].radius = 1;
DED_AddDecorLightStage(&decor->lights[i]);
}

return decor - ded->decorations;
Expand All @@ -821,6 +817,17 @@ void DED_RemoveDecoration(ded_t* ded, int index)
DED_DelEntry(index, (void**) &ded->decorations, &ded->count.decorations, sizeof(ded_decor_t));
}

int DED_AddDecorLightStage(ded_decorlight_t *li)
{
ded_decorlight_stage_t *stage = DED_NewEntry((void**) &li->stages, &li->stageCount, sizeof(*stage));

// The color (0,0,0) means the light is not active.
stage->elevation = 1;
stage->radius = 1;

return stage - li->stages;
}

int DED_AddReflection(ded_t* ded)
{
ded_reflection_t* ref = DED_NewEntry((void**) &ded->reflections, &ded->count.reflections, sizeof(ded_reflection_t));
Expand Down

0 comments on commit 6378c03

Please sign in to comment.