1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ResLight.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_GFX_RESLIGHT_H_
19 #define NW_GFX_RESLIGHT_H_
20 
21 #include <nw/ut/ut_ResUtil.h>
22 #include <nw/ut/ut_ResDictionary.h>
23 #include <nw/gfx/res/gfx_ResLookupTable.h>
24 #include <nw/gfx/res/gfx_ResFragmentShader.h>
25 #include <nw/gfx/res/gfx_ResRevision.h>
26 #include <nw/gfx/res/gfx_ResTypeInfo.h>
27 
28 namespace nw {
29 namespace gfx {
30 namespace res {
31 
32 class ResGraphicsFile;
33 
34 //! @details :private
35 struct ResLightData : public ResTransformNodeData
36 {
37     nw::ut::ResBool m_IsLightEnabled;
38     u8 padding_[3];
39 };
40 
41 //! @details :private
42 struct ResFragmentLightData : public ResLightData
43 {
44     enum Flag
45     {
46         FLAG_TWO_SIDE_DIFFUSE_ENABLED_SHIFT = ResTransformNode::FLAG_SHIFT_MAX,
47         FLAG_DISTANCE_ATTENUATION_ENABLED_SHIFT,
48         FLAG_INHERITING_DIRECTION_ROTATE_SHIFT,
49         FLAG_SHIFT_MAX,
50 
51         FLAG_TWO_SIDE_DIFFUSE_ENABLED     = 0x1 << FLAG_TWO_SIDE_DIFFUSE_ENABLED_SHIFT,
52         FLAG_DISTANCE_ATTENUATION_ENABLED = 0x1 << FLAG_DISTANCE_ATTENUATION_ENABLED_SHIFT,
53         FLAG_IS_INHERITING_DIRECTION_ROTATE  = 0x1 << FLAG_INHERITING_DIRECTION_ROTATE_SHIFT
54     };
55 
56     nw::ut::ResS32 m_LightKind;
57     nw::ut::ResFloatColor m_Ambient;
58     nw::ut::ResFloatColor m_Diffuse;
59     nw::ut::ResFloatColor m_Specular0;
60     nw::ut::ResFloatColor m_Specular1;
61     nw::ut::ResU32 m_AmbientU32;
62     nw::ut::ResU32 m_DiffuseU32;
63     nw::ut::ResU32 m_Specular0U32;
64     nw::ut::ResU32 m_Specular1U32;
65     nw::ut::ResVec3 m_Direction;
66     nw::ut::Offset toDistanceSampler;
67     nw::ut::Offset toAngleSampler;
68     nw::ut::ResF32 m_DistanceAttenuationStart; // アニメーション書き込み用バッファ
69     nw::ut::ResF32 m_DistanceAttenuationEnd; // アニメーション書き込み用バッファ
70     nw::ut::ResU32 m_DistanceAttenuationScale;
71     nw::ut::ResU32 m_DistanceAttenuationBias;
72 
73     nw::ut::ResBool m_IsDirty;
74     u8 padding_[3];
75 };
76 
77 //! @details :private
78 struct ResAmbientLightData : public ResLightData
79 {
80     nw::ut::ResFloatColor m_Ambient;
81     nw::ut::ResU32 m_AmbientU32;
82 
83     nw::ut::ResBool m_IsDirty;
84     u8 padding_[3];
85 };
86 
87 //! @details :private
88 struct ResVertexLightData : public ResLightData
89 {
90     enum Flag
91     {
92         FLAG_INHERITING_DIRECTION_ROTATE_SHIFT = ResTransformNode::FLAG_SHIFT_MAX,
93         FLAG_SHIFT_MAX,
94 
95         FLAG_IS_INHERITING_DIRECTION_ROTATE  = 0x1 << FLAG_INHERITING_DIRECTION_ROTATE_SHIFT
96     };
97 
98     nw::ut::ResS32 m_LightKind;
99     nw::ut::ResFloatColor m_Ambient;
100     nw::ut::ResFloatColor m_Diffuse;
101     nw::ut::ResVec3 m_Direction;
102     nw::ut::ResVec3 m_DistanceAttenuation;
103     nw::ut::ResF32 m_IsDistanceAttenuationEnabled;
104     nw::ut::ResVec2 m_SpotFactor;
105 };
106 
107 //! @details :private
108 struct ResHemiSphereLightData : public ResLightData
109 {
110     enum Flag
111     {
112         FLAG_INHERITING_DIRECTION_ROTATE_SHIFT = ResTransformNode::FLAG_SHIFT_MAX,
113         FLAG_SHIFT_MAX,
114 
115         FLAG_IS_INHERITING_DIRECTION_ROTATE  = 0x1 << FLAG_INHERITING_DIRECTION_ROTATE_SHIFT
116     };
117 
118     nw::ut::ResFloatColor m_GroundColor;
119     nw::ut::ResFloatColor m_SkyColor;
120     nw::ut::ResVec3 m_Direction;
121     nw::ut::ResF32 m_LerpFactor;
122 };
123 
124 //--------------------------------------------------------------------------
125 //! @brief  ライトを表すバイナリリソースの基底クラスです。
126 //---------------------------------------------------------------------------
127 class ResLight : public ResTransformNode
128 {
129 public:
130     enum { BINARY_REVISION = REVISION_RES_LIGHT };
131 
132     //! @brief ライトの光源の種類です。
133     enum Kind
134     {
135         KIND_DIRECTIONAL,   //!< ディレクショナルライトです。
136         KIND_POINT,         //!< ポイントライトです。
137         KIND_SPOT,          //!< スポットライトです。
138         KIND_UNUSED,        //!< 光源の種類を考慮しないライトです。
139         KIND_COUNT          //!< enum の最大値です。
140     };
141 
NW_RES_CTOR_INHERIT(ResLight,ResTransformNode)142     NW_RES_CTOR_INHERIT( ResLight, ResTransformNode )
143 
144     //---------------------------------------------------------------------------
145     //! @fn           void SetLightEnabled(bool value)
146     //! @brief        ライトの有効フラグを設定します。
147     //---------------------------------------------------------------------------
148     //---------------------------------------------------------------------------
149     //! @fn           bool IsLightEnabled() const
150     //! @brief        ライトの有効フラグを取得します。
151     //---------------------------------------------------------------------------
152     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( LightEnabled ) // IsLightEnabled(), SetLightEnabled()
153 
154     //---------------------------------------------------------------------------
155     //! @brief        リビジョンを取得します。
156     //!
157     //! @return       リソースのリビジョン情報です。
158     //---------------------------------------------------------------------------
159     u32 GetRevision() const { return this->GetHeader().revision; }
160 
161     //---------------------------------------------------------------------------
162     //! @brief        リソースのセットアップをおこないます。
163     //!
164     //! @param[in]    allocator アロケータです。
165     //! @param[in]    graphicsFile グラフィックスリソースです。
166     //---------------------------------------------------------------------------
167     Result Setup(os::IAllocator* allocator, ResGraphicsFile graphicsFile);
168 
169     //---------------------------------------------------------------------------
170     //! @brief        リソースの後始末をおこないます。
171     //---------------------------------------------------------------------------
172     void Cleanup();
173 };
174 typedef nw::ut::ResArrayPatricia<ResLight>::type  ResLightArray;
175 
176 //--------------------------------------------------------------------------
177 //! @brief  フラグメントライトを表すバイナリリソースクラスです。
178 //---------------------------------------------------------------------------
179 class ResFragmentLight : public ResLight
180 {
181 public:
182     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResFragmentLight) };
183     enum { SIGNATURE = NW_RES_SIGNATURE32('CFLT') };
184 
NW_RES_CTOR_INHERIT(ResFragmentLight,ResLight)185     NW_RES_CTOR_INHERIT( ResFragmentLight, ResLight )
186 
187 
188     //---------------------------------------------------------------------------
189     //! @fn           void SetSpecular1(f32 r, f32 g, f32 b)
190     //! @brief        ライトのスペキュラカラー1を設定します。
191     //---------------------------------------------------------------------------
192     //---------------------------------------------------------------------------
193     //! @fn           void SetSpecular0(f32 r, f32 g, f32 b)
194     //! @brief        ライトのスペキュラカラー0を設定します。
195     //---------------------------------------------------------------------------
196     //---------------------------------------------------------------------------
197     //! @fn           void SetLightKind(s32 value)
198     //! @brief        光源の種類を設定します。
199     //---------------------------------------------------------------------------
200     //---------------------------------------------------------------------------
201     //! @fn           void SetDirty(bool value)
202     //! @brief        ライトの内容が更新されているかどうかのフラグを設定します。
203     //---------------------------------------------------------------------------
204     //---------------------------------------------------------------------------
205     //! @fn           void SetDirection(f32 x, f32 y, f32 z)
206     //! @brief        ライトの方向を設定します。
207     //---------------------------------------------------------------------------
208     //---------------------------------------------------------------------------
209     //! @fn           void SetDiffuse(f32 r, f32 g, f32 b)
210     //! @brief        ライトのディフューズカラーを設定します。
211     //---------------------------------------------------------------------------
212     //---------------------------------------------------------------------------
213     //! @fn           void SetAmbient(f32 r, f32 g, f32 b)
214     //! @brief        ライトのアンビエントカラーを設定します。
215     //---------------------------------------------------------------------------
216     //---------------------------------------------------------------------------
217     //! @fn           bool IsDirty() const
218     //! @brief        ライトの内容が更新されているかどうかのフラグを取得します。
219     //---------------------------------------------------------------------------
220     //---------------------------------------------------------------------------
221     //! @fn           u32 GetSpecular1U32() const
222     //! @brief        ライトのスペキュラカラー1を RGBA8 の32bitフォーマットで取得します。
223     //---------------------------------------------------------------------------
224     //---------------------------------------------------------------------------
225     //! @fn           const nw::ut::FloatColor & GetSpecular1() const
226     //! @brief        ライトのスペキュラカラー1を取得します。
227     //---------------------------------------------------------------------------
228     //---------------------------------------------------------------------------
229     //! @fn           u32 GetSpecular0U32() const
230     //! @brief        ライトのスペキュラカラー0を RGBA8 の32bitフォーマットで取得します。
231     //---------------------------------------------------------------------------
232     //---------------------------------------------------------------------------
233     //! @fn           const nw::ut::FloatColor & GetSpecular0() const
234     //! @brief        ライトのスペキュラカラー0を取得します。
235     //---------------------------------------------------------------------------
236     //---------------------------------------------------------------------------
237     //! @fn           s32 GetLightKind() const
238     //! @brief        光源の種類を取得します。
239     //---------------------------------------------------------------------------
240     //---------------------------------------------------------------------------
241     //! @fn           ResLookupTable GetDistanceSampler()
242     //! @brief        距離減衰用のルックアップテーブルを取得します。
243     //---------------------------------------------------------------------------
244     //---------------------------------------------------------------------------
245     //! @fn           const nw::math::VEC3 & GetDirection() const
246     //! @brief        ライトの方向を取得します。
247     //---------------------------------------------------------------------------
248     //---------------------------------------------------------------------------
249     //! @fn           u32 GetDiffuseU32() const
250     //! @brief        ライトのディフューズカラーを RGBA8 の32bitフォーマットで取得します。
251     //---------------------------------------------------------------------------
252     //---------------------------------------------------------------------------
253     //! @fn           const nw::ut::FloatColor & GetDiffuse() const
254     //! @brief        ライトのディフューズカラーを取得します。
255     //---------------------------------------------------------------------------
256     //---------------------------------------------------------------------------
257     //! @fn           ResLightingLookupTable GetAngleSampler()
258     //! @brief        角度減衰用のルックアップテーブルを取得します。
259     //---------------------------------------------------------------------------
260     //---------------------------------------------------------------------------
261     //! @fn           u32 GetAmbientU32() const
262     //! @brief        ライトのアンビエントカラーを RGBA8 の32bitフォーマットで取得します。
263     //---------------------------------------------------------------------------
264     //---------------------------------------------------------------------------
265     //! @fn           const nw::ut::FloatColor & GetAmbient() const
266     //! @brief        ライトのアンビエントカラーを取得します。
267     //---------------------------------------------------------------------------
268     NW_RES_FIELD_PRIMITIVE_DECL( s32, LightKind )               // GetLightKind(), SetLightKind()
269     NW_RES_FIELD_FLOAT_U32_COLOR_DECL( nw::ut::FloatColor, Ambient )     // const FloatColor& GetAmbient()
270     NW_RES_FIELD_FLOAT_U32_COLOR_DECL( nw::ut::FloatColor, Diffuse )     // const FloatColor& GetDiffuse()
271     NW_RES_FIELD_FLOAT_U32_COLOR_DECL( nw::ut::FloatColor, Specular0 )   // const FloatColor& GetSpecular0()
272     NW_RES_FIELD_FLOAT_U32_COLOR_DECL( nw::ut::FloatColor, Specular1 )   // const FloatColor& GetSpecular1()
273     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, Direction )       // VEC3& GetDirection()
274     NW_RES_FIELD_CLASS_DECL( ResLookupTable, DistanceSampler ) // GetDistanceSampler()
275     NW_RES_FIELD_CLASS_DECL( ResLightingLookupTable, AngleSampler )    // GetAngleSampler()
276 
277     //---------------------------------------------------------------------------
278     //! @brief        参照テーブルを設定します。
279     //!               参照先に設定しますのでリソースの解放はされません。
280     //!
281     //! @param[in]    参照テーブルです。
282     //---------------------------------------------------------------------------
283     void SetDistanceSampler(ResImageLookupTable lookupTable)
284     {
285         NW_ASSERT(lookupTable.IsValid());
286         ResReferenceLookupTable referenceLut = ResStaticCast<ResReferenceLookupTable>(GetDistanceSampler());
287         referenceLut.ref().toTargetLut.set_ptr(lookupTable.ptr());
288     }
289 
290     //--------------------------------------------------------------------------
291     //! @brief        距離減衰の開始距離を取得します。
292     //!
293     //! @return       距離減衰の開始距離設定です。
294     //---------------------------------------------------------------------------
GetDistanceAttenuationStart()295     f32 GetDistanceAttenuationStart() const
296     {
297         return ref().m_DistanceAttenuationStart;
298     }
299 
300     //--------------------------------------------------------------------------
301     //! @brief        距離減衰の終了距離を取得します。
302     //!
303     //! @return       距離減衰の終了距離設定です。
304     //---------------------------------------------------------------------------
GetDistanceAttenuationEnd()305     f32 GetDistanceAttenuationEnd() const
306     {
307         return ref().m_DistanceAttenuationEnd;
308     }
309 
310     //--------------------------------------------------------------------------
311     //! @brief        距離減衰の開始距離を設定します。
312     //---------------------------------------------------------------------------
SetDistanceAttenuationStart(f32 start)313     void SetDistanceAttenuationStart(f32 start)
314     {
315         ref().m_DistanceAttenuationStart = start;
316         SetDistanceAttenuation(ref().m_DistanceAttenuationStart, ref().m_DistanceAttenuationEnd);
317     }
318 
319     //--------------------------------------------------------------------------
320     //! @brief        距離減衰の終了距離を設定します。
321     //---------------------------------------------------------------------------
SetDistanceAttenuationEnd(f32 end)322     void SetDistanceAttenuationEnd(f32 end)
323     {
324         ref().m_DistanceAttenuationEnd = end;
325         SetDistanceAttenuation(ref().m_DistanceAttenuationStart, ref().m_DistanceAttenuationEnd);
326     }
327 
328     //--------------------------------------------------------------------------
329     //! @brief        距離減衰の開始、終了パラメータを設定します。
330     //!
331     //! @param[in]    start   減衰開始距離です。
332     //! @param[in]    end     減衰終了距離です。
333     //---------------------------------------------------------------------------
SetDistanceAttenuation(f32 start,f32 end)334     void SetDistanceAttenuation(f32 start, f32 end)
335     {
336         f32 diff = end - start;
337 
338         f32 minimumDistance = 0.01f;
339         if (math::FAbs(diff) < minimumDistance)
340         {
341             diff = minimumDistance;
342         }
343 
344         ref().m_DistanceAttenuationScale = ut::Float20::Float32ToBits20(1.0f / diff);
345         ref().m_DistanceAttenuationBias = ut::Float20::Float32ToBits20(-start / diff);
346     }
347 
NW_RES_FIELD_BOOL_PRIMITIVE_DECL(Dirty)348     NW_RES_FIELD_BOOL_PRIMITIVE_DECL( Dirty )          // IsDirty(), SetDirty()
349 
350     //---------------------------------------------------------------------------
351     //! @brief        targetName で参照している参照テーブルを lookupTable を使って強制的にセットアップします。
352     //!
353     //! @param[in]    targetName 参照しているパス情報です。
354     //! @param[in]    lookupTable 参照テーブルです。
355     //---------------------------------------------------------------------------
356     void ForceSetupDistanceSampler(const char* targetName, ResLookupTable lookupTable)
357     {
358         NW_ASSERT(lookupTable.IsValid());
359         ResReferenceLookupTable referenceLut = ResStaticCast<ResReferenceLookupTable>(GetDistanceSampler());
360         referenceLut.ForceSetup(targetName, lookupTable);
361     }
362 };
363 
364 //--------------------------------------------------------------------------
365 //! @brief  グローバルアンビエントライトを表すバイナリリソースクラスです。
366 //---------------------------------------------------------------------------
367 class ResAmbientLight : public ResLight
368 {
369 public:
370     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResAmbientLight) };
371     enum { SIGNATURE = NW_RES_SIGNATURE32('CALT') };
372 
373     NW_RES_CTOR_INHERIT( ResAmbientLight, ResLight )
374 
375     //---------------------------------------------------------------------------
376     //! @fn           void SetAmbient(f32 r, f32 g, f32 b)
377     //! @brief        ライトのアンビエントカラーを設定します。
378     //---------------------------------------------------------------------------
379     //---------------------------------------------------------------------------
380     //! @fn           u32 GetAmbientU32() const
381     //! @brief        ライトのアンビエントカラーを RGBA8 の32bitフォーマットで取得します。
382     //---------------------------------------------------------------------------
383     //---------------------------------------------------------------------------
384     //! @fn           const nw::ut::FloatColor & GetAmbient() const
385     //! @brief        ライトのアンビエントカラーを取得します。
386     //---------------------------------------------------------------------------
387     NW_RES_FIELD_FLOAT_U32_COLOR_DECL( nw::ut::FloatColor, Ambient )     // FloatColor& GetAmbient()
388 };
389 
390 //--------------------------------------------------------------------------
391 //! @brief  頂点ライトを表すバイナリリソースクラスです。
392 //---------------------------------------------------------------------------
393 class ResVertexLight : public ResLight
394 {
395 public:
396     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResVertexLight) };
397     enum { SIGNATURE = NW_RES_SIGNATURE32('CVLT') };
398 
NW_RES_CTOR_INHERIT(ResVertexLight,ResLight)399     NW_RES_CTOR_INHERIT( ResVertexLight, ResLight )
400 
401     //---------------------------------------------------------------------------
402     //! @fn           void SetSpotFactor(f32 x, f32 y)
403     //! @brief        スポットライトの角度減衰係数を設定します。
404     //---------------------------------------------------------------------------
405     //---------------------------------------------------------------------------
406     //! @fn           void SetLightKind(s32 value)
407     //! @brief        光源の種類を設定します。
408     //---------------------------------------------------------------------------
409     //---------------------------------------------------------------------------
410     //! @fn           void SetDistanceAttenuation(f32 x, f32 y, f32 z)
411     //! @brief        距離減衰のパラメータを設定します。
412     //---------------------------------------------------------------------------
413     //---------------------------------------------------------------------------
414     //! @fn           void SetDirection(f32 x, f32 y, f32 z)
415     //! @brief        ライトの方向を設定します。
416     //---------------------------------------------------------------------------
417     //---------------------------------------------------------------------------
418     //! @fn           void SetDiffuse(f32 r, f32 g, f32 b)
419     //! @brief        ライトのディフューズカラーを設定します。
420     //---------------------------------------------------------------------------
421     //---------------------------------------------------------------------------
422     //! @fn           void SetAmbient(f32 r, f32 g, f32 b)
423     //! @brief        ライトのアンビエントカラーを設定します。
424     //---------------------------------------------------------------------------
425     //---------------------------------------------------------------------------
426     //! @fn           const nw::math::VEC2 & GetSpotFactor() const
427     //! @brief        スポットライトの角度減衰係数を取得します。
428     //---------------------------------------------------------------------------
429     //---------------------------------------------------------------------------
430     //! @fn           s32 GetLightKind() const
431     //! @brief        光源の種類を取得します。
432     //---------------------------------------------------------------------------
433     //---------------------------------------------------------------------------
434     //! @fn           const nw::math::VEC3 & GetDistanceAttenuation() const
435     //! @brief        距離減衰のパラメータを取得します。
436     //---------------------------------------------------------------------------
437     //---------------------------------------------------------------------------
438     //! @fn           const nw::math::VEC3 & GetDirection() const
439     //! @brief        ライトの方向を取得します。
440     //---------------------------------------------------------------------------
441     //---------------------------------------------------------------------------
442     //! @fn           const nw::ut::FloatColor & GetDiffuse() const
443     //! @brief        ライトのディフューズカラーを取得します。
444     //---------------------------------------------------------------------------
445     //---------------------------------------------------------------------------
446     //! @fn           const nw::ut::FloatColor & GetAmbient() const
447     //! @brief        ライトのアンビエントカラーを取得します。
448     //---------------------------------------------------------------------------
449     NW_RES_FIELD_PRIMITIVE_DECL( s32, LightKind )                   // GetLightLind(), SetLightKind()
450     NW_RES_FIELD_FLOAT_COLOR_DECL( nw::ut::FloatColor, Ambient )    // const FloatColor& GetAmbient()
451     NW_RES_FIELD_FLOAT_COLOR_DECL( nw::ut::FloatColor, Diffuse )    // const FloatColor& GetDiffuse()
452     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, Direction )           // VEC3& GetDirection()
453     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, DistanceAttenuation ) // VEC3& GetDistanceAttenuation()
454     NW_RES_FIELD_VECTOR2_DECL( nw::math::VEC2, SpotFactor )          // VEC2& GetSpotFactor()
455 
456     //---------------------------------------------------------------------------
457     //!  @brief        距離減衰が有効かどうかを取得します。
458     //!
459     //!  @return       距離減衰が有効であれば true を返します。
460     //---------------------------------------------------------------------------
461     bool IsDistanceAttenuationEnabled() const { return ref().m_IsDistanceAttenuationEnabled != 0.0f; }
462 
463     //---------------------------------------------------------------------------
464     //!  @brief        距離減衰が有効かどうかを設定します。
465     //!
466     //!  @param[in]    enable 距離減衰を有効にするためには true を指定します。
467     //---------------------------------------------------------------------------
SetDistanceAttenuationEnabled(bool enable)468     void SetDistanceAttenuationEnabled(bool enable)
469     {
470         ref().m_IsDistanceAttenuationEnabled = enable ? 1.0f : 0.0f;
471     }
472 
473     //---------------------------------------------------------------------------
474     //!  @brief        DistanceAttenuation と IsDistanceAttenuationEnabled を VEC4 として取得します。
475     //!
476     //!  @return       w 値に IsDistanceAttenuationEnabled が格納された 4 要素のベクトルです。
477     //---------------------------------------------------------------------------
GetDistanceAttenuationAndEnabled()478     math::VEC4& GetDistanceAttenuationAndEnabled()
479     {
480         return reinterpret_cast<nw::math::VEC4&>( ref().m_DistanceAttenuation );
481     }
482 
483     //---------------------------------------------------------------------------
484     //!  @brief        Direction と IsDistanceAttenuationEnabled を VEC4 として取得します。
485     //!
486     //!  @return       w 値に IsDistanceAttenuationEnabled が格納された 4 要素のベクトルです。
487     //---------------------------------------------------------------------------
GetDistanceAttenuationAndEnabled()488     const math::VEC4& GetDistanceAttenuationAndEnabled() const
489     {
490         return reinterpret_cast<const nw::math::VEC4&>( ref().m_DistanceAttenuation );
491     }
492 };
493 
494 //--------------------------------------------------------------------------
495 //! @brief  半球ライトを表すバイナリリソースクラスです。
496 //---------------------------------------------------------------------------
497 class ResHemiSphereLight : public ResLight
498 {
499 public:
500     enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResHemiSphereLight) };
501     enum { SIGNATURE = NW_RES_SIGNATURE32('CHLT') };
502 
NW_RES_CTOR_INHERIT(ResHemiSphereLight,ResLight)503     NW_RES_CTOR_INHERIT( ResHemiSphereLight, ResLight )
504 
505     //---------------------------------------------------------------------------
506     //! @fn           void SetSkyColor(f32 r, f32 g, f32 b)
507     //! @brief        空の色を設定します。
508     //---------------------------------------------------------------------------
509     //---------------------------------------------------------------------------
510     //! @fn           void SetLerpFactor(f32 value)
511     //! @brief        線形補間係数を設定します。
512     //---------------------------------------------------------------------------
513     //---------------------------------------------------------------------------
514     //! @fn           void SetGroundColor(f32 r, f32 g, f32 b)
515     //! @brief        地面の色を設定します。
516     //---------------------------------------------------------------------------
517     //---------------------------------------------------------------------------
518     //! @fn           void SetDirection(f32 x, f32 y, f32 z)
519     //! @brief        ライトの方向を設定します。
520     //---------------------------------------------------------------------------
521     //---------------------------------------------------------------------------
522     //! @fn           const nw::ut::FloatColor & GetSkyColor() const
523     //! @brief        空の色を取得します。
524     //---------------------------------------------------------------------------
525     //---------------------------------------------------------------------------
526     //! @fn           f32 GetLerpFactor() const
527     //! @brief        線形補間係数を取得します。
528     //---------------------------------------------------------------------------
529     //---------------------------------------------------------------------------
530     //! @fn           const nw::ut::FloatColor & GetGroundColor() const
531     //! @brief        地面の色を取得します。
532     //---------------------------------------------------------------------------
533     //---------------------------------------------------------------------------
534     //! @fn           const nw::math::VEC3 & GetDirection() const
535     //! @brief        ライトの方向を取得します。
536     //---------------------------------------------------------------------------
537     NW_RES_FIELD_FLOAT_COLOR_DECL( nw::ut::FloatColor, GroundColor ) // FloatColor& GetGroundColor()
538     NW_RES_FIELD_FLOAT_COLOR_DECL( nw::ut::FloatColor, SkyColor )    // FloatColor& GetSkyColor()
539     NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, Direction )       // VEC3& GetDirection()
540     NW_RES_FIELD_PRIMITIVE_DECL( f32, LerpFactor )              // GetLerpFactor(), SetLerpFactor()
541 
542     //---------------------------------------------------------------------------
543     //!  @brief        Direction と Lerp を VEC4 として取得します。
544     //!
545     //!  @return       w 値に Lerp が格納された 4 要素のベクトルです。
546     //---------------------------------------------------------------------------
547     nw::math::VEC4& GetDirectionAndLerp()
548     {
549         return reinterpret_cast<nw::math::VEC4&>( ref().m_Direction );
550     }
551 
552     //---------------------------------------------------------------------------
553     //!  @brief        Direction と Lerp を VEC4 として取得します。
554     //!
555     //!  @return       w 値に Lerp が格納された 4 要素のベクトルです。
556     //---------------------------------------------------------------------------
GetDirectionAndLerp()557     const nw::math::VEC4& GetDirectionAndLerp() const
558     {
559         return reinterpret_cast<const nw::math::VEC4&>( ref().m_Direction );
560     }
561 };
562 
563 } // namespace res
564 } // namespace gfx
565 } // namespace nw
566 
567 #endif // NW_GFX_RESLIGHT_H_
568