Citro3d
Loading...
Searching...
No Matches
fog.c
Go to the documentation of this file.
1#include "internal.h"
2
3void FogLut_FromArray(C3D_FogLut* lut, const float data[256])
4{
5 int i;
6 for (i = 0; i < 128; i ++)
7 {
8 float in = data[i], diff = data[i+128];
9
10 u32 val = 0;
11 if (in > 0.0f)
12 {
13 in *= 0x800;
14 val = (in < 0x800) ? (u32)in : 0x7FF;
15 }
16
17 u32 val2 = 0;
18 if (diff != 0.0f)
19 {
20 diff *= 0x800;
21 if (diff < -0x1000) diff = -0x1000;
22 else if (diff > 0xFFF) diff = 0xFFF;
23 val2 = (s32)diff & 0x1FFF;
24 }
25
26 lut->data[i] = val2 | (val << 13);
27 }
28}
29
30void FogLut_Exp(C3D_FogLut* lut, float density, float gradient, float near, float far)
31{
32 int i;
33 float data[256];
34 for (i = 0; i <= 128; i ++)
35 {
36 float x = FogLut_CalcZ(i/128.0f, near, far);
37 float val = expf(-powf(density*x, gradient));
38 if (i < 128)
39 data[i] = val;
40 if (i > 0)
41 data[i+127] = val-data[i-1];
42 }
44}
45
46void C3D_FogGasMode(GPU_FOGMODE fogMode, GPU_GASMODE gasMode, bool zFlip)
47{
48 C3D_Context* ctx = C3Di_GetContext();
49
50 if (!(ctx->flags & C3DiF_Active))
51 return;
52
53 ctx->flags |= C3DiF_TexEnvBuf;
54 ctx->texEnvBuf &= ~0x100FF;
55 ctx->texEnvBuf |= (fogMode&7) | ((gasMode&1)<<3) | (zFlip ? BIT(16) : 0);
56}
57
58void C3D_FogColor(u32 color)
59{
60 C3D_Context* ctx = C3Di_GetContext();
61
62 if (!(ctx->flags & C3DiF_Active))
63 return;
64
65 ctx->flags |= C3DiF_TexEnvBuf;
66 ctx->fogClr = color;
67}
68
69void C3D_FogLutBind(C3D_FogLut* lut)
70{
71 C3D_Context* ctx = C3Di_GetContext();
72
73 if (!(ctx->flags & C3DiF_Active))
74 return;
75
76 if (lut)
77 {
78 ctx->flags |= C3DiF_FogLut;
79 ctx->fogLut = lut;
80 } else
81 ctx->flags &= ~C3DiF_FogLut;
82}
void FogLut_FromArray(C3D_FogLut *lut, const float data[256])
Definition: fog.c:3
void C3D_FogColor(u32 color)
Definition: fog.c:58
void FogLut_Exp(C3D_FogLut *lut, float density, float gradient, float near, float far)
Definition: fog.c:30
void C3D_FogLutBind(C3D_FogLut *lut)
Definition: fog.c:69
void C3D_FogGasMode(GPU_FOGMODE fogMode, GPU_GASMODE gasMode, bool zFlip)
Definition: fog.c:46
@ C3DiF_Active
Definition: internal.h:75
@ C3DiF_TexEnvBuf
Definition: internal.h:84
@ C3DiF_FogLut
Definition: internal.h:91
u32 flags
Definition: internal.h:38
u32 texEnvBuf
Definition: internal.h:51
u32 fogClr
Definition: internal.h:52
C3D_FogLut * fogLut
Definition: internal.h:53
float24Uniform_s * data
Definition: uniforms.c:16