2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUiEffects_RendererSpotLight.h
19 * @brief This is the header file for the SpotLight class
22 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_SPOTLIGHT_H_
23 #define _FUI_EFFECTS_INTERNAL_RENDERER_SPOTLIGHT_H_
25 #include <FBaseSysLog.h>
27 #include <renderer/engine-model/FUiEffects_RendererEngineModelIntPropertyHolder.h>
28 #include <renderer/engine-model/FUiEffects_RendererEngineModelFloatPropertyHolder.h>
29 #include <renderer/engine-model/FUiEffects_RendererEngineModelVector3fPropertyHolder.h>
30 #include <utils/FUiEffects_Utils.h>
32 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
37 * @brief This class contains data for spot light in scene
47 * * @param [in] attenuation Global attenuation pointer
49 * @remark Sets default values for members
51 SpotLight(System::FloatPtr attenuation)
53 result r = GetLastResult();
54 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
55 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(attenuation) != null, E_INVALID_ARG, "[E_INVALID_ARG] PointLight attenuation equals null");
57 __position = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
58 __direction = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
59 __k1 = EngineModel::FloatPropertyHolderPtr(new (std::nothrow) EngineModel::FloatPropertyHolder);
60 __k2 = EngineModel::FloatPropertyHolderPtr(new (std::nothrow) EngineModel::FloatPropertyHolder);
61 __colorI = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
62 __Rk = EngineModel::FloatPropertyHolderPtr(new (std::nothrow) EngineModel::FloatPropertyHolder);
65 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
66 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__position) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
67 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__direction) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
68 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__k1) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
69 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__k2) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
70 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__colorI) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
71 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__Rk) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
73 __position->Set(0.f, 0.f, 0.f);
74 __target.set(0.f, 0.f, -1.f);
75 __direction->Set(0.f, 0.f, -1.f);
76 __halfOpeningAngle = 0.6f;
77 __fadeOutAngle = 0.1f;
78 __color.set(1.f, 0.f, 0.f);
81 __attenuation = attenuation;
89 * Sets position property
91 * @param [in] position New position
95 void SetPosition(const Tizen::Ui::Effects::_Utils::Vec3f& position)
97 __position->Set(position.x, position.y, position.z);
98 __direction->Set(Math::Vector3f(__target.x - __position->Get().X(), __target.y - __position->Get().Y(), __target.z - __position->Get().Z()).Normalize());
104 * Sets target property
106 * @param [in] target New target
110 void SetTarget(const Tizen::Ui::Effects::_Utils::Vec3f& target)
113 __direction->Set(Math::Vector3f(__target.x - __position->Get().X(), __target.y - __position->Get().Y(), __target.z - __position->Get().Z()).Normalize());
119 * Sets opening angle value
121 * @param [in] openingAngle New opening angle
125 void SetOpeningAngle(float openingAngle)
127 __halfOpeningAngle = openingAngle * 0.5f;
134 * Sets fadeout angle value
136 * @param [in] fadeOutAngle New fadeout angle
140 void SetFadeOutAngle(float fadeOutAngle)
142 __fadeOutAngle = fadeOutAngle;
149 * Sets color property
151 * @param [in] color New color value
155 void SetColor(const Tizen::Ui::Effects::_Utils::Vec3f& color)
164 * Sets intensity property
166 * @param [in] intensity New intensity value
170 void SetIntensity(float intensity)
172 __intensity = intensity;
181 * @param [in] enabled New enabled value
185 void SetEnabled(bool enabled)
193 * Gets position property
195 * @return position property
197 EngineModel::Vector3fPropertyHolderPtr GetPositionHolder(void) const
203 * Gets direction vector property
205 * @return direction vector property
207 EngineModel::Vector3fPropertyHolderPtr GetDirectionHolder(void) const
215 * @return k1 property
217 EngineModel::FloatPropertyHolderPtr GetK1Holder(void) const
225 * @return k2 property
227 EngineModel::FloatPropertyHolderPtr GetK2Holder(void) const
233 * Gets color*intensity value property
235 * @return color*intensity value property
237 EngineModel::Vector3fPropertyHolderPtr GetColorIHolder(void) const
245 * @return enabled value
247 bool GetEnabled(void) const
253 * Gets Rk value holder
255 * @return Rk value holder
257 EngineModel::FloatPropertyHolderPtr GetRkHolder(void) const
263 * Does source emitt any light?
265 * @return true if color*intensity = 0
267 bool IsBlack(void) const
269 return __maxCi <= std::numeric_limits<float>::epsilon() || __Rk->Get() <= std::numeric_limits<float>::epsilon();
273 * Updates precalculated values related to Attenuation
277 void UpdateAttenuation(void)
285 * Hidden copy constructor
287 SpotLight(const SpotLight &rhs);
291 * Hidden assignment operator
293 SpotLight& operator=(const SpotLight &rhs);
296 * Calculates parameters for shader
300 void UpdateK1K2(void)
302 __k1->Set(Math::EffectsCos(__halfOpeningAngle + __fadeOutAngle));
303 __k2->Set(1.0f / (Math::EffectsCos(__halfOpeningAngle) - __k1->Get()));
309 * Sets colorI property which is premultiplied color x intensity for use in shader. @n
310 * Also calculates 1 / Rmax, where Rmax is maxim distance light value is >= 1/255
314 void UpdateColorI(void)
316 __colorI->Set(__color.x * __intensity, __color.y * __intensity, __color.z * __intensity);
317 __maxCi = Math::EffectsAbs(__intensity * Math::EffectsMax(__color.x, Math::EffectsMax(__color.y, __color.z)));
325 * Updates precalculated values related to light emission radius
331 if(__maxCi > std::numeric_limits<float>::epsilon())
333 __Rk->Set(Math::EffectsSqrt(*__attenuation * (1.0f/255.f) / __maxCi));
338 Tizen::Ui::Effects::_Utils::Vec3f __target;
339 float __halfOpeningAngle;
340 float __fadeOutAngle;
341 _Utils::Vec3f __color;
346 EngineModel::Vector3fPropertyHolderPtr __position;
347 EngineModel::Vector3fPropertyHolderPtr __direction;
348 EngineModel::FloatPropertyHolderPtr __k1; /**< precalculated parameter = cos(OpeningAngle/2 + FadeOutAngle) */
349 EngineModel::FloatPropertyHolderPtr __k2; /**< precalculated parameter = 1 / (cos(OpeningAngle/2) - __k1) */
350 EngineModel::Vector3fPropertyHolderPtr __colorI; /**< __color * __intensity */
351 EngineModel::FloatPropertyHolderPtr __Rk;
352 System::FloatPtr __attenuation;
355 typedef System::SmartPtr<SpotLight> SpotLightPtr;
357 } } } } // Tizen::Ui::Effects::_EffectRenderer
359 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_DIRECTIONALLIGHT_H_