Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Arrrgggg  (Read 2123 times)
0 Members and 1 Guest are viewing this topic.
Offline DavidYazel

Junior Member




Java games rock!


« Posted 2003-07-21 02:31:15 »

I hate it when I stare at code for hours and cannot figure out what is wrong.

I have implemented shadow volumes in the xith3d engine.  The scenegraph can construct a shadow occluder for any branch in the scenegraph by examining all the geometry below it.

The occluders calculate a connectivity list and can be queried against lightsources to produce shadow volumes.  The volumes are perfect because when I render them to the color buffer they are correct.

But for some reason I cannot figure out, when I render them to the stencil buffer they are not updating the buffer, or when I test against it the tests are not working.  In fact if all I do is clear the stencil and then write geometry with a :

1  
2  
        gl.glStencilFunc(GL.GL_NOTEQUAL, 0, FULLMASK);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);


The geometry STILL RENDERS when it should be masked!

In this image I show the shadow volume in red.  The alpha blended square should only be drawing in the red areas.

http://www.magicosm.net/xith3d/snapshot.png

Anyone have any ideas?

I will post the routine below.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-07-21 02:31:51 »

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  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
    /**
     * draws the shadow volumns in the render bin
     * @param bin
     */

    protected void drawShadows(ShadowBin bin) {

        final int FULLMASK = 0xffffffff;
        // determine edges

        for (int i = 0; i < bin.curSize; i++)
            determineVisibleEdges(bin.buckets[i], bin.lightsource);

        gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT |
                        GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT |
                        GL.GL_STENCIL_BUFFER_BIT);

        gl.glPushMatrix();
        gl.glLoadIdentity();
        gl.glDisable(GL.GL_LIGHTING); // Turn Off Lighting
       gl.glDisable(GL.GL_TEXTURE_2D);
        gl.glDisable(GL.GL_TEXTURE_3D);
        gl.glStencilFunc(GL.GL_NEVER, 0xff,FULLMASK);

        gl.glDepthMask(true);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glEnable(GL.GL_DEPTH_TEST);

        // (test)draw a floor
       gl.glColor3f(0.2f,0.4f,0.2f);
        gl.glBegin(GL.GL_QUADS);                                    // Begin Drawing Quads
               // Floor
               gl.glNormal3f(0.0f, 1.0f, 0.0f);                        // Normal Pointing Up
               gl.glVertex3f(-100.0f,-10.0f,-100.0f);                  // Back Left
               gl.glVertex3f(-100.0f,-10.0f, 100.0f);                  // Front Left
               gl.glVertex3f( 100.0f,-10.0f, 100.0f);                  // Front Right
               gl.glVertex3f( 100.0f,-10.0f,-100.0f);
        gl.glEnd();
        gl.glPopMatrix();

        gl.glColor3f(1f,0f,0f);
        gl.glClearStencil(0);

        gl.glDisable(GL.GL_LIGHTING); // Turn Off Lighting

        gl.glEnable(GL.GL_CULL_FACE);
        gl.glCullFace(GL.GL_FRONT);
        gl.glDepthMask(false); // Turn Off Writing To The Depth-Buffer
       gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glEnable(GL.GL_DEPTH_TEST);
        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, 0xff,FULLMASK);
       gl.glStencilFunc( GL.GL_ALWAYS, 1, 0xFFFFFFFF );


        // 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.curSize; i++) {
            drawObjectShadow(bin.buckets[i], bin.lightsource);
        }

        // Second Pass. Decrease Stencil Value In The Shadow
       gl.glCullFace(GL.GL_BACK);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_DECR);

        for (int i = 0; i < bin.curSize; i++) {
            drawObjectShadow(bin.buckets[i], bin.lightsource);
        }

//        gl.glFrontFace(GL.GL_CCW);
       gl.glColorMask(true, true, true, true); // Enable Rendering To Colour Buffer For All Components

        // Draw A Shadowing Rectangl.gle Covering The Entire Screen
       gl.glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
        gl.glEnable(GL.GL_BLEND);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        /*
        for (int i = 0; i < bin.curSize; i++) {
            drawObjectShadow(bin.buckets[i], bin.lightsource);
        }
        */


        // get rid of the view matrix, only have the projection matrix

        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        renderFrame.getView().getProjection().get(trans);
        gl.glLoadMatrixf(trans);

        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPushMatrix();
        gl.glLoadIdentity();


        gl.glDepthMask(false);
//        gl.glColor3f(0,0,1);

        gl.glEnable(GL.GL_STENCIL_TEST); // Turn On Stencil Buffer Testing
       gl.glStencilFunc(GL.GL_EQUAL, 0, FULLMASK);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

        gl.glBegin(GL.GL_TRIANGLE_STRIP);

        gl.glBegin(GL.GL_TRIANGLE_STRIP);
                gl.glVertex3f(-0.1f, 0.1f,-1f);
                gl.glVertex3f(-0.1f,-0.1f,-1f);
                gl.glVertex3f( 0.1f, 0.1f,-1f);
                gl.glVertex3f( 0.1f,-0.1f,-1f);
            gl.glEnd();
        /*
        gl.glVertex3f( -100f, 100f, -2f);
        gl.glVertex3f( -100f, -1000f, -2f);
        gl.glVertex3f(100f, 100f, -2f);
        gl.glVertex3f(100f, -1000f, -2f);
        gl.glEnd();
        */

        gl.glPopMatrix();

        gl.glPopAttrib();

    }

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline DavidYazel

Junior Member




Java games rock!


« Reply #2 - Posted 2003-07-21 02:35:28 »

Ok so this code draws a blue square when it should be impossible.  I clear the stencil buffer, then only draw where it is not zero... yet it draws!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   gl.glClearStencil(0);
        gl.glEnable(GL.GL_STENCIL_TEST); // Turn On Stencil Buffer Testing
       gl.glStencilFunc(GL.GL_NOTEQUAL, 0, FULLMASK);
        gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

        gl.glColor3f(0,0,1);
      

        gl.glBegin(GL.GL_TRIANGLE_STRIP);
                gl.glVertex3f(-0.1f, 0.1f,-1f);
                gl.glVertex3f(-0.1f,-0.1f,-1f);
                gl.glVertex3f( 0.1f, 0.1f,-1f);
                gl.glVertex3f( 0.1f,-0.1f,-1f);
            gl.glEnd();

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidYazel

Junior Member




Java games rock!


« Reply #3 - Posted 2003-07-21 03:03:00 »

wooooot

I figured it out!

I forgot to set the GLCapabilities to give me a stencil buffer!

HAHAHAHHAHHA

Man I spent more time debugging that than it took to write the shadow volume code

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline TarmTarm

Senior Newbie




Write once, never run.


« Reply #4 - Posted 2003-07-21 06:25:12 »

I had the same problem yesterday with the stencil buffer. I almost threw my computer out of the window  before I found the solution Tongue
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2003-07-21 12:15:22 »

I always find these sorts of errors about half way through explaining it to someone else.  There I am trying to describe the problem, all worked up because I can't find the error, only to shrink away with a "never-mind" and go back to my desk. Smiley

They should just build a simple "Eliza-like" AI into IDEs so you can complain about bugs to them for a while.  Half way through chatting with the AI about how stupid some API is because it doesn't work the light bulb will turn on in your head and you can just click the close button on the chat interface and get back to work.

Offline aNt

Senior Member




AFK


« Reply #6 - Posted 2003-07-21 12:20:46 »

but wheres the fun in that?... u need that shocked confused look in other peoples faces... where they have no clue what the hell u are on about...  Grin
Offline Markus_Persson

JGO Wizard


Medals: 15
Projects: 19


Mojang Specifications


« Reply #7 - Posted 2003-07-21 12:31:29 »

Haha, it's funny because it's true. Wink

We've even put a system into place at work, where we try to explain our problems to people who are not involved in it. Most of the time you come up with the solution and/or realize you've missed a tiny detail while explaining it, and the rest of the time the listener can provide some very good out of the box thinking that helps you solve it.

Of course, some of the time it turns out to really be a REAL showstopper, like when SavaJe didn't let us change the id for the 802.11 card from the default value, and that value turned out to be the only setting our access point was hardcoded to reject, for security reasons.

That one drove us very much insane until we figured it out. Wink

Play Minecraft!
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.

BurntPizza (12 views)
2014-09-19 03:14:18

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!