Finish sky drawing

This commit is contained in:
Miloslav Ciz 2024-07-30 21:47:50 +02:00
parent 681bcf2712
commit 2caa4299e2
3 changed files with 2371 additions and 23 deletions

2326
assets.h

File diff suppressed because it is too large Load diff

View file

@ -307,7 +307,7 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1,
that by this become unused). This makes the map model smaller, faster and that by this become unused). This makes the map model smaller, faster and
prevents bleeding through due to z-bugger imprecisions. prevents bleeding through due to z-bugger imprecisions.
*/ */
void _LCR_rendererPruneHiddenMapTriangles(void) void _LCR_rendererCullHiddenMapTriangles(void)
{ {
int n = 0; // number of removed elements int n = 0; // number of removed elements
int i = 0; int i = 0;
@ -437,7 +437,7 @@ uint8_t _LCR_rendererBuildMapModel(void)
} }
} }
_LCR_rendererPruneHiddenMapTriangles(); _LCR_rendererCullHiddenMapTriangles();
return 1; return 1;
} }
@ -497,10 +497,12 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
unsigned long pixelIndex; unsigned long pixelIndex;
unsigned int topColor, bottomColor; unsigned int topColor, bottomColor;
LCR_loadImage(8); sky = 8 + 4 * sky;
LCR_loadImage(sky);
topColor = LCR_sampleImage(0,0); topColor = LCR_sampleImage(0,0);
LCR_loadImage(8 + 3); LCR_loadImage(sky + 3);
bottomColor = LCR_sampleImage(LCR_IMAGE_SIZE - 1,LCR_IMAGE_SIZE - 1); bottomColor = LCR_sampleImage(LCR_IMAGE_SIZE - 1,LCR_IMAGE_SIZE - 1);
anchorPoint[0] = ((LCR_EFFECTIVE_RESOLUTION_X * offsetH) anchorPoint[0] = ((LCR_EFFECTIVE_RESOLUTION_X * offsetH)
@ -511,7 +513,7 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
anchorPoint[0] += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; anchorPoint[0] += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
anchorPoint[1] = anchorPoint[1] =
(LCR_EFFECTIVE_RESOLUTION_Y) / 2 - (LCR_EFFECTIVE_RESOLUTION_Y) / 3 - // 3: we place the center a bit more up
(LCR_EFFECTIVE_RESOLUTION_Y * offsetV) / S3L_FRACTIONS_PER_UNIT (LCR_EFFECTIVE_RESOLUTION_Y * offsetV) / S3L_FRACTIONS_PER_UNIT
- LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; - LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
@ -538,7 +540,7 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
{ {
if (!linesLeft) if (!linesLeft)
{ {
LCR_loadImage(8 + skyPart); LCR_loadImage(sky + skyPart);
linesLeft = LCR_IMAGE_SIZE / 2; linesLeft = LCR_IMAGE_SIZE / 2;
skyPart++; skyPart++;
} }
@ -549,27 +551,53 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
ix += LCR_SETTING_SKY_SIZE) ix += LCR_SETTING_SKY_SIZE)
{ {
unsigned int color = LCR_getNextImagePixel(); unsigned int color = LCR_getNextImagePixel();
unsigned long startIndex = pixelIndex;
int x = anchorPoint[0] + ix; for (int k = 0; k < LCR_SETTING_SKY_SIZE; ++k)
{
if (y + k >= LCR_EFFECTIVE_RESOLUTION_Y)
break;
for (int j = 0; j < LCR_SETTING_SKY_SIZE; ++j)
{
int x = anchorPoint[0] + ix + j;
if (x >= 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE) if (x >= 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE)
x -= 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; x -= 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
while (x < LCR_EFFECTIVE_RESOLUTION_X) while (x < LCR_EFFECTIVE_RESOLUTION_X)
{ {
LCR_drawPixel(pixelIndex + x,color); LCR_drawPixel(startIndex + x,color);
x += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; x += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
} }
} }
startIndex += LCR_EFFECTIVE_RESOLUTION_X;
}
}
pixelIndex += LCR_EFFECTIVE_RESOLUTION_X * LCR_SETTING_SKY_SIZE; pixelIndex += LCR_EFFECTIVE_RESOLUTION_X * LCR_SETTING_SKY_SIZE;
y += LCR_SETTING_SKY_SIZE;
} }
else else
{
for (int ix = 0; ix < 2 * LCR_IMAGE_SIZE; ++ix) for (int ix = 0; ix < 2 * LCR_IMAGE_SIZE; ++ix)
LCR_getNextImagePixel(); LCR_getNextImagePixel();
for (int i = 0; i < LCR_SETTING_SKY_SIZE; ++i)
{
if (y >= 0)
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
{
LCR_drawPixel(pixelIndex,topColor);
pixelIndex++;
}
y++;
}
}
linesLeft--; linesLeft--;
y += LCR_SETTING_SKY_SIZE;
} }
while (y < 0) // can still be the case while (y < 0) // can still be the case
@ -592,12 +620,8 @@ void LCR_rendererDraw(void)
LCR_renderer.previousTriangleID = -1; LCR_renderer.previousTriangleID = -1;
S3L_newFrame(); S3L_newFrame();
// REMOVE LATER LCR_rendererDrawSky(2,
for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X * LCR_EFFECTIVE_RESOLUTION_Y; ++i) LCR_renderer.scene3D.camera.transform.rotation.y,
LCR_drawPixel(i,0xffff);
LCR_rendererDrawSky(0,
LCR_renderer.scene3D.camera.transform.rotation.y / 8,
-4 * LCR_renderer.scene3D.camera.transform.rotation.x); -4 * LCR_renderer.scene3D.camera.transform.rotation.x);
S3L_drawScene(LCR_renderer.scene3D); S3L_drawScene(LCR_renderer.scene3D);

View file

@ -48,7 +48,7 @@
#ifndef LCR_SETTING_SKY_SIZE #ifndef LCR_SETTING_SKY_SIZE
/** Size of sky texture pixel, 0 turns off sky rendering. */ /** Size of sky texture pixel, 0 turns off sky rendering. */
#define LCR_SETTING_SKY_SIZE 2 #define LCR_SETTING_SKY_SIZE 4
#endif #endif
#ifndef LCR_SETTING_MAP_MAX_SIZE #ifndef LCR_SETTING_MAP_MAX_SIZE