Skip to content

Commit

Permalink
Added light decoration fading angle
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 30, 2003
1 parent d17b733 commit 55a1324
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions doomsday/Include/rend_decor.h
Expand Up @@ -9,6 +9,7 @@ extern float decorWallMaxDist; // No decorations are visible beyond this.
extern float decorPlaneMaxDist;
extern float decorWallFactor;
extern float decorPlaneFactor;
extern float decorFadeAngle;

void Rend_InitDecorationsForFrame(void);
void Rend_ProjectDecorations(void);
Expand Down
1 change: 1 addition & 0 deletions doomsday/Include/rend_dyn.h
Expand Up @@ -27,6 +27,7 @@ typedef struct lumobj_s // For dynamic lighting.
DGLuint floorTex, ceilTex; // Lightmaps for floor/ceil.
DGLuint decorMap; // Decoration lightmap.
char flareTex; // Zero = automatical.
float flareMul; // Flare brightness factor.
}
lumobj_t;

Expand Down
1 change: 1 addition & 0 deletions doomsday/Src/con_console.c
Expand Up @@ -308,6 +308,7 @@ cvar_t engineCVars[] =
"rend-light-decor-wall-far", CVF_NO_MAX, CVT_FLOAT, &decorWallMaxDist, 0, 0, "Maximum distance at which wall light decorations are visible.",
"rend-light-decor-plane-bright", 0, CVT_FLOAT, &decorPlaneFactor, 0, 10, "Brightness of plane light decorations.",
"rend-light-decor-wall-bright", 0, CVT_FLOAT, &decorWallFactor, 0, 10, "Brightness of wall light decorations.",
"rend-light-decor-angle", 0, CVT_FLOAT, &decorFadeAngle, 0, 1, "Reduce brightness if surface/view angle too steep.",
// * Render-Glow
"rend-glow", 0, CVT_INT, &r_texglow, 0, 1, "1=Enable glowing textures.",
"rend-glow-wall", 0, CVT_INT, &useWallGlow, 0, 1, "1=Render glow on walls.",
Expand Down
48 changes: 37 additions & 11 deletions doomsday/Src/rend_decor.c
Expand Up @@ -43,13 +43,17 @@ float decorWallMaxDist = 1500; // No decorations are visible beyond this.
float decorPlaneMaxDist = 1500;
float decorWallFactor = 1;
float decorPlaneFactor = 1;
float decorFadeAngle = .1f;

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static int numSources;
static int maxSources;
static decorsource_t *sourceFirst, *sourceLast, *sourceCursor;

// Lights near surfaces get dimmer if the angle is too small.
static float surfaceNormal[3];

// CODE --------------------------------------------------------------------

/*
Expand Down Expand Up @@ -155,7 +159,7 @@ void Rend_AddLightDecoration
decorsource_t *source;
lumobj_t *lum;
float distance = Rend_PointDist3D(pos);
float fadeMul = 1;
float fadeMul = 1, flareMul = 1;
float maxDist = (isWall? decorWallMaxDist : decorPlaneMaxDist);
int i;

Expand All @@ -171,6 +175,26 @@ void Rend_AddLightDecoration
// Apply the brightness factor (was calculated using sector lightlevel).
fadeMul *= brightness * (isWall? decorWallFactor : decorPlaneFactor);

// Brightness drops as the angle gets too big.
if(def->elevation < 2 && decorFadeAngle > 0) // Close the surface?
{
float vector[3] = { pos[VX] - vx, pos[VZ] - vy, pos[VY] - vz };
float dot;
M_Normalize(vector);
dot =
-(surfaceNormal[VX] * vector[VX]
+ surfaceNormal[VY] * vector[VY]
+ surfaceNormal[VZ] * vector[VZ]);
if(dot < decorFadeAngle/2)
{
flareMul = 0;
}
else if(dot < 3 * decorFadeAngle)
{
flareMul *= (dot - decorFadeAngle/2) / (2.5f * decorFadeAngle);
}
}

if(fadeMul <= 0) return;

if(!(source = Rend_NewLightDecorationSource()))
Expand Down Expand Up @@ -217,6 +241,7 @@ void Rend_AddLightDecoration

// Zero = Texture chosen automatically.
lum->flareTex = def->flare_texture;
lum->flareMul = flareMul;

for(i = 0; i < 3; i++)
lum->rgb[i] = (byte) (255 * def->color[i] * fadeMul);
Expand Down Expand Up @@ -290,7 +315,7 @@ void Rend_DecorateLineSection
ded_decorlight_t *lightDef;
vertex_t *v1, *v2;
float lh, s, t; // Horizontal and vertical offset.
float posBase[2], normal[2], delta[2], pos[3], brightMul;
float posBase[2], delta[2], pos[3], brightMul;
float surfTexW, surfTexH, patternW, patternH;
int i, skip[2];

Expand All @@ -311,10 +336,11 @@ void Rend_DecorateLineSection
v2 = line->v1;
}

delta[VX] = FIX2FLT(v2->x - v1->x);
delta[VY] = FIX2FLT(v2->y - v1->y);
normal[VX] = delta[VY] / linfo->length;
normal[VY] = -delta[VX] / linfo->length;
delta[VX] = FIX2FLT(v2->x - v1->x);
delta[VY] = FIX2FLT(v2->y - v1->y);
surfaceNormal[VX] = delta[VY] / linfo->length;
surfaceNormal[VZ] = -delta[VX] / linfo->length;
surfaceNormal[VY] = 0;

// Height of the section.
lh = top - bottom;
Expand All @@ -339,8 +365,8 @@ void Rend_DecorateLineSection
// Skip must be at least one.
Rend_DecorationPatternSkip(lightDef, skip);

posBase[VX] = FIX2FLT(v1->x) + lightDef->elevation * normal[VX];
posBase[VY] = FIX2FLT(v1->y) + lightDef->elevation * normal[VY];
posBase[VX] = FIX2FLT(v1->x) + lightDef->elevation * surfaceNormal[VX];
posBase[VY] = FIX2FLT(v1->y) + lightDef->elevation * surfaceNormal[VZ];

patternW = surfTexW * skip[VX];
patternH = surfTexH * skip[VY];
Expand Down Expand Up @@ -554,9 +580,9 @@ void Rend_DecoratePlane
float pos[3], tileSize = 64, brightMul;
int i, skip[2];

// Keep the offsets within one tileSize.
//offX = M_CycleIntoRange(offX, tileSize);
//offY = M_CycleIntoRange(offY, tileSize);
surfaceNormal[VX] = 0;
surfaceNormal[VY] = elevateDir;
surfaceNormal[VZ] = 0;

// Generate a number of lights.
for(i = 0; i < DED_DECOR_NUM_LIGHTS; i++)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/Src/rend_halo.c
Expand Up @@ -552,7 +552,7 @@ void H_RenderHalo(vissprite_t *sourcevis, boolean primary)
f = minHaloSize*lum->flareSize/lum_distance;
if(f > 1) f = 1;
}
f *= distancedim;
f *= distancedim * lum->flareMul;

// The color & alpha of the flare.
color[CA] = f * (fl->alpha * occlusionfactor * fadefactor
Expand Down

0 comments on commit 55a1324

Please sign in to comment.