The process is "simple", you have to generate a cylinder to project a circular shadows:
1- Draw the ground
2- Draw front faces of the cylinder
3- Draw the back faces of the cylinder
4- combine 2 and 3 to get just the circle on the ground, using stencil functions.
Thanks to opengl samples i could made it
Code: Select all
//pseudo code
//Draw the object that will receive the shadow
//Translate, rotate, scale the "ground"
(code)
//Draw the gound
sceGuDrawArray(....
//Translate, rotate, scale the cylinder
//Move it to the position of the object that will cast the shadow
(code)
//1 - Draw Shadow back faces
sceGuEnable(GU_CULL_FACE);
sceGuDisable(GU_TEXTURE_2D);
sceGuDepthMask(GU_TRUE);
sceGuDisable(GU_LIGHTING);
sceGuFrontFace(GU_CW); //draw back faces
sceGuEnable(GU_STENCIL_TEST); // Stencil test
sceGuStencilFunc(GU_ALWAYS, 1, 1); // always set 1 bit in 1 bit mask
sceGuStencilOp(GU_KEEP, GU_KEEP, GU_REPLACE); // keep value on failed test (fail and zfail) and replace on pass
sceGuColor(GU_RGBA(0,0,0,0));
sceGuDrawArray(...
//2- Draw Shadow fron faces
sceGuFrontFace(GU_CCW);
sceGuStencilFunc(GU_EQUAL, 0, 1); // allow drawing where stencil is 1
sceGuStencilOp(GU_KEEP, GU_KEEP, GU_KEEP); // keep the stencil buffer unchanged
sceGuColor(GU_RGBA(0,0,0,alpha));
sceGuDrawArray(...
//Restore drawing to normal
sceGuDisable(GU_STENCIL_TEST);
sceGuDepthMask(GU_FALSE);
sceGuDisable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_LIGHTING);
.. :)
Advertising