1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_FragmentLight.h
4   Copyright (C)2010 Nintendo Co., Ltd.  All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: 33893 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 #ifndef NN_GR_FRAGMENT_LIGHT_H_
17 #define NN_GR_FRAGMENT_LIGHT_H_
18 
19 #include <nn/gr/CTR/gr_Prefix.h>
20 #include <nn/gr/CTR/gr_LookUpTable.h>
21 
22 namespace nn
23 {
24     namespace gr
25     {
26         namespace CTR
27         {
28 
29             /* Please see man pages for details
30 
31              */
32             class FragmentLight
33             {
34             public :
35                 /* Please see man pages for details
36 
37                  */
38                 class Source
39                 {
40                 public :
41 
42                     /* Please see man pages for details
43 
44 
45 
46                     */
47                     u8 id;
48 
49                     /* Please see man pages for details
50 
51 
52                     */
53                     bool isEnableTwoSideDiffuse;
54 
55                     /* Please see man pages for details
56 
57 
58                     */
59                     bool isEnableGeomFactor0;
60 
61                     /* Please see man pages for details
62 
63 
64                     */
65                     bool isEnableGeomFactor1;
66 
67                     /* Please see man pages for details
68 
69                            
70 
71                     */
72                     u8 diffuseR;
73 
74                     /* Please see man pages for details
75 
76 
77 
78 
79                     */
80                     u8 diffuseG;
81 
82                     /* Please see man pages for details
83 
84                            
85 
86 
87                     */
88                     u8 diffuseB;
89 
90                     /* Please see man pages for details
91 
92 
93 
94 
95                     */
96                     u8 ambientR;
97 
98                     /* Please see man pages for details
99 
100 
101 
102                     */
103                     u8 ambientG;
104 
105                     /* Please see man pages for details
106 
107 
108 
109                     */
110                     u8 ambientB;
111 
112                     /* Please see man pages for details
113 
114 
115 
116                     */
117                     u8 specular0R;
118 
119                     /* Please see man pages for details
120 
121 
122 
123                     */
124                     u8 specular0G;
125 
126                     /* Please see man pages for details
127 
128 
129 
130                     */
131                     u8 specular0B;
132 
133                     /* Please see man pages for details
134 
135 
136 
137 
138                     */
139                     u8 specular1R;
140 
141                     /* Please see man pages for details
142 
143 
144 
145 
146                     */
147                     u8 specular1G;
148 
149                     /* Please see man pages for details
150 
151 
152 
153 
154                     */
155                     u8 specular1B;
156 
157                 protected :
158                     /* Please see man pages for details
159 
160 
161                     */
162                     bit32  posXY;
163 
164                     /* Please see man pages for details
165 
166 
167                      */
168                     bit32  posZ;
169 
170                     /* Please see man pages for details
171 
172 
173                      */
174                     u8   isInfinity;
175                     NN_PADDING3;
176 
177                     /* Please see man pages for details
178 
179 
180                      */
181                     bit32 distAttnBias;
182 
183                     /* Please see man pages for details
184 
185 
186                      */
187                     bit32 distAttnScale;
188 
189                     /* Please see man pages for details
190 
191 
192                      */
193                     bit32 spotDirectionXY;
194 
195                     /* Please see man pages for details
196 
197 
198                      */
199                     bit32 spotDirectionZ;
200 
201 
202                 public :
203 
204                     /* Please see man pages for details
205 
206 
207 
208 
209 */
SetPosition(const nn::math::VEC3 & position,const bool is_infinity)210                     void SetPosition( const nn::math::VEC3& position, const bool is_infinity )
211                     {
212                         posXY = PICA_CMD_DATA_FRAG_LIGHT_POSITION_XY( Float32ToFloat16( position.x ),
213                                                                       Float32ToFloat16( position.y ) );
214                         posZ  = PICA_CMD_DATA_FRAG_LIGHT_POSITION_Z(  Float32ToFloat16( position.z ) );
215                         isInfinity = is_infinity ? 1 : 0;
216                     }
217 
218                     /* Please see man pages for details
219 
220 
221 
222 
223 
224 
225 */
SetPosition(const f32 position_x,const f32 position_y,const f32 position_z,const bool is_infinity)226                     void SetPosition( const f32 position_x, const f32 position_y, const f32 position_z, const bool is_infinity )
227                     {
228                         posXY = PICA_CMD_DATA_FRAG_LIGHT_POSITION_XY( Float32ToFloat16( position_x ),
229                                                                       Float32ToFloat16( position_y ) );
230                         posZ  = PICA_CMD_DATA_FRAG_LIGHT_POSITION_Z(  Float32ToFloat16( position_z ) );
231                         isInfinity = is_infinity ? 1 : 0;
232                     }
233 
234 
235                     /* Please see man pages for details
236 
237 
238 
239 */
SetSpotDirection(const nn::math::VEC3 & spot_direction)240                     void SetSpotDirection( const nn::math::VEC3& spot_direction )
241                     {
242                         spotDirectionXY = PICA_CMD_DATA_FRAG_LIGHT_SPOT_XY( Float32ToFix13Fraction11( -spot_direction.x ),
243                                                                             Float32ToFix13Fraction11( -spot_direction.y ) );
244                         spotDirectionZ  = PICA_CMD_DATA_FRAG_LIGHT_SPOT_Z(  Float32ToFix13Fraction11( -spot_direction.z ) );
245                     }
246 
247 
248                     /* Please see man pages for details
249 
250 
251 
252 
253 
254                      */
SetSpotDirection(const f32 & spot_direction_x,const f32 & spot_direction_y,const f32 & spot_direction_z)255                     void SetSpotDirection( const f32& spot_direction_x, const f32& spot_direction_y, const f32& spot_direction_z )
256                     {
257                         spotDirectionXY = PICA_CMD_DATA_FRAG_LIGHT_SPOT_XY( Float32ToFix13Fraction11( - spot_direction_x ),
258                                                                             Float32ToFix13Fraction11( - spot_direction_y ) );
259                         spotDirectionZ  = PICA_CMD_DATA_FRAG_LIGHT_SPOT_Z(  Float32ToFix13Fraction11( - spot_direction_z ) );
260                     }
261 
262 
263                     /* Please see man pages for details
264 
265 
266 
267 
268                      */
SetDistAttnScaleBias(const f32 scale,const f32 bias)269                     void SetDistAttnScaleBias( const f32 scale, const f32 bias )
270                     {
271                         distAttnScale = Float32ToFloat20( scale );
272                         distAttnBias  = Float32ToFloat20( bias );
273                     };
274 
275                     /* Please see man pages for details
276 
277 
278 
279 
280                      */
SetDistAttnStartEnd(const f32 start,const f32 end)281                     void SetDistAttnStartEnd( const f32 start, const f32 end )
282                     {
283                         f32 r = 1.f / ( end - start );
284                         SetDistAttnScaleBias( r, -start * r );
285                     };
286 
287                 public :
288                     /* Please see man pages for details
289 
290 
291 
292 
293                      */
294                     bit32* MakeAllCommand( bit32* command ) const;
295 
296                     /* Please see man pages for details
297 
298 
299 
300 
301 
302                      */
303                     bit32* MakeCommand( bit32* command ) const;
304 
305                     /* Please see man pages for details
306 
307 
308 
309 
310                      */
311                     bit32* MakeColorCommand( bit32* command ) const;
312 
313                     /* Please see man pages for details
314 
315 
316 
317 
318                      */
319                     bit32* MakeGeometryCommand( bit32* command ) const;
320 
321                 public :
322                     /* Please see man pages for details
323 
324                     */
325                     explicit Source();
326                 };
327 
328             public :
329                 //
330                 static const u32 LIGHT_SOURCE_MAX = 8;
331 
332                 /* Please see man pages for details
333 
334 
335 
336                 */
337                 // The value of dmp_FragmentMaterial.emission+dmp_FragmentMaterial.ambient×dmp_FragmentLighting.ambient [0.f, 1.f] is mapped to [0, 255] and set.
338                 //
339                 u8 globalAmbientR;
340 
341 
342                 /* Please see man pages for details
343 
344 
345 
346                  */
347                  // The value of dmp_FragmentMaterial.emission+dmp_FragmentMaterial.ambient×dmp_FragmentLighting.ambient [0.f, 1.f] is mapped to [0, 255] and set.
348                  //
349                 u8 globalAmbientG;
350 
351 
352                 /* Please see man pages for details
353 
354 
355 
356                  */
357                  // The value of dmp_FragmentMaterial.emission+dmp_FragmentMaterial.ambient×dmp_FragmentLighting.ambient [0.f, 1.f] is mapped to [0, 255] and set.
358                  //
359                 u8 globalAmbientB;
360                 NN_PADDING1;
361 
362 
363                 /* Please see man pages for details
364 
365 
366                 */
367                 Source source[ LIGHT_SOURCE_MAX ];
368 
369                 /* Please see man pages for details
370 
371 
372 
373                 */
374                 bool isEnable[ LIGHT_SOURCE_MAX ];
375 
376                 /* Please see man pages for details
377 
378 
379 
380                 */
381                 bool isEnableSpot[ LIGHT_SOURCE_MAX ];
382 
383                 /* Please see man pages for details
384 
385 
386 
387                 */
388                 bool isEnableDistAttn[ LIGHT_SOURCE_MAX ];
389 
390                 /* Please see man pages for details
391 
392 
393 
394                 */
395                 bool isShadowed[ LIGHT_SOURCE_MAX ];
396 
397                 /* Please see man pages for details
398 
399 
400                 */
401                 /*
402                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG0
403                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG1
404                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG2
405                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG3
406                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG4
407                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG5
408                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG6
409                  PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG7
410                  Set one of the above.
411                  */
412                 PicaDataFragLightEnvLayerConfig layerConfig;
413 
414                 /* Please see man pages for details
415 
416 
417                 */
418                 /*
419                  PICA_DATA_FRAG_LIGHT_ENV_NO_FRESNEL
420                  PICA_DATA_FRAG_LIGHT_ENV_PRI_ALPHA_FRESNEL
421                  PICA_DATA_FRAG_LIGHT_ENV_SEC_ALPHA_FRESNEL
422                  PICA_DATA_FRAG_LIGHT_ENV_PRI_SEC_ALPHA_FRESNEL
423                  Specify one of the above.
424                  */
425                 PicaDataFragLightEnvFresnel  fresnelSelector;
426 
427                 /* Please see man pages for details
428 
429 
430                 */
431                 /*
432                  PICA_DATA_FRAG_LIGHT_TEXTURE0
433                  PICA_DATA_FRAG_LIGHT_TEXTURE1
434                  PICA_DATA_FRAG_LIGHT_TEXTURE2
435                  PICA_DATA_FRAG_LIGHT_TEXTURE3
436                  Set one of the above.
437                  */
438                 PicaDataFragLightEnvTexture     shadowSelector;
439 
440                 /* Please see man pages for details
441 
442 
443                 */
444                 /*
445                  PICA_DATA_FRAG_LIGHT_ENV_BUMP_NOT_USED_DMP
446                  PICA_DATA_FRAG_LIGHT_ENV_BUMP_AS_BUMP_DMP
447                  PICA_DATA_FRAG_LIGHT_ENV_BUMP_AS_TANG_DMP
448                  Set one of the above.
449                  */
450                 PicaDataFragLightEnvBump        bumpMode;
451 
452                 /* Please see man pages for details
453 
454 
455                 */
456                 /*
457                  PICA_DATA_FRAG_LIGHT_TEXTURE0
458                  PICA_DATA_FRAG_LIGHT_TEXTURE1
459                  PICA_DATA_FRAG_LIGHT_TEXTURE2
460                  PICA_DATA_FRAG_LIGHT_TEXTURE3
461                  Set one of the above.
462                  */
463                 PicaDataFragLightEnvTexture     bumpSelector;
464 
465                 /* Please see man pages for details
466 
467 
468                 */
469                 bool                         isEnableShadowPrimary;
470 
471                 /* Please see man pages for details
472 
473 
474                 */
475                 bool                         isEnableShadowSecondary;
476 
477                 /* Please see man pages for details
478 
479 
480                 */
481                 bool                         isEnableShadowAlpha;
482 
483                 /* Please see man pages for details
484 
485 
486                 */
487                 bool                         isInvertShadow;
488 
489                 /* Please see man pages for details
490 
491 
492                 */
493                 bool                         isEnableBumpRenorm;
494 
495                 /* Please see man pages for details
496 
497 
498                 */
499                 bool                         isEnableClampHighLights;
500 
501                 /* Please see man pages for details
502 
503 
504 
505                 */
506                 /*
507                  * If this flag is set to "true",
508                  * if layer config is set to use D0, lookup table values are applied to the "distribution 0" term.
509                  * If layer config is not set to use D0, 1 is used.
510                  * If this flag is set to "false", 0 is used, regardless of the layer config settings.
511                  * The default value is "false".
512                  */
513                 bool                         isEnableLutD0;
514 
515                 /* Please see man pages for details
516 
517 
518 
519                 */
520                 /*
521                  * If this flag is set to "true",
522                  *If layer config is set to use D1, lookup table values are applied to the "distribution 1" term.
523                  * if layer config is not set to use D1, 1 is used.
524                  * If this flag is set to "false", 0 is used, regardless of the layer config settings.
525                  * The default value is "false".
526                  */
527                 bool                         isEnableLutD1;
528 
529                 /* Please see man pages for details
530 
531 
532 
533                 */
534                 /*
535                  * If this flag is set to "true",
536                  *if layer config is set to use RR, RG, and RB, then lookup table values are applied to the respective "reflection" terms.
537                  * if layer config is not set to use RR, RG, and RB, then 1 is used.
538                  * If this flag is set to "false", 0 is used, regardless of the layer config settings.
539                  * The default value is "true".
540                  */
541 
542                 bool                         isEnableLutRefl;
543                 NN_PADDING2;
544 
545 
546 
547                 /* Please see man pages for details
548 
549                 */
550                 class LutConfig
551                 {
552                 public :
553                     /* Please see man pages for details
554 
555 
556                     */
557                     /*
558                      Any of the following values can be set.
559                      PICA_DATA_FRAG_LIGHT_ENV_NH_DMP
560                      PICA_DATA_FRAG_LIGHT_ENV_VH_DMP
561                      PICA_DATA_FRAG_LIGHT_ENV_NV_DMP
562                      PICA_DATA_FRAG_LIGHT_ENV_LN_DMP
563                      PICA_DATA_FRAG_LIGHT_ENV_SP_DMP
564                      PICA_DATA_FRAG_LIGHT_ENV_CP_DMP
565 
566                      */
567                     PicaDataFragLightEnvLutInput input;
568 
569                     /* Please see man pages for details
570 
571 
572                     */
573                     /*
574                      * Set to "true" to set the lookup table argument range to [0, 1]. Set to "false" to set the range to [-1, 1].
575                      */
576                     bool isAbs;
577 
578                     /* Please see man pages for details
579 
580                            
581                      */
582                     PicaDataFragLightEnvLutScale scale;
583 
584                     NN_PADDING1;
585 
586                     /* Please see man pages for details
587 
588                     */
589                     explicit LutConfig();
590                 };
591 
592                 /* Please see man pages for details
593 
594 
595                 */
596                 LutConfig lutConfigD0;
597 
598                 /* Please see man pages for details
599 
600 
601                 */
602                 LutConfig lutConfigD1;
603 
604                 /* Please see man pages for details
605 
606 
607                 */
608                 LutConfig lutConfigSP;
609 
610                 /* Please see man pages for details
611 
612 
613                 */
614                 LutConfig lutConfigFR;
615 
616                 /* Please see man pages for details
617 
618 
619                 */
620                 LutConfig lutConfigRB;
621 
622                 /* Please see man pages for details
623 
624 
625                 */
626                 LutConfig lutConfigRG;
627 
628                 /* Please see man pages for details
629 
630 
631                 */
632                 LutConfig lutConfigRR;
633 
634             public :
635                 /* Please see man pages for details
636 
637                 */
638                 FragmentLight();
639 
640                 /* Please see man pages for details
641 
642 
643 
644 
645 
646                  */
647                 bit32* MakeLightSourceCommand( bit32* command ) const;
648 
649                 /*
650 
651 
652 
653 
654 
655 */
656                 bit32* MakeLutConfigCommand( bit32* command ) const;
657 
658                 /* Please see man pages for details
659 
660 
661 
662 
663 
664 
665 */
666                 bit32* MakeLightEnvCommand( bit32* command, bool isAddDummyCommand = true ) const;
667 
668                 /* Please see man pages for details
669 
670 
671 
672 
673 
674 
675                  */
676                 bit32* MakeAllCommand( bit32* command, bool isAddDummyCommand = true ) const;
677 
678                 /* Please see man pages for details
679 
680 
681 
682 
683 
684 
685                  */
686                 static bit32* MakeDisableCommand( bit32* command, bool isAddDummyCommand = true );
687             };
688 
689         } // namespace CTR
690     } // namespace gr
691 } // namespace nn
692 
693 #endif // NN_GR_FRAGMENT_LIGHT_H_
694