Specular light still buggy ??

Post Reply
nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Specular light still buggy ??

Post by nonameno » Mon Apr 12, 2010 7:22 am

here is the way i define my specular :

Code: Select all

                ldir=(guVector){0.0f,0.0f,0.0f};

                guVecMultiplySR(_GRR_view, &ldir,&ldir);
                GX_InitSpecularDirv(&MyLight0, &ldir);

                GX_InitLightShininess(&MyLight0, 10);
                GX_InitLightColor(&MyLight0, (GXColor){0xFF,0xFF,0xFF,0xFF});
                GX_LoadLightObj(&MyLight0, GX_LIGHT0);

                /////////////////////// Turn light ON ////////////////////////////////////////////////
                GX_SetNumChans(1);
                GX_SetChanCtrl(GX_COLOR0, GX_ENABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT0, GX_DF_NONE, GX_AF_SPEC);
                GX_SetChanCtrl(GX_ALPHA0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE);

                GX_SetNumTevStages(1);
                GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
                GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0 );

                GX_SetChanAmbColor(GX_COLOR0, (GXColor){0x00,0x00,0x00,0x00});
                GX_SetChanMatColor(GX_COLOR0, (GXColor){0xE0,0xE0,0xE0,0xE0});
as you can see i specify a STRANGE dirv {0.0f,0.0f,0.0f} that seems stupid for me ;)
but here is the nice no buggy result :
Image

here is a screen shot of a dirv {0.05f, 0.0f, 0.0f}
Image

in fact if i use any other value than {0.0f,0.0f,0.0f} for dirv i always get something buggy as you can see.

Any Help ?

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: Specular light still buggy ??

Post by shagkur » Mon Apr 12, 2010 8:17 am

Hi,

is _GRR_view the View*Model matrix? if so you've, for Light direction vectors, to inverse/transpose it (like you do for the normal matrix) and then mutliply the direction vector to get the real (world view) direction vector.

Example:
guMtxConcat(cam,mode,modelview);
guMtxInverse(modelview,tmp);
guMtxTranspose(tmp,mvinversetranspose);
guVecMultiplySR(mvinversetranspose,&ldir,&wdir);

Also the direction vector _must_ be of positive values for Specular Lights.

regards
shagkur

nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Re: Specular light still buggy ??

Post by nonameno » Mon Apr 12, 2010 9:45 am

hi shagkur ;)

and thx for you fast answer.

i just tested this :

Code: Select all

                ldir=(guVector){0.05f,0.0f,0.0f};

                guMtxInverse(_GRR_view,mr);
                guMtxTranspose(mr,mv);
                guVecMultiplySR(mv, &ldir,&ldir);
                GX_InitSpecularDirv(&MyLight0, &ldir);
same result :/

i bet i just missed something, but i cant understand what ;)

have a look at line 87 -> http://code.google.com/p/grrlib/source/ ... RRLIB_3D.c
here is the way i get _GRR_view

feel free to tell me i am a looser coz i miss this or this ;)

regards,
NoNameNo

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: Specular light still buggy ??

Post by shagkur » Mon Apr 12, 2010 11:04 am

Hi,

well, that's the correct way how you do it. Create the inverse-transpose of the view matrix (at this point i've to correct my previous post, because its NOT the inverse-transpose of the modelview) and the do a vector multiply with the scale/rotate components from the resulting inverse-transpose view matrix.
So to make it short: there's probably a bug in there. i'll have to take a look at it.

While looking at the GRRLib source i figured a little bug in there: line 440, the brightness or to be precisely the reference brightness _must_ be smaller than 1.0f otherwise distance attenuation is turned off.

regards
shagkur

PS: for specularity, ie. specular highlights, there's also the possible approach to do it per pixel rather than per vertex. Which normally leads to better visible results.

nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Re: Specular light still buggy ??

Post by nonameno » Mon Apr 12, 2010 11:14 am

as always fast answer ;)

i'm in mean time happy and not happy ;)
in fact i am happy to see i can finally say i understand how light works in general, but unhappy to see i spent so much time trying to get working specular ;)

heheh i hope getting a patch or a new release of libogc soon with a working specular light ;)

thx also for your info about brightness specification information ;)

like you see i finnaly managed to provide lihghts to grrlib users.

you also said there is a way to get specular effect using a per pixel stuff, any hints to investigate this way ?

regards,
NoNameNo

ps : for info, and for the fun, know that i get the exact same bug under dolphin emu ;)

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: Specular light still buggy ??

Post by shagkur » Mon Apr 12, 2010 4:13 pm

Hi again,

just for a test, could you try the following values for the direction:
{ 90.0f, 45.0f, 45.0f }

regards
shagkur

nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Re: Specular light still buggy ??

Post by nonameno » Mon Apr 12, 2010 4:27 pm

here is the "bad ? " result with the values you asked :
Image

NoNameNo

nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Re: Specular light still buggy ??

Post by nonameno » Thu Apr 15, 2010 11:38 am

Any news ??

Regard
NoNameNo

nonameno
Posts: 8
Joined: Mon Nov 30, 2009 1:20 pm

Re: Specular light still buggy ??

Post by nonameno » Tue Jun 15, 2010 2:11 pm

Shag ?? any news ??

Regards,
NNN

EvilTroopa
Posts: 4
Joined: Thu Jan 20, 2011 1:25 am

Re: Specular light still buggy ??

Post by EvilTroopa » Sat Jan 29, 2011 2:32 am

Sorry for bringing that topic back from the dead !

Just like NoNameNo, I've tried to use GX_InitSpecularDir with GX_InitLightShininess.
I tried to look at Wiirrlicht source code, but you never use GX_AF_SPEC. I assume you found a workaround to render specular lights.

Anyway, the only thing that gives a really nice result is when I give as light direction {0.0f, 0.0f, 0.0f}, but it always looks like the camera is the actual source of light for the specular (just like on NNN's first screenshot above).
GRRLIB specular light demo still uses that null light direction... So NNN doesn't seem to have found a good solution yet.

Here's my code, it's pretty much the same as NoNameNo.

Code: Select all

guVector lpos = {-Scene->lights[0].pos.x, -Scene->lights[0].pos.y, -Scene->lights[0].pos.z}; //I use inverted position as light direction
//guVector lpos = {0.0f, 0.0f, 0.0f};
guVecNormalize(&lpos);

Mtx mr, mv;
GXLightObj MyLight;
guVector wpos;

guMtxInverse(Scene->view, mr);
guMtxTranspose(mr, mv);
guVecMultiplySR(mv, &lpos, &wpos);

GX_InitSpecularDirv(&MyLight, &wpos);
GX_InitLightShininess(&MyLight, 40);
GX_InitLightColor(&MyLight, Scene->lights[0].color);
GX_LoadLightObj(&MyLight, GX_LIGHT2);

GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);

GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);

GX_SetNumChans(2);
GX_SetChanCtrl(GX_COLOR0, GX_ENABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT0 | GX_LIGHT1, GX_DF_CLAMP, GX_AF_NONE);
GX_SetChanCtrl(GX_ALPHA0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE);
GX_SetChanCtrl(GX_COLOR1, GX_ENABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT2, GX_DF_NONE, GX_AF_SPEC);
GX_SetChanCtrl(GX_ALPHA1, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE);

GX_SetNumTexGens(0);

GX_SetNumTevStages(2);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0 );
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
GX_SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR1 );
GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_ONE, GX_CC_CPREV );
GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV );

GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00,0x00,0x00,0xFF});
GX_SetChanMatColor(GX_COLOR1, (GXColor){0xFF, 0xFF, 0xFF, 0xFF});
Thanks ;)
EvilTroopa

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests