www.jpct.net

jPCT-AE - a 3d engine for Android => Bugs => Topic started by: Zyphuris55 on June 12, 2012, 08:10:54 am

Title: Fogging problems
Post by: Zyphuris55 on June 12, 2012, 08:10:54 am
I think this is a bug because it happens without any apparent logic.
In the game play part of my game, I have the game objects rendered in one world and the hud objects rendered in another world (so they would stay static while the rest of the game move). The game objects have transparency, while the hud objects don't.

On the first render frame, it renders the scene for both worlds and then draws the worlds (game then hud), but it's not displaying the fog on the game play's world objects. When I disable the rendering/ drawing of the hud world, the first render has the fog enabled.
With the hud world enabled and the scene incorrectly displaying, after touching the screen, the fog re-enables.

I tried using the framebuffer's clearZBufferOnly() before the hud's render/ draw line, but that didn't do anything. Then I played with some code which would render/ draw the worlds twice on only the first render frame, but that also did nothing. I also tried to disable the fog in the HUD's world (not sure how that would be helped)....but it also didn't do anything. Lastly, I disabled all the lighting in the HUD's world, both ambient light and any other lights added to the world, but the only thing that did was make the hud objects black.

= Gameplay code
Code: [Select]
boolean firstR = true;
public void Render(FrameBuffer fb)
{
/*
if(firstR)
{// attempted fix, which does nothing
world.renderScene(fb);
world.draw(fb);
fb.clearZBufferOnly();

hud.Render(fb);
}
*/

if((Touching || resetting) || firstR)
world.renderScene(fb);
firstR = false;

world.draw(fb);
//fb.clearZBufferOnly();
hud.Render(fb);
}


= HUD render code
Code: [Select]
private boolean render = true;
void Render(FrameBuffer fb)
{
if(render)
world.renderScene(fb);
render = false;

world.draw(fb);
}



Note: the renderScenes are linked to bool requirements so the worlds won't be needlessly rendering every frame (it made my phone hot and the fps slow).


The HUD currently only has 1 thing, which is the bottom left

= Pre-touch
(http://i49.tinypic.com/2jbjndg.png)

= Post-touch (ignore the half-lighted/half-darked block, the picture was taken between render frames)
(http://i48.tinypic.com/351yc1x.png)
Title: Re: Fogging problems
Post by: EgonOlsen on June 12, 2012, 08:27:16 am
Which OpenGL version are you using? 1.x or 2.0?
Title: Re: Fogging problems
Post by: EgonOlsen on June 12, 2012, 08:41:05 am
Have you tried to use another color than black as fog color?

And could you please set the log level in Logger to debug, set Config.glDebugLevel=1 and post the ouput for the first two frames (might be a bit large...)?
Title: Re: Fogging problems
Post by: Zyphuris55 on June 12, 2012, 09:31:32 am
I'm using OpenGL 2.0

...it was REALLY hard to get the logs, lol. I had to remove the 80,000 limit and be quick on the pause button. Even still, they are pretty lengthy.

Loga: Starts as soon as I clicked the button to go to the game play and paused after the first image was visible.
Logb: (cleared the first log first). Touched the screen which re-enabled the fogging, then paused it after the image what changed.

I haven't tried anything besides using "world.setFogParameters(20, 60, 0, 0, 0);". I didn't feel a fog of other than black would look good.

[attachment deleted by admin]
Title: Re: Fogging problems
Post by: Zyphuris55 on June 12, 2012, 09:46:01 am
I went through both logs now, looking for any differences...and I couldn't find any :-/. Does being an engine developer give you a more detailed eye than a normal coder would? lol

Anyway, if the log's aren't too helpful, I'd gladly send you the project for you to check out yourself.
Title: Re: Fogging problems
Post by: EgonOlsen on June 12, 2012, 10:30:39 am
These logs don't look complete to me. Neither of them contains output about setting the fog values nor a call to glClear. Anyway, i'll try to create a test case for this myself this evening. If that doesn't work out, i'll need your project to track this down.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 12, 2012, 11:06:13 am
Previously, the game had the "Config.glDebugLevel=1;" line in the creation of the render (which currently renders the menu and gameplay, I'm working on switching them to different activities). So I switched the line to be in onDrawFrame part of the render.

Code: [Select]
public void onDrawFrame(GL10 gl)
{
if(Screen == 1 && Screens.size() == 1)
{
Config.glDebugLevel=1;
Screens.put(1, new Gameplay());
}

fb.clear(back);

Screens.get(Screen).Render(fb);

//FPS(fb);
       
        fb.display();
}

but, the log seems to show nothing besides loading the objects and compiling them. There isn't even any gl calls like in the previous 2 logs.

I also changed the gameplay render function so it would draw the objects every frame...and nothing :-/

Code: [Select]
boolean firstR = true;
public void Render(FrameBuffer fb)
{
if((Touching || resetting) || firstR)
world.renderScene(fb);
firstR = false;

world.draw(fb);
//fb.clearZBufferOnly();
hud.Render(fb);
}

note: the renderer doesn't contain a world, only a framebuffer which it sends to the menu and gameplay classes. The creation of the gameplay/ menu class makes a new world just for that class.
Title: Re: Fogging problems
Post by: EgonOlsen on June 12, 2012, 08:34:55 pm
I tried to create a test case, but i can't reproduce the problem. I created a fogged main world and a non-fogged additional world, rendered them in that order in GL 2.0 mode and everything looked fine even for the first frame. I need to project or a simplified test case to track this down...
Title: Re: Fogging problems
Post by: Zyphuris55 on June 13, 2012, 12:35:35 am
Hmm...ok. Well, currently, I don't have a stable release. Last night I started converting the project from one activity to multiple activities and the process isn't complete yet. I can't even give the classes in question because I've already changed them for the activity conversion. But, as soon as it's at a stable spot, I'll send the project.
What email can I send it to when it's ready (if the problem still persists)?


Edit: The game is at a stable release now and the problem is still there
Title: Re: Fogging problems
Post by: EgonOlsen on June 13, 2012, 07:03:15 am
Just send it to info@jpct.net. I'll look at it this evening.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 13, 2012, 07:23:13 am
Ok, it's sent. And thank you for helping me with the problems.
Title: Re: Fogging problems
Post by: EgonOlsen on June 13, 2012, 09:11:41 pm
The problem is caused by the way you are dealing with the calls to renderScene(). If nothing in the scene has changed, you simply omit them. That this works is more by chance than intended... ;) The actual idea was to call both (or neither) every frame. However, i see the idea behind this...i've uploaded a jar that should fix this particular problem: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

Anyway, i'm not 100% sure that this is the only part that might cause problems if you do it this way. So in case of doubt, try to call renderScene()/draw() for each frame and see if that helps.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 13, 2012, 11:26:51 pm
I'm a bit confused on your reply. Currently I have it so it renders only the first scene or when the models are being changed, and on every frame it draws the scene (because it's parent class clears the framebuffer). I changed it from rendering every scene to only when needed to help prevent the phone from over-heating.
From what I can guess in your reply, your saying that the world.draw(fb) after the world.renderScene(fb) is a redundant call?

I'll try the jar as soon as I can.
Title: Re: Fogging problems
Post by: EgonOlsen on June 14, 2012, 08:19:12 am
From what I can guess in your reply, your saying that the world.draw(fb) after the world.renderScene(fb) is a redundant call?
No, what i tried to say was that every call to draw() should be preceded by a call to renderScene(). However, with the new jar, this shouldn't be a problem. At least not in this case.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 14, 2012, 08:26:05 am
Oh...now I can see of why you said it was surprising that it actually worked, lol.

I still haven't tried the jar yet, I've been busy with other things that are for this weekend.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 15, 2012, 09:11:54 am
I was just able to try the new jar...and it worked-ish. The fogging problem is fixed, but now there is graphical issues.
When moving left/right (which only effects the camera), the objects would flicker/ spin around as if the rotation is being forgotten. The camera would be on the opposite side of the object, or very far away, or drawing the object very close.

I have a class which interfaces the camera class. It has a cameraLook (Object3D), cameraPlace (Object3D) and a root (Object3D, the previous 2 are childs of this). After the look/ place are put in place (using the TranslateMesh), the game interacts with the camera movement by using the parent node only....the rotation and distance between the place/look are never changed thereafter.

I'm going to be revering back to the previous jar, the 1.25 version. It's easier to have a lighting problem than the objects flying around wildly when trying to move around.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 09:29:43 am
That's strange. The change that i did shouldn't have this consequence. Please try the new jar without your renderScene()-on-demand logic, i.e. always do a renderScene()/draw() in all cases and see if that helps.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 15, 2012, 09:35:58 am
No good either. I added the jar, cleaned the project, remove the limit so renderscene is on every frame, (enabled the fps counter), then tested the game. And it still has the visual glitches.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 09:38:01 am
Ok...then i have screwed up something with other changes that i did. How can reproduce this? Is it possible by using the version that you sent to me? How do i move then? I only managed to spin these wheels around.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 15, 2012, 09:43:30 am
I haven't changed anything drastic since the version I sent you, so that copy should still work. The problem is visual in both the menu and gameplay. Drag left/right slowly and you'll be able to see the glitching better, but it works at any movement speed.

To go into the gameplay, have "Campaign" selected and hit "go". I'm working on the lag between menu/gameplay.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 09:53:25 am
With the version on my phone (can't access the sources ATM), i can see some missing or shifted objects when moving left/right. Is that what you mean? Maybe you can make a screen shot of the glitch. I don't see anything like objects being rendered very large or something like that!?
Title: Re: Fogging problems
Post by: Zyphuris55 on June 15, 2012, 10:41:51 am
I'm sending you an email with a zip of 4 pictures (it would make this post too long if I tinypic'd them and they are too big to upload as an attachment through here).
The pictures were taken within the movement of 50-100 pixels (camera x translation of 1 - 2f) , or within one movement action. The game would flicker between types of these instances throughout the movement.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 10:56:35 am
Thanks. I think i've found a problem in a change that i did lately to save some memory. I'll try to fix this when i get back home.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 02:23:25 pm
... are you by any chance fiddling around with the camera or objects' positions in any thread other than the rendering thread? If you do so, don't do this, because jPCT and jPCT-AE aren't thread safe: http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety (http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety)
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 06:04:13 pm
I've updated the jar with a version that should fix the problems that my last change introduced while still maintaining the benefits: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

However, even when using the 1.25 jar, i'm getting the same render glitches with objects being moved while others are not and parts get clipped that should actually be visible. I haven't checked the game's code, but i really think that this is caused by fiddling around with the camera in parallel to the rendering thread, i.e. you are executing touch events directly when they happen without taking care of the rendering, which should at least be synchronized to this...or, the better solution IMHO, collect all events or their consequences and execute them in the rendering thread. This will also make the touch event handling more responsive.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 15, 2012, 07:23:13 pm
Yes, the touch events are taken care of as soon as they happen...I thought this was normal.
I created the class which controls all of what should happen for that screen (render, movements, actions, etc.), then fed that class to the renderer, then sent the renderer and previous class to the touch surface.
In the touch surface, I have the actions directly interfacing with the screen class, as opposed to the "queueEvent(new Runnable()....".

I'll try working on it now so the events are in the render thread, maybe by using a queue and run all the events before rendering/ drawing of the objects is done.


....I'm confused of how you're getting the same rendering glitches in the 1.25. The only model glitches I see in that version is there there is sometimes cracks between 2 objects, which are subtitley noticeable.
Title: Re: Fogging problems
Post by: EgonOlsen on June 15, 2012, 08:01:32 pm
....I'm confused of how you're getting the same rendering glitches in the 1.25. The only model glitches I see in that version is there there is sometimes cracks between 2 objects, which are subtitley noticeable.
I never experienced these kind of glitches that you got, not even with the faulty 1.26 version. But i do get these cracks and some missing objects quite often. This might depend on the speed of the device and if the cpu has one core or multiple. An easy way to do camera stuff in the render thread would be to use another camera in the touch event handling and synchronize on that instance in both threads. Then simply copy the data from that camera to the world's camera and you are done.
Title: Re: Fogging problems
Post by: Zyphuris55 on June 16, 2012, 03:08:24 am
I just finished the touch upgrade, so the actions take effect in the render thread only. Tested it with the 1.25, and there isn't any minor object disconnect like I saw previously. So I tried the beta you linked a few posts ago, and the game didn't have any glitches or fogging problem.

..so, it works :-). Thank you for your patience and help.


Edit: I re-enabled the line to render the scene only when needed (moving the objects and on the first frame), and the game still works. I get about 28 fps idle and 18 when moving around.