Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renderer: Added a camera vignette effect
In a physical camera lens, less light is received from the edges of the image compared to the center, making the center appear brighter. This is called "vignetting" and it can be used to enhance the appearance of a frame by making it seem more natural and to subtly help focus the eye on the center of the frame. See: http://en.wikipedia.org/wiki/Vignetting The renderer now draws a simple vignette by default. It can be toggled on and off with "rend-vignette", and further configured with "rend-vignette-darkness" and "rend-vignette-width".
- Loading branch information
Showing
8 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @file vignette.h | ||
* Renders a vignette for the player view. @ingroup render | ||
* | ||
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <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, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#ifndef LIBDENG_RENDER_VIGNETTE_H | ||
#define LIBDENG_RENDER_VIGNETTE_H | ||
|
||
#include "rect.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Initializes the vignette rendering module. This includes registering console | ||
* commands. | ||
*/ | ||
void Vignette_Register(void); | ||
|
||
/** | ||
* Renders the vignette for the player's view. | ||
* | ||
* @param viewRect View window where to draw the vignette. | ||
* @param fov Current horizontal FOV angle (degrees). | ||
*/ | ||
void Vignette_Render(const RectRaw* viewRect, float fov); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // LIBDENG_RENDER_VIGNETTE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @file vignette.c | ||
* Renders a vignette for the player view. @ingroup render | ||
* | ||
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <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, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#include "de_base.h" | ||
#include "de_console.h" | ||
#include "de_graphics.h" | ||
#include "m_vector.h" | ||
#include <math.h> | ||
|
||
static byte vignetteEnabled = true; | ||
static float vignetteDarkness = 1.0f; | ||
static float vignetteWidth = 1.0f; | ||
|
||
void Vignette_Register(void) | ||
{ | ||
C_VAR_BYTE ("rend-vignette", &vignetteEnabled, 0, 0, 1); | ||
C_VAR_FLOAT("rend-vignette-darkness", &vignetteDarkness, CVF_NO_MAX, 0, 0); | ||
C_VAR_FLOAT("rend-vignette-width", &vignetteWidth, 0, 0, 2); | ||
} | ||
|
||
void Vignette_Render(const RectRaw* viewRect, float fov) | ||
{ | ||
const int DIVS = 60; | ||
vec2f_t vec; | ||
float cx, cy, outer, inner; | ||
float alpha; | ||
int i; | ||
|
||
if(!vignetteEnabled) return; | ||
|
||
// Center point. | ||
cx = viewRect->origin.x + viewRect->size.width/2; | ||
cy = viewRect->origin.y + viewRect->size.height/2; | ||
|
||
// Radius. | ||
V2f_Set(vec, viewRect->size.width/2, viewRect->size.height/2); | ||
outer = V2f_Length(vec) + 1; // Extra pixel to account for a possible gap. | ||
if(fov < 100) | ||
{ | ||
// Small FOV angles cause the vignette to be thinner/lighter. | ||
outer *= (1 + 100.f/fov) / 2; | ||
} | ||
inner = outer * vignetteWidth * .4f; | ||
if(fov > 100) | ||
{ | ||
// High FOV angles cause the vignette to be wider. | ||
inner *= 100.f/fov; | ||
} | ||
|
||
alpha = vignetteDarkness * .5f; | ||
if(fov > 100) | ||
{ | ||
// High FOV angles cause the vignette to be darker. | ||
alpha *= fov/100.f; | ||
} | ||
|
||
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_CAMERA_VIGNETTE), GL_LINEAR); | ||
glEnable(GL_TEXTURE_2D); | ||
|
||
glBegin(GL_TRIANGLE_STRIP); | ||
for(i = 0; i <= DIVS; ++i) | ||
{ | ||
float ang = (float)(2 * PI * i) / (float)DIVS; | ||
float dx = cos(ang); | ||
float dy = sin(ang); | ||
|
||
glColor4f(0, 0, 0, alpha); | ||
glTexCoord2f(0, 1); | ||
glVertex2f(cx + outer * dx, cy + outer * dy); | ||
|
||
glColor4f(0, 0, 0, 0); | ||
glTexCoord2f(0, 0); | ||
glVertex2f(cx + inner * dx, cy + inner * dy); | ||
} | ||
glEnd(); | ||
|
||
glDisable(GL_TEXTURE_2D); | ||
} |