*ptr | Pointer to light source |
func | Pointer for callback function |
In principle, with the exception of NJS_ARGB of the first parameter, do not rewrite user light source parameters.
Use the first parameter as NJS_ARGB argb[2].
However, the setup value is different when the user function is reflected in njDrawObject() and njFastDrawObject() functions.
When multiple light sources are, sum up each element of the first parameter. If this is not done, all light source function effects before this function is called will be ineffective.
<In the case of njDrawObject()>
Set as NJS_ARGB argb[2].
argb[0].a argb[0].r argb[0].g argb[0].b : Diffuse
argb[1].a argb[1].r argb[1].g argb[1].b : Specula
Basic setting of callback function:
func(NJS_ARGB* argb, NJS_POINT3* pnt, NJS_VECTOR* nml, NJS_LIGHT* lt)
{
NJS_ARGB dif, spc;
/* Light source calculation */
argb[0].a += dif.a;
argb[0].r += dif.r;
argb[0].g += dif.g;
argb[0].b += dif.b;
/*argb[1].a += spc.a;*/
argb[1].r += spc.r;
argb[1].g += spc.g;
argb[1].b += spc.b;
}
<In the case of njFastDrawObject()>
Only a,r elements of NJS_ARGB argb[0] are set. ( = Float intensity[2])
argb[0].a : Diffuse
argb[0].r : Specula
Basic setting of callback function:
func(NJS_ARGB* argb, NJS_POINT3* pnt, NJS_VECTOR* nml, NJS_LIGHT* lt)
{
Float dif, spc;
/* Light source calculation */
argb[0].a += dif.a;
argb[0].r += dif.r;
}
#include <Shinobi.h> : NJS_LIGHT light; void func(NJS_ARGB* argb, NJS_POINT3* pnt, NJS_VECTOR* nml, NJS_LIGHT* lt) { : /* Example of internal results of normal polygon line and light direction */ deg = - nml->x * NJM_LIGHT_VECTOR(lt). x - nml->y * NJM_LIGHT_VECTOR(lt).y - nml->z * NJM_LIGHT_VECTOR(lt).z; : /* argb */ if (deg > 0.f) { argb[0].a += deg * deg * NJM_LIGHT_SPC(lt).a; argb[1].r += deg * deg * NJM_LIGHT_SPC(lt).r; argb[1].g += deg * deg * NJM_LIGHT_SPC(lt).g; argb[1].b += deg * deg * NJM_LIGHT_SPC(lt).b; argb[0].r += deg * NJM_LIGHT_DIF(lt).r; argb[0].g += deg * NJM_LIGHT_DIF(lt).g; argb[0].b += deg * NJM_LIGHT_DIF(lt).b; } } void njUserInit(void) { : sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1); njCreateLight(&light, NJD_USER_LIGHT); /* Set user function, func, for light "lt" */ njSetUserLight (&light, func); : }
Light functions created by users and macros used in them are as shown below.
1. Callback function
<format>
func( *argb, *pnt, *nml, *ptr)
NJS_ARGB *argb
NJS_POINT3 *pnt
NJS_VECTOR *nml
NJS_LIGHT *ptr
<parameter>
*argb | Pointer for completed operation |
*pnt | Pointer to polygon location vector |
*nml | Pointer to polygon normal line vector |
*ptr | Light pointer set by njCreateLight() |
2. Macro (at the time of NJS_LIGHT *ptr)
<NJM_LIGHT_VECTOR(ptr)>
Light current direction: NJS_VECTOR. To be refered to as NJM_LIGHT_VECTOR(ptr).x.
<NJM_LIGHT_POINT(ptr)>
Light current location: NJS_POINT3. To be refered to as NJM_LIGHT_POINT(ptr).x.
<NJM_LIGHT_AMB(ptr)>
Environment light intensity: At NJS_ARGB, the value is generally 0-1.f. (However, the value could be more than 1.f.) To be refered to as NJM_LIGHT_AMB(ptr).r.
<NJM_LIGHT_DIF(ptr)>
Diffuse light intensity: At NJS_ARGB, the value is generally 0-1.f. (However, the value could be more than 1.f.) To be refered to as NJM_LIGHT_DIF(ptr).r.
<NJM_LIGHT_SPC(ptr)>
Specula light intensity: At NJS_ARGB, the value is generally 0-1.f. (However, the value could be more than 1.f.) To be refered to as NJM_LIGHT_SPC(ptr).r.
<NJM_LIGHT_EXP(ptr)>
Exponent: Int is a part of the object data information. The width of the specula is calculated from this. The table for compatibility with SOFTIMAGE is indicated below.
NINJA | SOFTIMAGE |
0 | 0 |
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 6 |
6 | 8 |
7 | 12 |
8 | 16 |
9 | 24 |
10 | 32 |
11 | 48 |
12 | 64 |
13 | 96 |
14 | 128 |
15 | 192 |
16 | 256 |
<NJM_LIGHT_COLOR(ptr)>
Light color: NJS_ARGB. Light color is calculated.
<NJM_LIGHT_INIT_VECTOR(ptr)>
Direction prior to light matrix calculation: NJS_VECTOR. This is the initial direction prior to matrix calculation.
<NJM_LIGHT_INIT_POINT(ptr)>
Position before light matrix calculation: NJS_POINT3. This is the initial position before matrix calculation.
<NJM_LIGHT_MATRIX(ptr)>
Light matrix: NJS_MATRIX. This is the light matrix.