-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document fog functions Gfx_SetFog(2) and Play_SetFog #1922
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -847,28 +847,50 @@ Gfx gEmptyDL[] = { | |||||||||||
gsSPEndDisplayList(), | ||||||||||||
}; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Set fog color and range. | ||||||||||||
* | ||||||||||||
* At or prior to fog near, geometry is unaffected by fog. At or beyond fog far, geometry is fully fogged. | ||||||||||||
* Between near and far pixels will be linearly interpolated between the unfogged color and the supplied fog color. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
it is "some z"-linear but not view space z linear when using perspective projection (I forgot the details (if I ever grasped them)), anyway so I don't think specifying linear is all that useful |
||||||||||||
* | ||||||||||||
* Fog far should be in the range 0 to 1000 and greater than or equal to fog near. If fog near is negative everything | ||||||||||||
* will be fully fogged. If fog near is 1000 or greater there is no fog. | ||||||||||||
*/ | ||||||||||||
Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) { | ||||||||||||
// Ensure fog far is greater than near | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this only ensures that near != far, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it ensures that far is greater than near only in the case where they are initially the same. like, the important bit that tharo is stressing here is that far gets incremented by 1 to be bigger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
if (far == near) { | ||||||||||||
far++; | ||||||||||||
} | ||||||||||||
|
||||||||||||
ASSERT(near != far, "n != f", "../z_rcp.c", 1155); | ||||||||||||
|
||||||||||||
// Set the fog color, far away geometry will be rendered as this solid color. | ||||||||||||
gDPSetFogColor(gfx++, r, g, b, a); | ||||||||||||
|
||||||||||||
if (near >= 1000) { | ||||||||||||
// Fog far is expected to be at most 1000 so near >= far. Set a constant shade alpha of 0 for no fog | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I wouldn't write anything on why, this whole function is sloppy without good "why"s anyway |
||||||||||||
gSPFogFactor(gfx++, 0, 0); | ||||||||||||
} else if (near >= 997) { | ||||||||||||
gSPFogFactor(gfx++, 0x7FFF, 0x8100); | ||||||||||||
} else if (near > 996) { | ||||||||||||
// Calculating the fog multiplier when far = 1000 and near >= 997 using `128000 / (far - near)` as in | ||||||||||||
// SPFogPosition would result in an overflow since 128000 / (1000 - 997) > 32767. Avoid this overflow by | ||||||||||||
// effectively clamping near to ~996. This is almost SPFogPosition(996.0937f, 1000) | ||||||||||||
Comment on lines
+873
to
+875
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest moving details to the general case
Suggested change
|
||||||||||||
gSPFogFactor(gfx++, 0x7FFF, -0x7F00); // Fixed point: 0x7FFF = 1.0, -0x7F00 = -0.992 | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fm and fo are s0.15 ? Where is this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
32512 is chosen so that f(z)=255 at z=1 There's some weirdness in how the microcode actually computes this since z itself isn't really in the interval [-1,1], it's in s15.16 format. The calculation is something like
https://github.com/Mr-Wiseguy/f3dex2/blob/master/f3dex2.s#L1432 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then if to interpret |
||||||||||||
} else if (near < 0) { | ||||||||||||
// Fog near is out of range. Set a constant shade alpha of 255 for fully fogged | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
gSPFogFactor(gfx++, 0, 255); | ||||||||||||
} else { | ||||||||||||
// Normal range. Shade alpha is 0 at z <= near and 255 at z >= far, linearly interpolated in between. | ||||||||||||
//! @bug If the difference between near and far is not at least 4, the fog multiplier will overflow. This is | ||||||||||||
//! handled above when fog far is 1000 but for closer fog far it is not accounted for. | ||||||||||||
Comment on lines
+882
to
+883
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
gSPFogPosition(gfx++, near, far); | ||||||||||||
} | ||||||||||||
|
||||||||||||
return gfx; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Like Gfx_SetFog but issues a pipesync before changing fog color. | ||||||||||||
* | ||||||||||||
* @see Gfx_SetFog | ||||||||||||
*/ | ||||||||||||
Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) { | ||||||||||||
if (far == near) { | ||||||||||||
far++; | ||||||||||||
|
@@ -891,6 +913,11 @@ Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) | |||||||||||
return gfx; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Wrapper for Gfx_SetFog | ||||||||||||
* | ||||||||||||
* @see Gfx_SetFog | ||||||||||||
*/ | ||||||||||||
Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) { | ||||||||||||
return Gfx_SetFog(gfx, r, g, b, a, near, far); | ||||||||||||
} | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgive me but I find this comment somewhat clunky, I tried to rewrite it more to my liking