fog problem on ios

Monkey Forums/Monkey Programming/fog problem on ios

NoOdle(Posted 2012) [#1]
I have a weird problem with fog at the moment. I have created a cube and scaled it to 100,1,100 and set the fog range to 25 near and 50 far. On GLFW this works fine but on the iPhone the floor object appeared faded. It fades in and out depending on the camera yaw which is baffling me.

google provided this http://s231.codeinspot.com/q/1779029 but I would have expected the same behaviour on both targets. I'd like to think that this is a problem with the way I have done something... I don't want my floor to be made up using lots of quads! Anyone have any ideas what could be causing it?

	'/ Do fog
	If Self.fogMode = 1
		glEnable( GL_FOG )		
		glFogf( GL_FOG_MODE, GL_LINEAR )
		glFogf( GL_FOG_START, Self.fogNear )
		glFogf( GL_FOG_END, Self.fogFar )
		glFogfv( GL_FOG_COLOR, [ self.fogR, self.fogG, self.fogB ])
	Else
		glDisable( GL_FOG )
	Endif


As you can see in the screenshot below, the floor has been affected by the fog. If the camera was to rotate more this effect fades in and out. Very strange!




JIM(Posted 2012) [#2]
I'm not 100% sure on this one, btu the fog might be computed on a per-vertex basis in this case. Since the fog is computed using a "plane" parallel to the camera viewport, the angle of the camera will definitely alter the stat of the furthest vertices (e.g: If you're looking up or down, then the whole floor wil be outside the fog. If you looks straight ahead, the fog will affect half of the floor).

Since you only have 4 (actually 8, but for the sake of the explanation keep it to 4) vertices that define the floor, and the color is just interpolated, you get this undesired effect. If two of the vertices are at maximum range in the fog (which is the case here) then the floor is strongly affected by this. Even moreso if somehow the fog is computed behind the camera as well (though I doubt it).

If my theory is right, you should see the floor normally if you look directly down.

EDIT: In this case the fix would be to either use more polygons for the floor (not necesarily a grid. you could use lods for this. I'll link the paper if I can find it) OR you could make sure you compute the fog per-pixel (GLES 2.0)


NoOdle(Posted 2012) [#3]
Thanks JIM, I was really hoping that wasn't the case as it doesn't do it on GLFW target. I would have liked the behaviour to be the same for both so that people wouldn't need to alter the code too much. Also as this is a 1.1 engine I don't have the option to do fog per-pixel which is a shame! Lighting per pixel would be nice as well!

That paper sounds interesting, I don't think I have come across that before, definitely interested in the link if you can find it :)

[edit] Just tried pointing the Camera down and the result is as you suspected...


JIM(Posted 2012) [#4]
There we go http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter02.html

Part of the GPU Gems. I totally recommend reading them all :)

The techniques there are GPU-based, but the main layout of the terrain could be inspired from there. Especially useful if the area you move around is rather small.

It would be great if things would just run the same on all targets, but once in a while you hit a difference like this sadly :(

One other option I can think of right now (if and only if your terrain is flat) is to disable fog completely on the ground, and use another large quad with a circular gradient on it. That way you'd "manually" do fog on the ground.

This could also work with non-frat ground with texture projection I would assume, but it will be slower :)


NoOdle(Posted 2012) [#5]
Thank you JIM, I'll give that a read! I've been meaning on reading the entire series but I've got so many other books I'm halfway through, I need more hours in my days!!

One other option I can think of right now (if and only if your terrain is flat) is to disable fog completely on the ground, and use another large quad with a circular gradient on it. That way you'd "manually" do fog on the ground.


Yea that sounds like a good idea. I'll have to have a play around with that and see what it looks like.