1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef _SKY_LIGHT_H_
#define _SKY_LIGHT_H_
#include "System/float3.h"
#include "System/float4.h"
#include "System/Matrix44f.h"
struct ISkyLight {
public:
virtual ~ISkyLight() {}
virtual void Update() {}
virtual bool SetLightDir(const float4& newDir) { return false; }
virtual bool IsDynamic() const = 0;
const float4& GetLightDir() const { return lightDir; }
const float GetLightIntensity() const { return lightIntensity; }
const float GetUnitShadowDensity() const { return unitShadowDensity; }
const float GetGroundShadowDensity() const { return groundShadowDensity; }
protected:
/**
* @brief current sunlight direction
*/
float4 lightDir;
/**
* @brief sunlight intensity scale (in [0, 1])
*/
float lightIntensity;
/**
* @brief elevation-adjusted unit shadow density
*/
float unitShadowDensity;
/**
* @brief elevation-adjusted ground shadow density
*/
float groundShadowDensity;
};
struct StaticSkyLight: public ISkyLight {
public:
StaticSkyLight();
bool IsDynamic() const { return false; }
};
struct DynamicSkyLight: public ISkyLight {
public:
DynamicSkyLight();
bool IsDynamic() const { return true; }
void Update();
bool SetLightDir(const float4& newDir);
void SetLightParams(float4 newDir, float startAngle, float orbitTime);
void SetLuaControl(bool b) { luaControl = b; }
bool GetLuaControl() const { return luaControl; }
private:
inline float4 CalculateSunPos(const float startAngle) const;
bool luaControl;
bool updateNeeded;
/**
* @brief the sun normally starts where its peak elevation occurs, unless this offset angle is set
*/
float sunStartAngle;
/**
* @brief the initial sun angle (around y-axis)
*/
float initialSunAngle;
/**
* @brief the distance of sun orbit center from origin
*/
float sunOrbitHeight;
/**
* @brief the radius of the sun orbit
*/
float sunOrbitRad;
/**
* @brief the time in seconds for the sun to complete the orbit
*/
float sunOrbitTime;
/**
* @brief density factor to provide darker shadows at low sun altitude
*/
float shadowDensityFactor;
/**
* @brief the lowest sun elevation for an automatically generated orbit
*/
float orbitMinSunHeight;
/**
* @brief matrix that rotates the sun orbit
*/
CMatrix44f sunRotation;
};
#endif
|