No worries
Here is some code that requires no media(other than the stencilshadow.fx file to be present in the project folder)
It shows 3 real-time stencil shadows, cast using ONE light and render targets, with the light being re-positioned between syncs.
Let me state that this code isnt mine. I originally pulled it in DarkBasic Pro form from the snippets database(or somewhere in these forums)
It uses a sprite as its render target, which as you will see isnt the best way of doing it( a textured 3D object would be better ), but this way is simple and it works to demonstrate the technique.
#include "DarkGDK.h"
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
void dbSetShadowShadingOn ( int iID, int iMesh, int iRange, int iUseShader );
void dbSetShadowPosition ( int iMode, float fX, float fY, float fZ );
bool SetNewObjectFinalProperties( int iID, float fRadius ); // this is an undocumented GDK command for setting object
// properties. Used in conjunction with CreateNewObject();
// Its only here as I was experimenting with stuff
int __cdecl dbCameraExist(int);
// whenever using Dark GDK you must ensure you include the header file
typedef struct t_Lights
{
float xpos;
float ypos;
float zpos;
int ColorR;
int ColorG;
int ColorB;
float Range;
int CameraID;
int ImageID;
} _Light;
_Light lightarray[12];
void add_Shadow_Light(int ID, float xpos, float ypos, float zpos, int r, int g, int b, float range);
static int g_ireturnVal = 0;
static int g_iRet = 0;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn();
dbSyncRate(0);
dbSetDisplayMode(1024, 768, 32);
dbAutoCamOff();
dbColorBackdrop(0);
dbSetAmbientLight(25);
dbSetNormalizationOn();
dbSetGlobalShadowsOn();
dbSetGlobalShadowShades(1);
dbSetPointLight(0, 0.0, 0.0, 0.0);
//` make floor
dbMakeMatrix(1, 2000, 2000, 100, 100);
dbPositionMatrix(1, -1000, 0, -1000);
dbSetMatrixWireframeOff(1);
//` make object to cast shadow
dbMakeObjectCube(1, 100);
dbPositionObject(1, 100, 50, 100);
dbSetShadowShadingOn(1, -1, 500, 1);
dbMakeObjectSphere(2, 100, 25, 25);
dbPositionObject(2, -250, 50, -250);
dbSetShadowShadingOn(2, -1, 500, 1);
dbMakeObjectCube(5, 150);
dbPositionObject(5, 300, 155, 120);
dbSetShadowShadingOn(5, -1, 500, 1);
//` lights
//GoSub setup
add_Shadow_Light(0, 500, 100, 500, 255, 0, 0, 600 );
add_Shadow_Light(1, 424, 150, -424, 0, 255, 0, 800 );
add_Shadow_Light(2, -182, 429, 120, 0, 0, 255, 800 );
//` camera
dbPositionCamera(-200, 100, -200);
char* tb;
char* tbb;
float increaser = 0.00;
while ( LoopGDK ( ) )
{
// ` camera
dbMoveCamera((dbUpKey()-dbDownKey())*6.0);
dbRotateCamera(dbCameraAngleX() + dbMouseMoveY(), dbCameraAngleY() + dbMouseMoveX(), 0.0);
//` object 2
increaser += 0.5;
dbPositionObject(2, dbObjectPositionX(2) + (dbSin(increaser) * 5), 50, dbObjectPositionZ(2) + (dbCos(increaser) * 5));
//` lights
for(int a = 0; a <= 2; a++) // To Array Count(Light(0))
{
dbRotateCamera(lightarray[a].CameraID, dbCameraAngleX(), dbCameraAngleY(), dbCameraAngleZ());
dbPositionCamera(lightarray[a].CameraID, dbCameraPositionX(), dbCameraPositionY(), dbCameraPositionZ());
dbColorLight(0, lightarray[a].ColorR, lightarray[a].ColorG, lightarray[a].ColorB);
dbPositionLight(0, lightarray[a].xpos, lightarray[a].ypos, lightarray[a].zpos);
dbSetLightRange(0, lightarray[a].Range);
dbSetShadowPosition( -1, lightarray[a].xpos, lightarray[a].ypos, lightarray[a].zpos);
if(a == 0)
{
dbSyncMask(1 << 1);
//dbSyncCamera(1);
}
if(a == 1)
{
dbSyncMask(1 << 2);
//dbSyncCamera(2);
}
if(a == 2)
{
dbSyncMask(1 << 3);
//dbSyncCamera(3);
}
dbFastSync();
}//next a
dbSyncMask(1 << 0); // 2^0
// ` debug
tb = new char[256];
tbb = new char[256];
strcpy(tb, "Screen FPS : ");
strcat(tb, dbStr(dbScreenFPS()));
dbSetCursor(0, 0);
dbPrint(tb);
strcpy(tbb, dbStr(dbCameraPositionX()));
strcat(tbb, " // ");
strcat(tbb, dbStr(dbCameraPositionY()));
strcat(tbb, " // ");
strcat(tbb, dbStr(dbCameraPositionZ()));
dbPrint(tbb);
for(int x = 0; x <= 2; x++)
{
dbSprite(lightarray[x].ImageID, 0, 0, lightarray[x].ImageID);
dbSizeSprite(lightarray[x].ImageID, dbScreenWidth(), dbScreenHeight());
dbSetSpriteAlpha(lightarray[x].ImageID, 127.5);
}//Next x
// update the screen
dbSync();
delete []tb;
delete []tbb;
}
// return back to windows
return;
}
void add_Shadow_Light(int ID, float xpos, float ypos, float zpos, int r, int g, int b, float range)
{
//Array Insert At Bottom Light(0)
int pos = ID; //Array Count(lightarray(0))
lightarray[pos].xpos = xpos;
lightarray[pos].ypos = ypos;
lightarray[pos].zpos = zpos;
lightarray[pos].ColorR = r;
lightarray[pos].ColorG = g;
lightarray[pos].ColorB = b;
lightarray[pos].Range = range;
lightarray[pos].CameraID = ID+1;//FindFreeCamera();
lightarray[pos].ImageID = ID+1;//FindFreeImage();
dbMakeCamera(lightarray[pos].CameraID);
dbSetCameraRange(lightarray[pos].CameraID, 10, 20000);
dbSetCameraToImage(lightarray[pos].CameraID, lightarray[pos].ImageID, 512, 512);
}; //EndFunction
and here is a compiled and running EXE so you can see what it does(I threw the stencilshadow.fx file in the archive aswell incase you cant find it)
If it ain't broke.... DONT FIX IT !!!