Welcome! Log In Create A New Profile

Advanced

[RESOLVED] GX_SetFog has anybody ever tried using it?

Posted by owen 
[RESOLVED] GX_SetFog has anybody ever tried using it?
December 27, 2010 08:28PM
I tried setting it up but its parameters are unusual to me. I mostly either get a completly red screen or a redish tint. I want to use it so that objects coming to wards the screen in my game are slightly hidden behind the fog.



Edited 1 time(s). Last edit at 12/30/2010 04:01PM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 28, 2010 02:54AM
What's the code that you're using?
Re: GX_SetFog has anybody ever tried using it?
December 28, 2010 04:39AM
I've tried several combinations and coordinates but all I get is either all polygons are rendered totally black or there is a black fog over everything;

GXColor c = {10, 10, 10};
GX_SetFog ( GX_FOG_ORTHO_EXP, -300, -600, 0, -10000, c );
OR
GX_SetFog ( GX_FOG_PERSP_EXP ,-620,-630,-600,-650, c );

not sure if I need to use Z coords that are in the positive but I don't think that should matter.

My camera is set to;

GRRLIB_3dMode(0.1,-10000,45,0,0);



Edited 1 time(s). Last edit at 12/28/2010 04:41AM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 28, 2010 06:32AM
Here is how the fog function is defined in libogc:

void GX_SetFog(u8 type, f32 startz, f32 endz, f32 nearz, f32 farz, GXColor col);

Let's start with this one (using perspective):

GX_SetFog (GX_FOG_PERSP_EXP ,-620,-630,-600,-650, c );

The start and end are awfully close to each other, but I think the problem would the nearz and farz, which need to match the projection matrix parameters. Let's say that we use a perspective projection like so:

guPerspective(projection, 45, width/height, 0.1f, 100.0f);
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);

Then our SetFog function would need to be called like this:
GX_SetFog (GX_FOG_PERSP_EXP , 620, 630, 0.1f, 100.0f, c );

I think the values are positive when passing to the fog function. Also, if you're using perspective, try GX_FOG_LIN (it's the same as GX_FOG_PERSP_LIN) to see if that's better for you.

I should warn you though, I haven't used fog in a while.
Re: GX_SetFog has anybody ever tried using it?
December 28, 2010 05:24PM
I've tried setting it to the correct matrix settings (0, -10000) but I'm going to try using positive numbers and see how it works out.

Do you remember how the fog is supposed to look? is it like WHITE TINT on the whole screen or does it look like real fog/mist with volume? If you have any videos with how the end results looks that would be helpful.



Edited 1 time(s). Last edit at 12/28/2010 05:27PM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 29, 2010 03:11AM
I found my fog code! Here's what I used (modified for simplicity):

// Previously defined variables:
Mtx44 projection;
f32 width, height;

// Fog variables
GXFogAdjTbl fogTable;
bool fogAdjust = true;
GXColor fogcolor = {128,128,128,255};

// Set up the projection matrix
guPerspective(projection, 45, width/height, 16.0f, 1024.0f);
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);

// Set pixel processing mode
GX_SetBlendMode(GX_BM_BLEND, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
GX_SetZMode(GX_TRUE, GX_LESS, GX_TRUE);

// Start the fog at 16 and end at 
GX_SetFog(GX_FOG_LIN, 16.0f, 1024.0f, 16.0f, 1024.0f, fogcolor);

// Adjust the scene so that the sides of the screen are properly fogged.
if (fogAdjust){
    GX_InitFogAdjTable(&fogTable, (u16) width, projection);
    GX_SetFogRangeAdj(GX_ENABLE, (u16) width/2, &fogTable);
}
else{
    GX_SetFogRangeAdj(GX_DISABLE, 0, NULL);
}
The fog does seem to be a "white tint" as you call it. The entire screen is not actually blanketed in fog. GX calculates the fog for each polygon's distance from the viewer. Use the same background color as the fog and the objects will appear to "fade" into the distance.
Re: GX_SetFog has anybody ever tried using it?
December 29, 2010 04:28AM
hmmm yes I never had that GX_InitFogAdjTable() and GX_SetFogRangeAdj() call but I have seen that white tint effect during some of my experiments and it doesn;t look pretty at all :(. Its going to be tricky with the fact that I have absolutely no polygons in some areas of my screen (and i was hoping that the fog function would be ideal to hide this fact) but I will give this a try. thanx for your help,

ps if all else fails I'll attempt to draw thousands of dots,all across the screen lol.



Edited 1 time(s). Last edit at 12/29/2010 04:30AM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 29, 2010 05:42AM
If you set your background/clear color to the same color as the fog, it should be the same as having 100% fog where you have no polygons on the screen.
GX_SetCopyClear(fogcolor, GX_MAX_Z24);
Then again, I'm not quite sure what you're going for.
Re: GX_SetFog has anybody ever tried using it?
December 29, 2010 07:08AM
something like this (without the snow particle effects): [www.youtube.com]

if looks basically like that I;d be ok. still haven't gotten a chance to test out the above code yet though.



Edited 1 time(s). Last edit at 12/29/2010 07:09AM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 29, 2010 11:40PM
Yeah, minus the snow, that's what fog looks like.
Re: GX_SetFog has anybody ever tried using it?
December 30, 2010 05:54AM
RESOLVED!! After what feels like months of painful trail and error I finally found out what was wrong with my code. I had misinterpreted what the parameters ment. The fog seems to work based on the draw distance of the camera as opposed to my "real world" coordinates. here is the code that seems to work now;
Note that the copyclear color call really makes the effect work, so don't go drawing plasma graphics in the background ( all your polygons will look like the night stage in DKReturns [www.youtube.com] ).
float camera_draw_distance=10000;
		GRRLIB_3dMode(1,camera_draw_distance,45,0,0);

void draw_fog( u32 color ) {
	GXColor fogcolor = {R(color),G(color),B(color),A(color)};
	GX_SetFog(GX_FOG_LIN, 0, camera_draw_distance/2, 1, camera_draw_distance, fogcolor);
	GX_SetCopyClear(fogcolor, GX_MAX_Z24);
}

thanx dancinninja, I could not have figured it out without your help. Now for the snow! lol



Edited 1 time(s). Last edit at 12/30/2010 06:00AM by owen.
Re: GX_SetFog has anybody ever tried using it?
December 30, 2010 07:38AM
I look forward to your project! Glad I could help.
Re: GX_SetFog has anybody ever tried using it?
December 30, 2010 03:59PM
Considering the amount of time I spent on it you would think that the fog would be a critical feature but its really cosmetic at this point. This is a early version of my project: [www.youtube.com] (no fog) rest of the info is on my wiibrew page.



Edited 1 time(s). Last edit at 12/30/2010 04:00PM by owen.
Sorry, only registered users may post in this forum.

Click here to login