Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  Multipass lighting problem (now with screenshots!) [SOLVED]  (Read 1927 times)
0 Members and 1 Guest are viewing this topic.
Offline Aikavanak

Junior Newbie





« Posted 2008-07-06 04:14:32 »

Hey,

This may be more like a general OpenGL question, but I'm really struggling with this one...

I am trying to get per-pixel dynamic lights working in my JOGL app (an extremely young game engine), using multiple passes to draw each light and blend them together. From what I know, the basic idea is to render ambient light in an initial pass, and then add the diffuse lighting components in the next passes, one for each light.

It also seems like a good idea to write the z-buffer in only the first pass, to save time in the later ones. However, this doesn't seem to be working in my code.

I initialize OpenGL like this:
1  
2  
3  
gl.glEnable(GL.GL_BLEND);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);


And my rendering code looks 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  
gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
     
// Ambient and depth buffer pass.
gl.glBlendFunc(GL.GL_ONE,GL.GL_ZERO);
// Enable depth buffer writes.
gl.glDepthMask(true);
     
ambientShader.enable();
     
renderScene();
     
ambientShader.disable();
     
// Lighting passes.
// Add new fragment colors to colors from previous pass.
gl.glBlendFunc(GL.GL_ONE,GL.GL_ONE);
// Disable depth buffer writes.
gl.glDepthMask(false);
     
diffuseShader.enable();
     
for(int i=0;i<lightManager.getNumLights();i++)
{
    diffuseShader.sendUniform("lightIndex", i);
         
    renderScene();
}

diffuseShader.disable();


With this code, I get strange artifacts that I thought at first were due to z-fighting, because if I set glDepthMask(true) for the diffuse passes, the artifacts disappear. But polygons aren't appearing over others, sections of my rendered model are just disappearing. Right now I'm testing with only one light.

Each pass is working fine on its own, I've tried commenting out one or the other and looking at the results.

Is there anything wrong with my code? I don't think the problem in is the shaders, but I can post their code too if it would be helpful. I can also try to upload some screenshots of the artifacts.

System specs:
Windows Vista Business 64-bit
nVidida GeForce 8800 GTS 640MB with 175.19 drivers
JDK/JRE 1.6.0 update 4
JOGL 1.1.1 

Thanks!
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2008-07-06 04:50:27 »

Pictures of the artifacts and the separate lights would be useful, also, you could try using a traceGL to print out all of your opengl calls to make sure nothing odd is happening.

Offline Aikavanak

Junior Newbie





« Reply #2 - Posted 2008-07-10 06:08:16 »

I have uploaded some screenshots of the problem to my website. Check them out at www.ryangerleve.com/artifact/index.html.

Notice how after switching out of wireframe mode with glDepthMask(false), the model isn't drawn on the lines that made up the wireframe. Very strange, because I clear the depth and color buffers every frame (I'm running at 60fps). Wireframe mode is controlled by glPolygonMode.

Please post any ideas you have, as I am still stuck on this!

Thanks!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2008-07-10 23:52:21 »

If glDepthMask() is false, then it disables all writing to the depth buffer, including when you clear the buffers.  At the beginning of your frame, set glDepthMask(true) before calling glClear().

Offline Aikavanak

Junior Newbie





« Reply #4 - Posted 2008-07-11 04:36:56 »

Thanks lhkbob! That was exactly the problem! I thought just adding the GL_DEPTH_MASK flag to glClear would do it, guess not. Anyway, thanks, that had really stumped me.
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!