Add potato mode

This commit is contained in:
Miloslav Ciz 2024-12-18 18:40:03 +01:00
parent 5d9038021a
commit e42212d7c1
4 changed files with 95 additions and 7 deletions

View file

@ -12,6 +12,12 @@
#define S3L_NEAR_CROSS_STRATEGY 1
#define S3L_Z_BUFFER 1
#if LCR_SETTING_POTATO_GRAPHICS
#define S3L_PERSPECTIVE_CORRECTION 0
#define S3L_NEAR_CROSS_STRATEGY 1
#define S3L_FLAT 1
#endif
#include "small3dlib.h"
/// Renderer specific unit, length of one map square.
@ -190,6 +196,47 @@ void LCR_rendererDrawText(const char *text, int x, int y, uint16_t color,
void _LCR_pixelFunc3D(S3L_PixelInfo *pixel)
{
#if LCR_SETTING_POTATO_GRAPHICS
// simple shader for simplified graphics
if (pixel->triangleID != LCR_renderer.previousTriID)
{
LCR_renderer.previousTriID = pixel->triangleID;
LCR_renderer.flatAndTransparent = 0x630c; // base gray
if (pixel->modelIndex < 8)
{
uint8_t tData =
(LCR_renderer.mapTriangleData +
LCR_renderer.chunkStarts[LCR_renderer.loadedChunks[
pixel->modelIndex]])[pixel->triangleIndex];
switch (tData & 0x0f)
{
case 3: LCR_renderer.flatAndTransparent &= ~(0x3008); break; // grass
case 4: LCR_renderer.flatAndTransparent &= ~(0x0408); break; // mud
case 5: LCR_renderer.flatAndTransparent |= 0x0010; break; // ice
case 6: LCR_renderer.flatAndTransparent |= 0x8080; break; // acc
case 7: LCR_renderer.flatAndTransparent &= ~(0x4208); break; // fan
default: break;
}
tData &= 0x30;
LCR_renderer.flatAndTransparent |=
(((uint16_t) (tData)) >> 4) |
(((uint16_t) (tData)) << 2) |
(((uint16_t) (tData)) << 7);
}
else
LCR_renderer.flatAndTransparent >>= 1; // car, darken
LCR_renderer.flatAndTransparent += pixel->triangleIndex % 4;
}
LCR_drawPixelXYUnsafe(pixel->x,pixel->y,LCR_renderer.flatAndTransparent);
#else // LCR_SETTING_POTATO_GRAPHICS
// once we get a new triangle, we precompute things for it:
if (pixel->triangleID != LCR_renderer.previousTriID)
{
@ -352,6 +399,7 @@ void _LCR_pixelFunc3D(S3L_PixelInfo *pixel)
#endif
LCR_drawPixelXYUnsafe(pixel->x,pixel->y,color);
#endif // LCR_SETTING_POTATO_GRAPHICS
}
S3L_Index _LCR_rendererAddMapVert(S3L_Unit x, S3L_Unit y, S3L_Unit z)
@ -1199,6 +1247,10 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
{
LCR_LOG2("drawing sky");
#if LCR_SETTING_POTATO_GRAPHICS
LCR_rendererDrawRect(0,0,LCR_EFFECTIVE_RESOLUTION_X,
LCR_EFFECTIVE_RESOLUTION_Y,0x7bfd,0);
#else
int anchorPoint[2], y;
unsigned long pixelIndex;
unsigned int topColor, bottomColor;
@ -1319,6 +1371,7 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
y++;
}
#endif
}
void _LCR_rendererLoadMapChunk(uint8_t chunk, int8_t x, int8_t y, int8_t z)
@ -1672,7 +1725,31 @@ void LCR_rendererDraw(void)
LCR_rendererDrawLOD();
LCR_LOG2("gonna render 3D scene");
#if LCR_SETTING_POTATO_GRAPHICS
/* in potato mode we render twice so that car is always in front of the
level model (lack of precise depth causes artifacts otherwise) */
LCR_renderer.carModel->config.visible = 0;
LCR_renderer.ghostModel->config.visible = 0;
S3L_drawScene(LCR_renderer.scene);
for (int i = 0; i < LCR_renderer.scene.modelCount; ++i)
LCR_renderer.scene.models[i].config.visible = 0;
LCR_renderer.carModel->config.visible = 1;
LCR_renderer.ghostModel->config.visible = 1;
S3L_newFrame();
S3L_drawScene(LCR_renderer.scene);
for (int i = 0; i < LCR_renderer.scene.modelCount; ++i)
LCR_renderer.scene.models[i].config.visible = 1;
#else
S3L_drawScene(LCR_renderer.scene);
#endif
LCR_LOG2("rendering 3D scene done");
LCR_renderer.frame++;