Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shadows, Shaders, DisplayLists?  (Read 9511 times)
0 Members and 1 Guest are viewing this topic.
Offline Zer Gut Shnitzel

Senior Newbie





« Posted 2006-12-13 18:07:43 »

Hi,

Can somebody please provide some more information on the following features in relation to the current Xith code

Shadows - I know there is some work being done on this, I would like to know a bit more about how it works (or doesn't work) in the current version, where should I start if I wanna start playing with this feature (where the code is and how is it supposed to work).

Pixel / Vertex Shaders - I have seen some code in CoolDude's demos, is there any addition documentation, planned development, design ideas, or any kind of specific information on how this currently works (supposed to work). I am specifically interested in Per pixel lighting and using the shading language for materials.

Display Lists - Is there any documentation, examples, planned deveopment, etc...

Thanks
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #1 - Posted 2006-12-13 19:13:57 »

Shadows - I know there is some work being done on this, I would like to know a bit more about how it works (or doesn't work) in the current version, where should I start if I wanna start playing with this feature (where the code is and how is it supposed to work).

Don't know. Ask Amos. I haven't used shadows so far.

Pixel / Vertex Shaders - I have seen some code in CoolDude's demos, is there any addition documentation, planned development, design ideas, or any kind of specific information on how this currently works (supposed to work). I am specifically interested in Per pixel lighting and using the shading language for materials.

We also have GLSL shaders. And we have both vertex and pixel shaders. But I haven't worked with them so far. So I can only tell you, they are there.

Display Lists - Is there any documentation, examples, planned deveopment, etc...

Display Lists are used, when a Shape3D is of the Type STATIC (see the setType() method or the specific constructor) or another not-DYNAMIC type. See the JavaDoc for more details. DisplayLists are not fully used. They're planned to be used in a larger extend. But it won't hit the API; just internal changes resulting in speed-ups.

Marvin
Offline hawkwind

Junior Devvie




Java games rock!


« Reply #2 - Posted 2006-12-13 23:08:56 »

I have a zip of a Java3D implementation of shadows done by javacooldude.  I can post it as a starting place
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Zer Gut Shnitzel

Senior Newbie





« Reply #3 - Posted 2006-12-14 15:25:53 »

Quote
I have a zip of a Java3D implementation of shadows done by javacooldude.  I can post it as a starting place

That would be great.

Also if somebody is familiar how shadows are supposed to work in Xith please post some info.

Cheers
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #4 - Posted 2006-12-14 17:53:26 »

Also if somebody is familiar how shadows are supposed to work in Xith please post some info.
Well that's what's problematic : it was David Yazel who implemented them and he has gone so we have to take over his work. But I said I was gonna work on it..

AFAIK, It works with several render passes, for an object to have a shadow, first an Occluder must be computed (user-side : set shape3d.setIsOccluder(true) first) then some tricky rendering stuff is done and tadaa it works... Now that's roughly that but in maybe 20 minutes I'll be able again to do some Java stuff (I'm reinstalling my PC)

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #5 - Posted 2006-12-14 18:21:47 »

Quote
then some tricky rendering stuff is done and tadaa it works

Hahahaha, wish it was that simple   Undecided

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Zer Gut Shnitzel

Senior Newbie





« Reply #6 - Posted 2006-12-14 20:24:17 »

Quote
it was David Yazel who implemented them and he has gone so we have to take over his work. But I said I was gonna work on it..

I am guessing (but might be completely wrong) it should go something like this

The occluders have to be created / maintaned properly... based on some proxy shape volume
The shadow geometry has to be created using projected rays / occluder intersections...
Shadow geometry is rendered in a sepparate rendering pass (stencil buffer?)...
Shadow rendering output is composited over the image...

Now where would this be in current Xith code?

Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #7 - Posted 2006-12-15 09:55:54 »

why,in ShadowAtomPeer, I suppose...

DarkProphet, I almost knew how it works, but had no time to explain further...

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Zer Gut Shnitzel

Senior Newbie





« Reply #8 - Posted 2006-12-15 21:00:36 »

Hi,

I was able to fix the shadows when I change the following methods too look like this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
 private final void drawObjectShadow(GL gl, Occluder object, Point3f lightPosition)
    {
        object.getLocalToVworld().getOpengl(openGLProjMatrix);

        gl.glPushMatrix();
       
        gl.glMultMatrixf(openGLProjMatrix, 0);
       
        gl.glDisableClientState(GL.GL_COLOR_ARRAY);
        gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
        gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
        gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
       
        object.getBuffer().getCoordinateData().getFloatBuffer().rewind();
        gl.glVertexPointer(3, GL.GL_FLOAT, 0, object.getBuffer().getCoordinateData().getFloatBuffer());
        gl.glDrawArrays(GL.GL_TRIANGLES, 0, object.getBuffer().getValidVertexCount());
        addTriangles( object.getBuffer().getValidVertexCount() / 3 );
        gl.glPopMatrix();
    }
   
    /**
     * draws the shadow volumns in the render bin
     *
     * @param bin
     */

    protected final void drawShadows(GL gl, ShadowBin bin)
    {
        //ProfileTimer.startProfile("CanvasPeerImpl::drawShadows");
        final int FULLMASK = 0xffffffff;
        final int STENCIL_VAL = 128;
       
        // determine edges
       
        for (int i = 0; i < bin.size(); i++)
        {
             bin.getOccluder(i).determineVisibleEdges( bin.getLightSource() );
        }
       
        gl.glDisable(GL.GL_LIGHTING); // Turn Off Lighting
       
        gl.glEnable(GL.GL_CULL_FACE);
        gl.glCullFace(GL.GL_BACK);
       
        gl.glDepthMask(false); // Turn Off Writing To The Depth-Buffer
        gl.glDepthFunc(GL.GL_LEQUAL);
       
        gl.glEnable(GL.GL_STENCIL_TEST); // Turn On Stencil Buffer Testing
        gl.glColorMask(false, false, false, false); // Don't Draw Into The Colour Buffer
        gl.glStencilFunc(GL.GL_ALWAYS, 1, 0xffffffff);
        gl.glFrontFace(GL.GL_CCW);
       
        // First Pass. Increase Stencil Value In The Shadow
       
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_INCR);
       
        for (int i = 0; i < bin.size(); i++)
        {
             drawObjectShadow( gl, bin.getOccluder(i), bin.getLightSource() );
        }
       
        // Second Pass. Decrease Stencil Value In The Shadow
   
        gl.glFrontFace(GL.GL_CW);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_DECR);
       
        gl.glColor3f(0f, 0f, 0f);
        for (int i = 0; i < bin.size(); i++)
        {
             drawObjectShadow( gl, bin.getOccluder(i), bin.getLightSource() );
        }
       
        gl.glFrontFace(GL.GL_CCW);
        gl.glColorMask(true, true, true, true); // Enable Rendering To Colour Buffer For All Components
       
        // Draw A Shadowing Rectangle Covering The Entire Screen
        gl.glColor4f(0.0f, 0.0f, 0.0f, 0.2f);
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
        gl.glStencilFunc(GL.GL_NOTEQUAL, 0, 0xffffffff);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);
        gl.glPushMatrix();
        gl.glLoadIdentity();
        gl.glBegin(GL.GL_TRIANGLE_STRIP);
        gl.glVertex3f(-1f, 1f, -0.20f);
        gl.glVertex3f(-1f, -1f, -0.20f);
        gl.glVertex3f(1f, 1f, -0.20f);
        gl.glVertex3f(1f, -1f, -0.20f);
        gl.glEnd();
        gl.glPopMatrix();
        gl.glDisable(GL.GL_BLEND);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glDepthMask(true);
        gl.glEnable(GL.GL_LIGHTING);
        gl.glDisable(GL.GL_STENCIL_TEST);
        gl.glShadeModel(GL.GL_SMOOTH);
    }


Cheers

Vlad
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #9 - Posted 2006-12-16 13:02:36 »

Man, just tell me your SF.net account name (or create one) and I'll grant you Dev access on xith3d & xith-tk.

2 hundreds thanks Smiley  (haven't tested yet but trusting you).

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #10 - Posted 2006-12-30 15:27:19 »

I have committed the Shadows fix. How can I see, if it works now?

Marvin
Offline Zer Gut Shnitzel

Senior Newbie





« Reply #11 - Posted 2007-01-02 17:04:10 »

Setup a scene with let's say a plane at 0 in Y and a cube above it. Now the cube you need to make an occluder by using setIsOccluder(true). I think you also need to add a point light (-1000,1100,1100 seems to be a good location for it), and set up the appearances that have materials defined. In my test I used the following settings for light:

PointLight light = new PointLight(true, new Color3f(0.5f, 0.5f, 1),new Point3f(-1000,1100,1100), new Vector3f());

and the following for material:

mat.setAmbientColor(0.25f,0.25f,0.25f);
mat.setShininess(0.75f);

Now it is possible that you can actually get the shadows to appear without the light source and material defined I just haven't tested that far. From the code it looks like the actuall lights that are in the scene are not used for the shadow calculations. There is a hard coded light location at -10000, 10000, 10000 or something like that, that is used for all the shadow volume projections. The improvement here would be to use the actual light node and their locations in space to calculate the shadow volumes.   
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #12 - Posted 2007-01-02 17:50:29 »

Setup a scene with let's say a plane at 0 in Y and a cube above it. Now the cube you need to make an occluder by using setIsOccluder(true). I think you also need to add a point light (-1000,1100,1100 seems to be a good location for it), and set up the appearances that have materials defined. In my test I used the following settings for light:

PointLight light = new PointLight(true, new Color3f(0.5f, 0.5f, 1),new Point3f(-1000,1100,1100), new Vector3f());

and the following for material:

mat.setAmbientColor(0.25f,0.25f,0.25f);
mat.setShininess(0.75f);

Now it is possible that you can actually get the shadows to appear without the light source and material defined I just haven't tested that far. From the code it looks like the actuall lights that are in the scene are not used for the shadow calculations. There is a hard coded light location at -10000, 10000, 10000 or something like that, that is used for all the shadow volume projections. The improvement here would be to use the actual light node and their locations in space to calculate the shadow volumes.   

Thanks. I will check it out.

Marvin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (59 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!