Commit 976b62fc authored by engineer_apple's avatar engineer_apple

Burningvideo - add Stencil Shadow Rendering (one color only and 32 bit only),...

Burningvideo - add Stencil Shadow Rendering (one color only and 32 bit only), pushed Burningvideo to 0.47

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3337 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2a8461a4
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Changes in 1.7.1 (05.07.2010) TA Changes in 1.7.1 (05.07.2010) TA
- BurningVideo - BurningVideo
- add Normalmap Rendering ( one light only), pushed Burningvideo to 0.46 - add Normalmap Rendering ( one light only), pushed Burningvideo to 0.46
- add Stencil Shadow Rendering (one color only and 32 bit only), pushed Burningvideo to 0.47
- internal vertexformat changed - internal vertexformat changed
- changed fixpoint from 9 to 10 bit fract resolution - changed fixpoint from 9 to 10 bit fract resolution
- renamed createBurningVideoDriver to createBurningVideoDriver and uses SIrrlichtCreationParameters like opengl - renamed createBurningVideoDriver to createBurningVideoDriver and uses SIrrlichtCreationParameters like opengl
......
...@@ -25,7 +25,6 @@ using namespace irr; ...@@ -25,7 +25,6 @@ using namespace irr;
int main() int main()
{ {
// ask if user would like shadows // ask if user would like shadows
/*
char i; char i;
printf("Please press 'y' if you want to use realtime shadows.\n"); printf("Please press 'y' if you want to use realtime shadows.\n");
...@@ -37,9 +36,7 @@ int main() ...@@ -37,9 +36,7 @@ int main()
video::E_DRIVER_TYPE driverType=driverChoiceConsole(); video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT) if (driverType==video::EDT_COUNT)
return 1; return 1;
*/
video::E_DRIVER_TYPE driverType = video::EDT_BURNINGSVIDEO;// video::EDT_DIRECT3D9; // video::EDT_BURNINGSVIDEO; // video::EDT_OPENGL; //video::EDT_BURNINGSVIDEO;
bool shadows = true;
/* /*
Create device and exit if creation failed. We make the stencil flag Create device and exit if creation failed. We make the stencil flag
......
...@@ -63,7 +63,7 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows, ...@@ -63,7 +63,7 @@ bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows,
box->addItem(L"OpenGL 1.5"); box->addItem(L"OpenGL 1.5");
box->addItem(L"Direct3D 8.1"); box->addItem(L"Direct3D 8.1");
box->addItem(L"Direct3D 9.0c"); box->addItem(L"Direct3D 9.0c");
box->addItem(L"Burning's Video 0.46"); box->addItem(L"Burning's Video 0.47");
box->addItem(L"Irrlicht Software Renderer 1.0"); box->addItem(L"Irrlicht Software Renderer 1.0");
box->setSelected(selected); box->setSelected(selected);
......
...@@ -3443,7 +3443,9 @@ void COpenGLDriver::drawStencilShadowVolume(const core::vector3df* triangles, s3 ...@@ -3443,7 +3443,9 @@ void COpenGLDriver::drawStencilShadowVolume(const core::vector3df* triangles, s3
glPopAttrib(); glPopAttrib();
} }
//! Fills the stencil shadow with color. After the shadow volume has been drawn
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
//! to draw the color of the shadow.
void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor leftUpEdge, void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor leftUpEdge,
video::SColor rightUpEdge, video::SColor leftDownEdge, video::SColor rightDownEdge) video::SColor rightUpEdge, video::SColor leftDownEdge, video::SColor rightDownEdge)
{ {
......
This diff is collapsed.
...@@ -159,6 +159,7 @@ namespace video ...@@ -159,6 +159,7 @@ namespace video
virtual core::dimension2du getMaxTextureSize() const; virtual core::dimension2du getMaxTextureSize() const;
virtual IDepthBuffer * getDepthBuffer () { return DepthBuffer; } virtual IDepthBuffer * getDepthBuffer () { return DepthBuffer; }
virtual IStencilBuffer * getStencilBuffer () { return StencilBuffer; }
protected: protected:
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// define render case // define render case
#define SUBTEXEL #define SUBTEXEL
#define INVERSE_W //#define INVERSE_W
#define USE_ZBUFFER #define USE_ZBUFFER
#define USE_SBUFFER #define USE_SBUFFER
...@@ -85,10 +85,15 @@ public: ...@@ -85,10 +85,15 @@ public:
//! draws an indexed triangle list //! draws an indexed triangle list
virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c );
virtual void setParam ( u32 index, f32 value);
private: private:
void scanline (); // fragment shader
typedef void (CTRStencilShadow::*tFragmentShader) ();
void fragment_zfail_decr ();
void fragment_zfail_incr ();
tFragmentShader fragmentShader;
sScanConvertData scan; sScanConvertData scan;
sScanLineData line; sScanLineData line;
...@@ -108,9 +113,30 @@ CTRStencilShadow::CTRStencilShadow(CBurningVideoDriver* driver) ...@@ -108,9 +113,30 @@ CTRStencilShadow::CTRStencilShadow(CBurningVideoDriver* driver)
/*! /*!
*/ */
void CTRStencilShadow::scanline () void CTRStencilShadow::setParam ( u32 index, f32 value)
{
u32 val = (u32) value;
// glStencilOp (fail,zfail,zpass
if ( index == 1 && val == 1 )
{
fragmentShader = &CTRStencilShadow::fragment_zfail_incr;
}
else
if ( index == 1 && val == 2 )
{
fragmentShader = &CTRStencilShadow::fragment_zfail_decr;
}
}
/*!
*/
void CTRStencilShadow::fragment_zfail_decr ()
{ {
tVideoSample *dst; //tVideoSample *dst;
#ifdef USE_ZBUFFER #ifdef USE_ZBUFFER
fp24 *z; fp24 *z;
...@@ -204,7 +230,7 @@ void CTRStencilShadow::scanline () ...@@ -204,7 +230,7 @@ void CTRStencilShadow::scanline ()
#endif #endif
#endif #endif
dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; //dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#ifdef USE_ZBUFFER #ifdef USE_ZBUFFER
z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
...@@ -230,24 +256,167 @@ void CTRStencilShadow::scanline () ...@@ -230,24 +256,167 @@ void CTRStencilShadow::scanline ()
if ( line.z[0] < z[i] ) if ( line.z[0] < z[i] )
#endif #endif
#ifdef CMP_W #ifdef CMP_W
if ( line.w[0] >= z[i] ) if ( line.w[0] < z[i] )
#endif #endif
{ {
#ifdef INVERSE_W // zfail
inversew = fix_inverse32 ( line.w[0] ); stencil[i] -= 1;
}
#ifdef IPOL_Z
line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
line.c[0][0] += slopeC[0];
#endif
#ifdef IPOL_T0
line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_T1
line.t[1][0] += slopeT[1];
#endif
#ifdef IPOL_T2
line.t[2][0] += slopeT[2];
#endif
#ifdef IPOL_L0
line.l[0][0] += slopeL[0];
#endif
}
}
/*!
*/
void CTRStencilShadow::fragment_zfail_incr ()
{
//tVideoSample *dst;
#ifdef USE_ZBUFFER
fp24 *z;
#endif
#ifdef USE_SBUFFER
u32 *stencil;
#endif
s32 xStart;
s32 xEnd;
s32 dx;
#ifdef SUBTEXEL
f32 subPixel;
#endif
#ifdef IPOL_Z
f32 slopeZ;
#endif
#ifdef IPOL_W
fp24 slopeW;
#endif
#ifdef IPOL_C0
sVec4 slopeC[MATERIAL_MAX_COLORS];
#endif
#ifdef IPOL_T0
sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif
#ifdef IPOL_L0
sVec3 slopeL[BURNING_MATERIAL_MAX_TANGENT];
#endif
// apply top-left fill-convention, left
xStart = core::ceil32( line.x[0] );
xEnd = core::ceil32( line.x[1] ) - 1;
dx = xEnd - xStart;
#else if ( dx < 0 )
return;
// slopes
const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );
#ifdef IPOL_Z
slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T0
slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif
#ifdef IPOL_T2
slopeT[2] = (line.t[2][1] - line.t[2][0]) * invDeltaX;
#endif
#ifdef IPOL_L0
slopeL[0] = (line.l[0][1] - line.l[0][0]) * invDeltaX;
#endif #endif
dst[i] = 0xFFFFFFFF; #ifdef SUBTEXEL
subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
line.c[0][0] += slopeC[0] * subPixel;
#endif
#ifdef IPOL_T0
line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
line.t[1][0] += slopeT[1] * subPixel;
#endif
#ifdef IPOL_T2
line.t[2][0] += slopeT[2] * subPixel;
#endif
#ifdef IPOL_L0
line.l[0][0] += slopeL[0] * subPixel;
#endif
#endif
//dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#ifdef WRITE_Z #ifdef USE_ZBUFFER
z[i] = line.z[0]; z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif #endif
#ifdef WRITE_W
z[i] = line.w[0]; #ifdef USE_SBUFFER
stencil = (u32*) Stencil->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif #endif
#ifdef INVERSE_W
f32 inversew;
#endif
#ifdef IPOL_C0
tFixPoint r3, g3, b3;
#endif
for ( s32 i = 0; i <= dx; i++ )
{
#ifdef CMP_Z
if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
if ( line.w[0] < z[i] )
#endif
{
// zfail
stencil[i] += 1;
} }
#ifdef IPOL_Z #ifdef IPOL_Z
...@@ -485,7 +654,7 @@ void CTRStencilShadow::drawTriangle ( const s4DVertex *a,const s4DVertex *b,cons ...@@ -485,7 +654,7 @@ void CTRStencilShadow::drawTriangle ( const s4DVertex *a,const s4DVertex *b,cons
#endif #endif
// render a scanline // render a scanline
scanline (); (this->*fragmentShader) ();
scan.x[0] += scan.slopeX[0]; scan.x[0] += scan.slopeX[0];
scan.x[1] += scan.slopeX[1]; scan.x[1] += scan.slopeX[1];
...@@ -693,7 +862,7 @@ void CTRStencilShadow::drawTriangle ( const s4DVertex *a,const s4DVertex *b,cons ...@@ -693,7 +862,7 @@ void CTRStencilShadow::drawTriangle ( const s4DVertex *a,const s4DVertex *b,cons
#endif #endif
// render a scanline // render a scanline
scanline (); (this->*fragmentShader) ();
scan.x[0] += scan.slopeX[0]; scan.x[0] += scan.slopeX[0];
scan.x[1] += scan.slopeX[1]; scan.x[1] += scan.slopeX[1];
......
...@@ -39,6 +39,11 @@ namespace video ...@@ -39,6 +39,11 @@ namespace video
DepthBuffer = (CDepthBuffer*) driver->getDepthBuffer (); DepthBuffer = (CDepthBuffer*) driver->getDepthBuffer ();
if ( DepthBuffer ) if ( DepthBuffer )
DepthBuffer->grab(); DepthBuffer->grab();
Stencil = (CStencilBuffer*) driver->getStencilBuffer ();
if ( Stencil )
Stencil->grab();
} }
...@@ -51,6 +56,9 @@ namespace video ...@@ -51,6 +56,9 @@ namespace video
if (DepthBuffer) if (DepthBuffer)
DepthBuffer->drop(); DepthBuffer->drop();
if (Stencil)
Stencil->drop();
for ( u32 i = 0; i != BURNING_MATERIAL_MAX_TEXTURES; ++i ) for ( u32 i = 0; i != BURNING_MATERIAL_MAX_TEXTURES; ++i )
{ {
if ( IT[i].Texture ) if ( IT[i].Texture )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment