Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 268 vs 272 for /trunk/Source Code/Rendering/Lighting/Headers/Light.h

Diff revisions: vs.
  @@ -31,44 +31,32 @@
31 31 LIGHT_TYPE_DIRECTIONAL = 0,
32 32 LIGHT_TYPE_POINT = 1, ///< or omni light, if you prefer
33 33 LIGHT_TYPE_SPOT = 2,
34 - LIGHT_TYPE_PLACEHOLDER
34 + LightType_PLACEHOLDER
35 35 };
36 36
37 37 enum LightMode{
38 38 LIGHT_MODE_SIMPLE = 0, ///< normal light. Can't be moved or changed at runtime
39 39 LIGHT_MODE_TOGGLABLE = 1, ///< can be switched on or off and can change brightness,color, range at runtime
40 40 LIGHT_MODE_MOVABLE = 2, ///< can change position at runtime / most expensive
41 - LIGHT_MODE_DOMINANT = 3 ///< only shadow caster in scene
41 + //LIGHT_MODE_DOMINANT = 3 ///< only shadow caster in scene
42 42 };
43 43
44 - ///Defines all light properties that are stores as a 3 or 4 component vector
45 - enum LightPropertiesV{
46 - LIGHT_PROPERTY_DIFFUSE,
47 - LIGHT_PROPERTY_SPECULAR,
48 - };
49 - ///Defines all light properties that are stored as a floating point value
50 - enum LightPropertiesF{
51 - LIGHT_PROPERTY_SPOT_EXPONENT,
52 - LIGHT_PROPERTY_SPOT_CUTOFF,
53 - LIGHT_PROPERTY_CONST_ATT,
54 - LIGHT_PROPERTY_LIN_ATT,
55 - LIGHT_PROPERTY_QUAD_ATT,
56 - LIGHT_PROPERTY_BRIGHTNESS,
57 - LIGHT_PROPERTY_AMBIENT
44 + struct LightVisualProperties {
45 + vec4<F32> _diffuse; //< rgb = diffuse, w = ambientFactor;
46 + vec3<F32> _specular; //< rgb = specular color
58 47 };
59 48
60 - struct LightProperties {
61 - vec4<F32> _attenuation; //< x = constAtt, y = linearAtt, z = quadraticAtt, w = spotCutoff
49 + struct LightPhysicalProperties {
50 + vec4<F32> _attenuation; //< x = constAtt, y = linearAtt, z = quadraticAtt, w = brightness
62 51 vec4<F32> _position; //< Position is a direction for directional lights. w-light type: 0.0 - directional, 1.0 - point, 2.0 - spot
63 52 vec4<F32> _direction; //< xyz = Used by spot lights, w = spotExponent
64 - vec4<F32> _diffuse; //< rgb = diffuse, w = ambientFactor;
65 - vec4<F32> _specular; //< rgb = specular color, w = brightness
53 + F32 _spotCutoff;
66 54 };
67 55
68 56 struct LightShadowProperties {
69 57 mat4<F32> _lightVP[4]; //< light viewProjection matrices
70 58 vec4<F32> _floatValues; //< random float values (e.g. split distances)
71 - vec3<F32> _lightPosition[4]; //<light's position in world space
59 + vec4<F32> _lightPosition[4]; //<light's position in world space
72 60 };
73 61
74 62 class Camera;
  @@ -79,6 +67,15 @@
79 67 ///A light object placed in the scene at a certain position
80 68 class Light : public SceneNode {
81 69 public:
70 + enum PropertyType{
71 + PROPERTY_TYPE_VISUAL = 0,
72 + PROPERTY_TYPE_PHYSICAL = 1,
73 + PROPERTY_TYPE_SHADOW = 2,
74 + PropertyType_PLACEHOLDER = 3
75 + };
76 +
77 + typedef Unordered_map<I64, Light*> LightMap;
78 +
82 79 ///Create a new light assigned to the specified slot with the specified range
83 80 /// @param slot = the slot the light is assigned to (as in OpenGL slot for example)
84 81 /// @param range = the light influence range (for spot/point lights)
  @@ -88,47 +85,39 @@
88 85 ///Light score determines the importance of this light for the current node queries
89 86 inline F32 getScore() const {return _score;}
90 87 inline void setScore(const F32 score) {_score = score;}
91 - ///Set all light vector-properties
92 - virtual void setLightProperties(const LightPropertiesV& propName, const vec3<F32>& value);
93 - ///Set all light float-properties
94 - virtual void setLightProperties(const LightPropertiesF& propName, F32 value);
95 - ///Get light vector properties
96 - virtual vec3<F32> getVProperty(const LightPropertiesV& key) const;
97 - ///Get light floating point properties
98 - virtual F32 getFProperty(const LightPropertiesF& key) const;
99 - ///Get light ID
100 - inline U32 getId() const {return _id;}
88 +
101 89 ///Get light slot
102 90 inline U8 getSlot() const {return _slot;}
103 91 ///Is the light a shadow caster?
104 92 inline bool castsShadows() const {return _castsShadows;}
105 93 ///Get the entire property block
106 - inline const LightProperties& getProperties() const {return _properties;}
94 + inline const LightPhysicalProperties& getPhysicalProperties() const { return _physicalProperties; }
95 + inline const LightVisualProperties& getVisualProperties() const { return _visualProperties; }
107 96 inline const LightShadowProperties& getShadowProperties() const {return _shadowProperties;}
97 + inline F32 getRange() const {return _physicalProperties._attenuation.w;}
98 + void setRange(F32 range);
108 99 ///Get light diffuse color
109 - inline vec3<F32> getDiffuseColor() const {return _properties._diffuse.rgb();}
100 + inline vec3<F32> getDiffuseColor() const { return _visualProperties._diffuse.rgb(); }
101 + void setDiffuseColor(const vec3<F32>& newDiffuseColor);
102 + ///Get light specular color
103 + inline vec3<F32> getSpecularColor() const { return _visualProperties._specular; }
104 + void setSpecularColor(const vec3<F32>& newSpecularColor);
110 105 ///Get light position for omni and spot or direction for a directional light
111 - inline vec3<F32> getPosition() const {return _properties._position.xyz();}
106 + inline vec3<F32> getPosition() const { return _physicalProperties._position.xyz(); }
112 107 void setPosition(const vec3<F32>& newPosition);
113 108 ///Get direction for spot lights
114 - inline vec3<F32> getDirection() const {return _properties._direction.xyz();}
109 + inline vec3<F32> getDirection() const { return _physicalProperties._direction.xyz(); }
115 110 void setDirection(const vec3<F32>& newDirection);
116 111 ///Light state (on/off)
117 112 inline bool getEnabled() const {return _enabled;}
118 113
119 - ///Set a new light ID.
120 - ///The light ID is not the slot! It is used simply to identify the lights uniquely
121 - inline void setId(const U32 id) {_id = id; _dirty = true;}
122 - ///Set the light slot.
123 - ///Slot is used by the rendering API internally
124 - inline void setSlot(const U8 slot) {_slot = slot; _dirty = true;}
125 114 ///Does this list cast shadows?
126 115 inline void setCastShadows(const bool state) {_castsShadows = state;}
127 116 ///Draw a sphere at the lights position
128 117 ///The impostor has the range of the light's effect range and the diffuse color as the light's diffuse property
129 118 inline void setDrawImpostor(const bool state) {_drawImpostor = state;}
130 119 ///Turn the light on/off
131 - inline void setEnabled(const bool state) {_enabled = state; _dirty = true;}
120 + inline void setEnabled(const bool state) {_enabled = state;}
132 121 ///Get the light type.
133 122 ///See LightType enum
134 123 inline const LightType& getLightType() const {return _type;}
  @@ -136,7 +125,7 @@
136 125 ///Get a pointer to the light's impostor
137 126 inline Impostor* const getImpostor() const {return _impostor;}
138 127 //Checks if this light needs and update
139 - void updateState(const bool force = false);
128 + void onCameraChange();
140 129
141 130 ///Dummy function from SceneNode;
142 131 bool onDraw(SceneGraphNode* const sgn, const RenderStage& currentStage) { return true; }
  @@ -156,10 +145,10 @@
156 145 virtual void generateShadowMaps(SceneRenderState& sceneRenderState);
157 146 inline const mat4<F32>& getShadowVPMatrix(U8 index) const { return _shadowProperties._lightVP[index]; }
158 147 inline const vec4<F32>& getShadowFloatValues() const { return _shadowProperties._floatValues; }
159 - inline const vec3<F32>& getShadowLightPos(U8 index) const { return _shadowProperties._lightPosition[index]; }
148 + inline const vec4<F32>& getShadowLightPos(U8 index) const { return _shadowProperties._lightPosition[index]; }
160 149 inline void setShadowVPMatrix(U8 index, const mat4<F32>& newValue) { _shadowProperties._lightVP[index].set(newValue); }
161 150 inline void setShadowFloatValue(U8 index, F32 newValue) { _shadowProperties._floatValues[index] = newValue; }
162 - inline void setShadowLightPos(U8 index, const vec3<F32>& newValue) { _shadowProperties._lightPosition[index].set(newValue); }
151 + inline void setShadowLightPos(U8 index, const vec3<F32>& newValue) { _shadowProperties._lightPosition[index].set(newValue, 1.0f); }
163 152 inline void shadowMapResolutionFactor(U8 factor) {_resolutionFactor = factor;}
164 153 inline U8 shadowMapResolutionFactor() const {return _resolutionFactor;}
165 154
  @@ -181,22 +170,20 @@
181 170 ///Called when the rendering resolution changes
182 171 void updateResolution(I32 newWidth, I32 newHeight);
183 172 ///Get a ref to the shadow camera used by this light
184 - Camera* const shadowCamera() const {return _shadowCamera;}
185 -
186 - private:
187 - ///Enum to char* translation for vector properties
188 - const char* LightEnum(const LightPropertiesV& key) const;
189 - ///Enum to char* translation for floating point properties
190 - const char* LightEnum(const LightPropertiesF& key) const;
173 + Camera* const shadowCamera() const {return _shadowCamera;}
174 + ///Set the light slot.
175 + ///Slot is used by the rendering API internally
176 + inline void setSlot(const U8 slot) { _slot = slot;}
191 177
192 178 protected:
193 179
194 - LightProperties _properties;
180 + LightPhysicalProperties _physicalProperties;
181 + LightVisualProperties _visualProperties;
195 182 LightShadowProperties _shadowProperties;
196 183
197 - U32 _id;
198 184 LightType _type;
199 185 LightMode _mode;
186 + bool _dirty[PropertyType_PLACEHOLDER];
200 187
201 188 private:
202 189 U8 _resolutionFactor;
  @@ -210,7 +197,6 @@
210 197 Camera* _shadowCamera;
211 198 DELEGATE_CBK _callback;
212 199 F32 _score;
213 - bool _dirty;
214 200 bool _enabled;
215 201
216 202 protected: