Project

General

Profile

Actions

Emulator Issues #181

closed

Fog Emulation

Added by Sonicadvance1 over 15 years ago.

Status:
Fixed
Priority:
Low
Category:
GFX
% Done:

0%

Operating system:
N/A
Issue type:
Feature request
Milestone:
Regression:
No
Relates to usability:
No
Relates to performance:
No
Easy:
No
Relates to maintainability:
No
Regression start:
Fixed in:

Description

This isn't related to the Mario Kart overlay, this is actual fog.
I've managed to figure out with what is already in the code, the fog color,
the fog type, and possibly the fog density.
Density may be bpmem.fog.b_magnitude or bpmem.fog.a.GetA(), I'm not quite
sure yet.
I can't get the start of the fog and end of the fog, so this isn't helping
any. If anyone knows anything, this could help out a lot.

Also, I'm guessing ATI doesn't like GL fog, since it doesn't like anything GL

Actions #1

Updated by hrydgard over 15 years ago

You could reverse engineer the gxfog function in libogc..

Actions #2

Updated by XTra.KrazzY over 15 years ago

Yay, reversing libogc is great. Why haven't we thought about it earlier?

Range is half implemented and no games I saw use the backward exponential fog types.
Should there be one that does, please report and some effort will be done. There's no
documentation about any backward exponential fog anywhere.

Actions #3

Updated by Sonicadvance1 over 15 years ago

// 0xEE: (((farz*nearz)/ ((farz-nearz)*(endz-startz))) / (1 << b_expn)) >> 12
// 0xEF: B_Mant * 8388638
// 0xF0: b_expn
// 0xF1: c_hex, Function to get : startz / (endz - startz)
// 0xF2: Color, well known
Actions #4

Updated by XTra.KrazzY over 15 years ago

Backward exponential = Reverse exponential = Exponential decay
http://en.wikipedia.org/wiki/Exponential_decay

Actions #5

Updated by XTra.KrazzY over 15 years ago

Basically e-x for BACKEXP and e-2x for BACKEXP2, where x is the distance

Actions #6

Updated by XTra.KrazzY over 15 years ago

By the way... LibOGC's Setfog and params:

3860 void GX_SetFog(u8 type,f32 startz,f32 endz,f32 nearz,f32 farz,GXColor col)
3861 {
3862 f32 A, B, B_mant, C, A_f;
3863 u32 b_expn, b_m, a_hex, c_hex,proj = 0;
3864
3865
3866 proj = (u32)((type >> 3) & 0x01);
3867
3868 // Calculate constants a, b, and c (TEV HW requirements).
3869 if(proj) { // Orthographic Fog Type
3870 if((farz==nearz) || (endz==startz)) {
3871 // take care of the odd-ball case.
3872 A_f = 0.0f;
3873 C = 0.0f;
3874 } else {
3875 A = 1.0f/(endz-startz);
3876 A_f = (farz-nearz) * A;
3877 C = (startz-nearz) * A;
3878 }
3879
3880 b_expn = 0;
3881 b_m = 0;
3882 } else { // Perspective Fog Type
3883 // Calculate constants a, b, and c (TEV HW requirements).
3884 if((farz==nearz) || (endz==startz)) {
3885 // take care of the odd-ball case.
3886 A = 0.0f;
3887 B = 0.5f;
3888 C = 0.0f;
3889 } else {
3890 A = (farz*nearz)/((farz-nearz)(endz-startz));
3891 B = farz/(farz-nearz);
3892 C = startz/(endz-startz);
3893 }
3894
3895 B_mant = B;
3896 b_expn = 1;
3897 while(B_mant>1.0) {
3898 B_mant /= 2;
3899 b_expn++;
3900 }
3901
3902 while((B_mant>0) && (B_mant<0.5)) {
3903 B_mant *= 2;
3904 b_expn--;
3905 }
3906
3907 A_f = A/(1<<(b_expn));
3908 b_m = (u32)(B_mant * 8388638);
3909 }
3910 a_hex = (
(u32*)((void*)&A_f));
3911 c_hex = ((u32)((void*)&C));
3912
3913 GX_LOAD_BP_REG(0xee000000|(a_hex>>12));
3914 GX_LOAD_BP_REG(0xef000000|b_m);
3915 GX_LOAD_BP_REG(0xf0000000|b_expn);
3916 GX_LOAD_BP_REG(0xf1000000|((type<>12)));
3917 GX_LOAD_BP_REG(0xf2000000|(_SHIFTL(col.r,16,8)|_SHIFTL(col.g,8,8)|(col.b&0xff)));
3918 }
3919
3920 void GX_SetFogRangeAdj(u8 enable,u16 center,GXFogAdjTbl *table)
3921 {
3922 GX_LOAD_BP_REG(0xe8000156);
3923 }

Actions #7

Updated by XTra.KrazzY over 15 years ago

macros:

#define GX_LOAD_BP_REG(x) \
36 do { \
37 FIFO_PUTU8(0x61); \
38 FIFO_PUTU32((x)); \
39 } while(0)
40
41 #define GX_LOAD_CP_REG(x, y) \
42 do { \
43 FIFO_PUTU8(0x08); \
44 FIFO_PUTU8((x)); \
45 FIFO_PUTU32((y)); \
46 } while(0)
47
48 #define GX_LOAD_XF_REG(x, y) \
49 do { \
50 FIFO_PUTU8(0x10); \
51 FIFO_PUTU32(((x)&0xffff)); \
52 FIFO_PUTU32((y)); \
53 } while(0)
54
55 #define GX_LOAD_XF_REGS(x, n) \
56 do { \
57 FIFO_PUTU8(0x10); \
58 FIFO_PUTU32((((((n)&0xffff)-1)<<16)|((x)&0xffff))); \
59 } while(0)

Actions #8

Updated by XTra.KrazzY over 15 years ago

Implement it sonicadvance

By the way, sorry for the flood :}

Actions #9

Updated by XTra.KrazzY over 15 years ago

Just posting to say "Hey! Does anyone work on the fog? Can anyone write a homebrew
with fog so that I can test whether what I implement works or not?"

Actions #10

Updated by XTra.KrazzY about 15 years ago

AHEM:
http://www.patentstorm.us/patents/6580430/description.html

Inventors

* Hollis, Martin
* Law, Patrick Y.

Assignee

* Nintendo Co., Ltd.

Application
No. 726225 filed on 11/28/2000

"...the percentage of fog color blended with the pixel color is determined based on
one of the following two fog density functions:

Fog=(2-8)*(Ze-Z0)/Z1-Z0) (Backwards Exponential)

Fog=(2-8)(Ze-Z0)/Z1-Z0)*2 (Backwards Exponential Squared)

wherein Ze is an eye-space z value of the pixel, Z0 is an eye-space z value at which
fog begins, and Z1 is an eye-space z value at which fog density substantially reaches
a maximum value.

A range adjustment is preferably made to the eye-space z value (Ze) prior to applying
the fog density function in order to compensate for the change in range as the
viewing angle increases in the x direction away from the Z axis."

Actions #12

Updated by XTra.KrazzY about 15 years ago

  • Status changed from New to Work started
Actions #13

Updated by zantezuken about 15 years ago

I've found some problems which fog produces in RE0
-> RE0 r2308: http://img10.imageshack.us/img10/9048/nofog.png
-> RE0 r2310: http://img10.imageshack.us/img10/1159/fog.png
-> Fullscreen snapshot: http://img24.imageshack.us/img24/7499/fogfull.png

RE1 doesn't affected by that.

Actions #15

Updated by donkopunchstania about 15 years ago

@zantezuken I don't see an issue with the screens you posted. The one with fog looks
different because there is fog, but I don't think it looks wrong.

Are there any problems or can this issue be closed?

Actions #16

Updated by XTra.KrazzY about 15 years ago

I verified that this issue may be closed. Even the WindWaker fog works nice now
(though it's very far and in order to really see it you have to fly very high/look
very far. In any case, there are some DoF blurring shaders we are missing but they
are far from being fog)

I think this case is closed and we can consider fog done. Great work donko.

Actions #17

Updated by zantezuken about 15 years ago

"@zantezuken I don't see an issue with the screens you posted. The one with fog looks
different because there is fog, but I don't think it looks wrong.
Are there any problems or can this issue be closed?"

Such fog is EVERYWHERE but he SHOULDN'T be there. Just looks at original screens
from GameCube itself.
It looks completelly ugly, just like brightness @ max.
P.S. Can be fog feature configurable (ON/OFF)?

Actions #18

Updated by federelli about 15 years ago

Screens look perfectly fine to me as well, fog is applied everywhere as it should be,
stronger on the backgrounds and softer on the foreground.

Actions #19

Updated by donkopunchstania about 15 years ago

There is no range (horizontal) fog adjustment. This and toggling fog on/off are
possible new issues, but the original issue here is resolved.

Actions #21

Updated by Anonymous almost 13 years ago

  • Status changed from Work started to Fixed

Ignore this...Status:Verified was removed, changing to Fixed

Actions

Also available in: Atom PDF