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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// A class representing a light
//
//=============================================================================
#ifndef DMELIGHT_H
#define DMELIGHT_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmedag.h"
//-----------------------------------------------------------------------------
// Forward declaration
//-----------------------------------------------------------------------------
struct LightDesc_t;
//-----------------------------------------------------------------------------
// A base class for lights
//-----------------------------------------------------------------------------
class CDmeLight : public CDmeDag
{
DEFINE_ELEMENT( CDmeLight, CDmeDag );
public:
// Sets the color and intensity
// NOTE: Color is specified 0-255 floating point.
void SetColor( const Color &color );
void SetIntensity( float flIntensity );
// Sets up render state in the material system for rendering
virtual void SetupRenderState( int nLightIndex );
virtual bool GetLightDesc( LightDesc_t *pDesc ) { return false; }
protected:
// Sets up render state in the material system for rendering
void SetupRenderStateInternal( LightDesc_t &desc, float flAtten0, float flAtten1, float flAtten2 );
CDmaVar< Color > m_Color;
CDmaVar< float > m_flIntensity;
};
//-----------------------------------------------------------------------------
// A directional light
//-----------------------------------------------------------------------------
class CDmeDirectionalLight : public CDmeLight
{
DEFINE_ELEMENT( CDmeDirectionalLight, CDmeLight );
public:
void SetDirection( const Vector &direction );
const Vector &GetDirection() const { return m_Direction; }
// Sets up render state in the material system for rendering
virtual bool GetLightDesc( LightDesc_t *pDesc );
private:
CDmaVar<Vector> m_Direction;
};
//-----------------------------------------------------------------------------
// A point light
//-----------------------------------------------------------------------------
class CDmePointLight : public CDmeLight
{
DEFINE_ELEMENT( CDmePointLight, CDmeLight );
public:
void SetPosition( const Vector &pos ) { m_Position = pos; }
const Vector &GetPosition() const { return m_Position; }
// Sets the attenuation factors
void SetAttenuation( float flConstant, float flLinear, float flQuadratic );
// Sets the maximum range
void SetMaxDistance( float flMaxDistance );
// Sets up render state in the material system for rendering
virtual bool GetLightDesc( LightDesc_t *pDesc );
protected:
CDmaVar< Vector > m_Position;
CDmaVar< float > m_flAttenuation0;
CDmaVar< float > m_flAttenuation1;
CDmaVar< float > m_flAttenuation2;
CDmaVar< float > m_flMaxDistance;
};
//-----------------------------------------------------------------------------
// A spot light
//-----------------------------------------------------------------------------
class CDmeSpotLight : public CDmePointLight
{
DEFINE_ELEMENT( CDmeSpotLight, CDmePointLight );
public:
// Sets the spotlight direction
void SetDirection( const Vector &direction );
// Sets the spotlight angle factors
// Angles are specified in degrees, as full angles (as opposed to half-angles)
void SetAngles( float flInnerAngle, float flOuterAngle, float flAngularFalloff );
// Sets up render state in the material system for rendering
virtual bool GetLightDesc( LightDesc_t *pDesc );
private:
CDmaVar<Vector> m_Direction;
CDmaVar<float> m_flSpotInnerAngle;
CDmaVar<float> m_flSpotOuterAngle;
CDmaVar<float> m_flSpotAngularFalloff;
};
//-----------------------------------------------------------------------------
// An ambient light
//-----------------------------------------------------------------------------
class CDmeAmbientLight : public CDmeLight
{
DEFINE_ELEMENT( CDmeAmbientLight, CDmeLight );
public:
// Sets up render state in the material system for rendering
virtual void SetupRenderState( int nLightIndex );
};
#endif // DMELIGHT_H
|