Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 10:52:30 pm
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)Shadow Casting
Pages: 1 [2] 3
Print
Author Topic: Shadow Casting  (Read 5230 times)
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #15 on: 20. June 2007, 02:15:57 pm »

Ok. So, it will work with UV?
Yeah. Look at the code example I posted.
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #16 on: 20. June 2007, 05:54:07 pm »

Well.. thats what i did.. is the way i did that correct or is there a bug in my code? Or is the Occluder method not working well?
I dont know how volume shadows are working in detail. Each polygon which is not visible will be extruded on a path with a direction away from the light.
But wouldnt it be much more efficent if i just use the visible outer and inner edges? That shadowvolume would have less geometry.   
Yeah, certainly. Are you going to write that ?
Hey, check this out:
http://www.gamedev.net/reference/articles/article1873.asp
Scroll down about two-fifths of the way, to the heading "Silhouette Determination".

So, it seems that the only edges that need to be extruded for the shadow volume are the ones which border both a face pointing away from the light on one side, and towards the light on the other.  Using the dot-product, this is very possible...is there a dot-product method for IndexedTriangleStripArray?
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #17 on: 21. June 2007, 03:58:36 pm »

The Gamasutra article they talk about looks particularly interesting :
http://www.gamasutra.com/features/20021011/lengyel_01.htm

Though it's complicated.. (well, IMHO Smiley ... @Marvin Wink yeah shadows *are* complicated)
Logged
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #18 on: 01. July 2007, 02:38:20 pm »

Im still working on shadowcasting. I hope ill finish everything on-time.
Ah, very cool. Any results yet ?
Logged
Jotschi
Enjoying the stay
*
Offline Offline

Posts: 55



View Profile
« Reply #19 on: 03. July 2007, 11:23:49 pm »

My method for determin the silhouette of an object is nearly done. But i think it is very slow and the code looks very bad. 
Logged
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #20 on: 04. July 2007, 02:29:41 pm »

My method for determin the silhouette of an object is nearly done. But i think it is very slow and the code looks very bad. 
Great ! Maybe you can optimize later Smiley
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #21 on: 05. July 2007, 05:18:41 pm »

Very cool. Maybe you want dev-rights on xith3d/xith-tk? Then you can check-in the code. But please don't do it today, since I have some real big changes, that I will finish today and then checkin. I could not connect to the internet during the last three days because of ISP problems caused by the weather. So All my last days changes are still only locally and have to be committed and I want to avoid conflicts.

Marvin
Logged
david yazel
Xith3D GOD (yes, he is)
Just dropped in
*********
Offline Offline

Posts: 2



View Profile WWW Email
« Reply #22 on: 06. July 2007, 06:49:40 pm »

Hi all.  Amos wrote and said you guys were stuck on the shadow implementation.  This is what I wrote him:

Quote
Regarding shadows. As you probably know there are many different shadow algorithms and frankly I have not given it a ton of thought in all this time. The basic algorithm calls for occluders to be placed in the scene graph that have a representative shape roughly the size of the shape casting the shadow. We are using the stencil buffer for these shadows and it is a projection of the occluders geometry into the stencel buffer and then a basic black drawing where the stencil is set. It is the most primitive of the shadowing systems and cannot generate objects that self shadow and it cannot generate soft shadowing. It also has a restriction that the object being shadowed (usually an occluder) must be a closed polygon, with no gaps. The generator I wrote can calculate a default occluder for any set of points and if an occluder is not provided my code will create one of these representations. Shadowing was working, within these restrictions, when I left the project. What exactly is no longer working?


I seem to remember that there was a basic way to enable/disable shadowing.  It was very obvious in the rendering code where the shadow pass was.  I might have to check out the code and see what the renderer looks like nowadays.  Is it possible that people just refactored the shadow rendering code right out of the code base?  I also know at one time there was a standard demo that showed shadowing.
Logged
david yazel
Xith3D GOD (yes, he is)
Just dropped in
*********
Offline Offline

Posts: 2



View Profile WWW Email
« Reply #23 on: 06. July 2007, 07:03:42 pm »

I just checked the code in the 0.9 release.  Shadow support is all still there, al least in the open GL version of CanvasPeerImpl.

In the renderMain method there is a line:
Code:
// render shadows if there are any occluders
 1050         if ((!isPickMode()) && ((shotCreator == null) || (shotCreator.getFormat() == ScreenshotCreator.Format.RGB)) && (binProvider.getShadowsBin().size() > 0) && (renderingOptions.getOption(Option.USE_SHADOWS)) )
 1051         {
 1052             drawShadows( binProvider.getShadowsBin() );
 1053         }

So in your test make sure you have the USE_SHADOWS rendering options.  If you are already way past such simplistic solutions then let me know.  The shadow rendering code is really standard, I probably stole it from carmack.

Here is the guts:

Code:
   /**
  404      * draws the shadow volumns in the render bin
  405      * @param bin
  406      */
  407     private final void drawShadows(ShadowBin bin)
  408     {
  409         ProfileTimer.startProfile( "CanvasPeerImpl::drawShadows" );
  410         final int FULLMASK = 0xffffffff;
  411         final int STENCIL_VAL = 128;
  412
  413         // determine edges
  414         for (int i = 0; i < bin.size(); i++)
  415         {
  416             bin.getOccluder(i).determineVisibleEdges( bin.getLightSource() );
  417         }
  418
  419         GL11.glPushAttrib( GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT |
  420                            GL11.GL_ENABLE_BIT | GL11.GL_POLYGON_BIT |
  421                            GL11.GL_STENCIL_BUFFER_BIT );
  422
  423         GL11.glPushMatrix();
  424         GL11.glLoadIdentity();
  425         GL11.glDisable( GL11.GL_LIGHTING ); // turn off Lighting
  426         GL11.glDisable( GL11.GL_TEXTURE_2D );
  427         GL11.glDisable( GL12.GL_TEXTURE_3D );
  428         GL11.glDisable( GL11.GL_BLEND );
  429         GL11.glStencilFunc( GL11.GL_NEVER, 0xff, FULLMASK );
  430
  431         GL11.glDepthMask( true );
  432         GL11.glDepthFunc( GL11.GL_LEQUAL );
  433         GL11.glEnable( GL11.GL_DEPTH_TEST );
  434
  435         GL11.glPopMatrix();
  436
  437         GL11.glColor3f( 1f, 0f, 0f );
  438         GL11.glClearStencil( STENCIL_VAL );
  439         GL11.glClear( GL11.GL_STENCIL_BUFFER_BIT );
  440
  441         GL11.glDisable( GL11.GL_LIGHTING ); // turn off Lighting
  442
  443         GL11.glFrontFace( GL11.GL_CCW );
  444         GL11.glEnable( GL11.GL_CULL_FACE );
  445         GL11.glCullFace( GL11.GL_FRONT );
  446
  447         GL11.glDepthMask( false ); // turn off writing to the Depth-Buffer
  448         GL11.glDepthFunc( GL11.GL_LEQUAL );
  449         GL11.glEnable( GL11.GL_DEPTH_TEST );
  450         GL11.glEnable( GL11.GL_STENCIL_TEST ); // turn on Stencil-Buffer testing
  451         GL11.glColorMask( false, false, false, false ); // don't draw into the Color-Buffer
  452         GL11.glStencilFunc( GL11.GL_ALWAYS, STENCIL_VAL, FULLMASK );
  453
  454         // First Pass. Increase Stencil Value In The Shadow
  455         GL11.glStencilOp( GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_INCR );
  456
  457         for (int i = 0; i < bin.size(); i++) {
  458             drawObjectShadow( bin.getOccluder( i ), bin.getLightSource() );
  459         }
  460
  461         // Second Pass. Decrease Stencil Value In The Shadow
  462         GL11.glCullFace( GL11.GL_BACK );
  463         GL11.glStencilOp( GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_DECR );
  464
  465         GL11.glColor3f(0.5f, 0.5f, 0f);
  466         for (int i = 0; i < bin.size(); i++)
  467         {
  468             drawObjectShadow( bin.getOccluder(i), bin.getLightSource() );
  469         }
  470
  471         GL11.glColorMask( true, true, true, true ); // enable rendering to Color-Buffer for all components
  472
  473         // Draw A Shadowing RectanGL11.gle Covering The Entire Screen
  474         GL11.glColor4f( 0.0f, 0.0f, 0.0f, 0.4f );
  475         GL11.glEnable( GL11.GL_BLEND );
  476         GL11.glEnable( GL11.GL_DEPTH_TEST );
  477         GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
  478
  479         // get rid of the view matrix, only have the projection matrix
  480
  481         GL11.glMatrixMode( GL11.GL_PROJECTION );
  482         GL11.glLoadIdentity();
  483         view.getProjection().get( trans );
  484         floatBuffer4x4.clear();
  485         floatBuffer4x4.put( trans ).flip();
  486         floatBuffer4x4.rewind();
  487         GL11.glLoadMatrix( floatBuffer4x4 );
  488
  489         GL11.glMatrixMode( GL11.GL_MODELVIEW );
  490         GL11.glPushMatrix();
  491         GL11.glLoadIdentity();
  492
  493         GL11.glDepthMask( false );
  494
  495         GL11.glEnable( GL11.GL_STENCIL_TEST ); // turn on Stencil-Buffer testing
  496         GL11.glStencilFunc( GL11.GL_NOTEQUAL, STENCIL_VAL, FULLMASK );
  497         GL11.glStencilOp( GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP );
  498         GL11.glCullFace( GL11.GL_BACK );
  499         GL11.glDisable( GL11.GL_CULL_FACE );
  500         GL11.glAlphaFunc( GL11.GL_ALWAYS, 0f );
  501
  502         GL11.glBegin( GL11.GL_TRIANGLE_STRIP );
  503         GL11.glVertex3f( -100f, 100f, -2f );
  504         GL11.glVertex3f( -100f, -1000f, -2f );
  505         GL11.glVertex3f( +100f, 100f, -2f );
  506         GL11.glVertex3f( +100f, -1000f, -2f );
  507         GL11.glEnd();
  508
  509         GL11.glPopMatrix();
  510
  511         GL11.glPopAttrib();
  512         ProfileTimer.endProfile();
  513     }

Oh and one last thing, you need at least one DIRECT light source for shadow casting.
« Last Edit: 06. July 2007, 07:05:36 pm by david yazel » Logged
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #24 on: 06. July 2007, 07:21:04 pm »

I also know at one time there was a standard demo that showed shadowing.
One that showed shadowing alone ? Or something included, e.g. in the Quake3 BSP demo ?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #25 on: 06. July 2007, 07:55:31 pm »

Hi, David.

Thank you so much for taking the time to help us Smiley.

Actually we are indeed way past such solutions. The shadow rendering code is still active and the RenderOption to enable shadows is ON by default. There is a convenience method in Canvas3D called enableLighting(), which also enables shadows. And this method is invoked once at Canvas creation time.

I once wrote a simple test case to test shadows, which is in the org.xith3d.test.render package (ShadowsTest). It does use a DirectionalLight (but good to know, that this is required). It unfortunately crashes at occluder creation, which it didn't when I wrote the test. Don't know what happened (certainly my fault Wink). But Jotschi (a user here on xith.org) is currently working on the occluder code, so he will certainly have fixed this bug already.

If you have a bit of time, I would suggest, that you checkout the code from SVN. IIRC the ShadowsTest does not yet exist in the 0.9 release and it is anyway best to track this bug in the latest code base.

I guess, the project was already split into two projects (xith3d and xith-tk) at your days. If not, then you know now Wink.

At a later time we will want to use GLSL or CG for shadow rendering to also support soft- and realistic shadows. But for the 1.0 release we thought, it might be best to get the current volume-shadows implementation working and later replace (optional) it with a more up-to-date one.

Marvin
Logged
'n ddrylliog
Moderator
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #26 on: 06. July 2007, 08:29:27 pm »

Thanks marvin for summing up the situation.
Logged
Jotschi
Enjoying the stay
*
Offline Offline

Posts: 55



View Profile
« Reply #27 on: 06. July 2007, 10:25:19 pm »

I'm still having some (little) trouble with my method for determine all visible edges. There are some edges inside my result set which shouldn't be included. I'm not sure if thats a problem with my method or with the source geometry. As said in another thread i had to swap each second face of for example Sphere. When using GeoSphere swapping each second face isn't needed to get the right face normals. And when you create a Sphere and use a certain number for
slices or/and stacks (don't remember the numbers) you get a vertice count which isn't dividable by 3. (to get the number of polygons)

Thats important for me because my method for determine the visible edges works like that:

1. run through all polygons
2. check if polygon is visible for the light source
3. if visible add all edges of that polygon to a list but:
4. check if the edges you want to add are already inside the list
5. if edge is already inside the list remove it and don't add the edge
6. check next polygon

After that you just get the edges on the silhouette because they don't have a neighbor edge which is visible.

Some words to the old occluder stuff.. the code there seems to be very tidy and efficient but in my mind there were changes to xith how it handles the geometry. The occluder stuff had to generate unique vertice lists by itself but these tasks can be done for example by an IndexedTriangleFanArray and   
Code:
GeomDataInterface data = ( (GeometryArray)os.shape.getGeometry() ).getCoordinateData();

for example returns just a list of unique vertices but a TriangleArray like is assumed.

Please correct me if i'm wrong.




Some pictures:
 




Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #28 on: 06. July 2007, 10:35:00 pm »

Looks very promising.

About the changes in xith: No there are no changes in xith itself about geometry handling. TriangleArray, IndexedTrangleArray, TriangleStripArray, etc. were always there. I simply changed the default Sphere, etc. implementations to use a more efficient XXTriangleYYArray. But if you loaded some kind of model or something like that, you would probably get an IndexedTriangleStripArray as well. That was never different.

Marvin
Logged
Jotschi
Enjoying the stay
*
Offline Offline

Posts: 55



View Profile
« Reply #29 on: 07. July 2007, 04:38:35 pm »

Another one:



Until now its just a workaround. I dont use stencil techniques.
Logged
Pages: 1 [2] 3
Print
Jump to:  

Theme orange-lt created by panic