GameCube/Wii: Implement fog

This commit is contained in:
UnknownShadow200 2024-06-19 18:38:20 +10:00
parent 3275675b8e
commit f6666d59b2
4 changed files with 44 additions and 2 deletions

View file

@ -63,6 +63,9 @@ include $(PS2SDK)/samples/Makefile.pref
$(BUILD_DIR)/%.o: src/%.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c # IOP modules
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
$(BUILD_DIR)/%.o: %.S
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@

View file

@ -387,24 +387,63 @@ static PackedCol gfx_fogColor;
static float gfx_fogEnd = -1.0f, gfx_fogDensity = -1.0f;
static int gfx_fogMode = -1;
static void UpdateFog(void) {
float beg = 0.0f, end = 0.0f;
float near = 0.1f, far = Game_ViewDistance;
int mode = GX_FOG_NONE;
GXColor color;
color.r = PackedCol_R(gfx_fogColor);
color.g = PackedCol_G(gfx_fogColor);
color.b = PackedCol_B(gfx_fogColor);
color.a = PackedCol_A(gfx_fogColor);
// Fog end values based off https://github.com/devkitPro/opengx/blob/master/src/gc_gl.c#L1770
if (!gfx_fogEnabled) {
near = 0.0f;
far = 0.0f;
} else if (gfx_fogMode == FOG_LINEAR) {
mode = GX_FOG_LIN;
end = gfx_fogEnd;
} else if (gfx_fogMode == FOG_EXP) {
mode = GX_FOG_EXP;
beg = near;
end = 5.0f / gfx_fogDensity;
} else if (gfx_fogMode == FOG_EXP2) {
mode = GX_FOG_EXP2;
beg = near;
end = 2.0f / gfx_fogDensity;
}
GX_SetFog(mode, beg, end, near, far, color);
}
void Gfx_SetFog(cc_bool enabled) {
gfx_fogEnabled = enabled;
UpdateFog();
}
void Gfx_SetFogCol(PackedCol color) {
if (color == gfx_fogColor) return;
gfx_fogColor = color;
UpdateFog();
}
void Gfx_SetFogDensity(float value) {
if (value == gfx_fogDensity) return;
gfx_fogDensity = value;
UpdateFog();
}
void Gfx_SetFogEnd(float value) {
if (value == gfx_fogEnd) return;
gfx_fogEnd = value;
UpdateFog();
}
void Gfx_SetFogMode(FogFunc func) {
if (func == gfx_fogMode) return;
gfx_fogMode = func;
UpdateFog();
}
static void SetAlphaTest(cc_bool enabled) {

View file

@ -1380,7 +1380,7 @@ void GLContext_Free(void) {
}
void* GLContext_GetAddress(const char* function) {
return (void*)glXGetProcAddress((const GLubyte*)function);
return (void*)glXGetProcAddress(function);
}
cc_bool GLContext_SwapBuffers(void) {

View file

@ -354,7 +354,7 @@ void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* par
Gfx_UpdateTexture(texId, x, y, part, part->width, mipmaps);
}
static void CopyTextureData(void* dst, int dstStride, const struct Bitmap* src, int srcStride) {
static CC_INLINE void CopyTextureData(void* dst, int dstStride, const struct Bitmap* src, int srcStride) {
cc_uint8* src_ = (cc_uint8*)src->scan0;
cc_uint8* dst_ = (cc_uint8*)dst;
int y;