2015-02-16 17:36:18 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2014-2016, The OpenClonk Team and contributors
|
2015-02-16 17:36:18 +00:00
|
|
|
*
|
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
|
|
|
*
|
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
|
|
|
*/
|
2014-10-11 21:13:10 +00:00
|
|
|
#ifndef C4FOWLIGHT_H
|
|
|
|
#define C4FOWLIGHT_H
|
|
|
|
|
2016-10-22 11:19:22 +00:00
|
|
|
#include "C4ForbidLibraryCompilation.h"
|
|
|
|
|
2015-06-17 19:30:56 +00:00
|
|
|
#ifndef USE_CONSOLE
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "object/C4Object.h"
|
|
|
|
#include "graphics/C4Surface.h"
|
|
|
|
#include "graphics/C4FacetEx.h"
|
|
|
|
#include "landscape/fow/C4FoWLightSection.h"
|
|
|
|
#include "landscape/fow/C4FoWDrawStrategy.h"
|
|
|
|
#include "lib/C4Rect.h"
|
2014-10-11 21:13:10 +00:00
|
|
|
|
2014-11-17 22:01:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
/** This class represents one light source. A light source has an associated object with which the light source moves
|
2014-10-12 10:59:25 +00:00
|
|
|
and one light section that handles the light beams for each direction (up, down, left, right).
|
2014-10-11 21:13:10 +00:00
|
|
|
|
2015-01-02 00:06:00 +00:00
|
|
|
Furthermore, each light source has a size. This is usually the object's lightRange. See SetReach.
|
2014-10-11 21:13:10 +00:00
|
|
|
*/
|
|
|
|
class C4FoWLight
|
|
|
|
{
|
|
|
|
friend class C4FoW;
|
|
|
|
public:
|
|
|
|
C4FoWLight(C4Object *pObj);
|
|
|
|
~C4FoWLight();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t iX, iY; // center position
|
2014-10-12 10:59:25 +00:00
|
|
|
int32_t iReach; // maximum length of beams
|
|
|
|
int32_t iFadeout; // number of pixels over which beams fade out
|
2014-10-11 21:13:10 +00:00
|
|
|
int32_t iSize; // size of the light source. Decides smoothness of shadows
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
float gBright; // brightness of the light source. 1.0 is maximum.
|
|
|
|
float colorR; // red color component of the light source. 1.0 is maximum.
|
|
|
|
float colorG; // green color component of the light source. 1.0 is maximum.
|
|
|
|
float colorB; // blue color component of the light source. 1.0 is maximum.
|
|
|
|
float colorV; // color value. 1.0 is maximum.
|
|
|
|
float colorL; // color lightness. 1.0 is maximum.
|
2014-10-11 21:13:10 +00:00
|
|
|
C4FoWLight *pNext;
|
|
|
|
C4Object *pObj; // Associated object
|
|
|
|
|
2014-11-17 22:01:12 +00:00
|
|
|
std::vector<C4FoWLightSection*> sections;
|
2014-11-16 17:57:42 +00:00
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
public:
|
|
|
|
int32_t getX() const { return iX; }
|
|
|
|
int32_t getY() const { return iY; }
|
|
|
|
int32_t getReach() const { return iReach; }
|
|
|
|
int32_t getFadeout() const { return iFadeout; }
|
|
|
|
int32_t getTotalReach() const { return iReach + iFadeout; }
|
|
|
|
int32_t getSize() const { return iSize; }
|
2014-11-21 14:32:33 +00:00
|
|
|
int32_t getNormalSize() const { return iSize * 2; }
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
float getBrightness() const { return colorV * gBright; }
|
|
|
|
float getR() const { return colorR; }
|
|
|
|
float getG() const { return colorG; }
|
|
|
|
float getB() const { return colorB; }
|
|
|
|
float getValue() const { return colorV; }
|
|
|
|
float getLightness() const { return colorL; }
|
2014-10-11 21:13:10 +00:00
|
|
|
C4FoWLight *getNext() const { return pNext; }
|
|
|
|
C4Object *getObj() const { return pObj; }
|
|
|
|
|
|
|
|
/** Sets the light's size in pixels. The reach is the total radius of the light while the fadeout is the number of
|
|
|
|
pixels after which the light should dim down */
|
|
|
|
void SetReach(int32_t iReach, int32_t iFadeout);
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
|
|
|
|
/** Sets the light's color in rgba format. */
|
|
|
|
void SetColor(uint32_t iValue);
|
2014-10-11 21:13:10 +00:00
|
|
|
|
2014-10-12 10:59:25 +00:00
|
|
|
/** Triggers the recalculation of all light beams within the given rectangle for this light because the landscape changed. */
|
2014-10-11 21:13:10 +00:00
|
|
|
void Invalidate(C4Rect r);
|
2014-10-12 10:59:25 +00:00
|
|
|
/** Update all light beams within the given rectangle for this light */
|
2014-10-11 21:13:10 +00:00
|
|
|
void Update(C4Rect r);
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Render this light*/
|
2016-01-02 05:18:15 +00:00
|
|
|
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall& call);
|
2014-10-11 21:13:10 +00:00
|
|
|
|
2015-01-02 00:42:09 +00:00
|
|
|
bool IsVisibleForPlayer(C4Player *player) const; // check if attached to an object that is not hostile to the given player
|
|
|
|
|
2014-11-16 17:57:42 +00:00
|
|
|
private:
|
2014-11-21 14:32:33 +00:00
|
|
|
typedef std::list<class C4FoWBeamTriangle> TriangleList;
|
|
|
|
|
|
|
|
/** Calculate "normal" fan points - where the normal hasn't maxed out yet */
|
2014-11-23 17:39:24 +00:00
|
|
|
void CalculateFanMaxed(TriangleList &triangles) const;
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Calculate the intermediate fade points used for constructing the intermediate fade triangles later on */
|
2014-11-23 17:06:10 +00:00
|
|
|
void CalculateIntermediateFadeTriangles(TriangleList &triangles) const;
|
2014-11-16 17:57:42 +00:00
|
|
|
|
2014-11-23 16:44:40 +00:00
|
|
|
void ProjectPointOutward(float &x, float &y, float maxDistance) const;
|
|
|
|
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Draws the triangle fan (the area with 100% light around the light source) with the given strategy */
|
2014-11-23 17:06:10 +00:00
|
|
|
void DrawFan(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
|
2014-11-21 14:32:33 +00:00
|
|
|
/** Draws the triangle fan (100% light, maxed out normals) with the given strategy */
|
2014-11-23 17:06:10 +00:00
|
|
|
void DrawFanMaxed(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Draws the fadeoot triangles - those around the triangle fan - with the given strategy */
|
2014-11-23 17:06:10 +00:00
|
|
|
void DrawFade(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Draws the fadeout triangles in between the normal fadeout triangles with the given strategy */
|
2014-11-23 17:06:10 +00:00
|
|
|
void DrawIntermediateFadeTriangles(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Returns the (squared) distance from this light source to the given point. Squared simply because we only need this
|
|
|
|
for comparison of distances. So we don't bother to sqrt it */
|
2014-11-23 16:40:24 +00:00
|
|
|
float GetSquaredDistanceTo(int32_t x, int32_t y) const { return (x - getX()) * (x - getX()) + (y - getY()) * (y - getY()); }
|
2014-11-16 17:57:42 +00:00
|
|
|
|
2016-01-02 02:39:16 +00:00
|
|
|
/* Draw strategy instances. We keep them around once created, so they can
|
|
|
|
* reuse a VBO between individual renderings. */
|
|
|
|
std::unique_ptr<C4FoWDrawStrategy> OnScreenStrategy;
|
|
|
|
std::unique_ptr<C4FoWDrawStrategy> OffScreenStrategy;
|
2014-10-11 21:13:10 +00:00
|
|
|
};
|
|
|
|
|
2015-06-17 19:30:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|