Advertising (This ad goes away for registered users. You can Login or Register)

Shadow volumes

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Post Reply
Mills
Posts: 31
Joined: Sat Aug 02, 2014 10:09 am

Shadow volumes

Post by Mills » Sat May 28, 2016 10:47 am

I managed to make simple shadows with pspsdk.

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);
	
	.. :)
Image

Image
Advertising
Last edited by Mills on Sun May 29, 2016 4:27 pm, edited 1 time in total.

Mills
Posts: 31
Joined: Sat Aug 02, 2014 10:09 am

Re: Shadow volumes

Post by Mills » Sun May 29, 2016 4:13 pm

Well I solved myself, i'll edit the first post in case someone want to know how this is made.
Advertising

User avatar
Malachi
Posts: 131
Joined: Fri Feb 11, 2011 10:28 pm

Re: Shadow volumes

Post by Malachi » Tue May 31, 2016 4:16 pm

Any chance on releasing this:
Would really like to test your work!

Post Reply

Return to “Programming and Security”