Start floor particles
This commit is contained in:
parent
71b1230880
commit
fde803bb18
2 changed files with 66 additions and 11 deletions
64
renderer.h
64
renderer.h
|
@ -21,6 +21,7 @@
|
|||
// ^ just S3L_FRACTIONS_PER_UNIT leaves some tris bugging
|
||||
|
||||
#define LCR_RENDERER_CHUNK_RESOLUTION 4 // do not change
|
||||
#define LCR_RENDERER_LOD_BLOCKS 64 // do not change
|
||||
|
||||
#define LCR_RENDERER_CHUNK_SIZE_HORIZONTAL \
|
||||
((LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT) / LCR_RENDERER_CHUNK_RESOLUTION)
|
||||
|
@ -28,17 +29,21 @@
|
|||
#define LCR_RENDERER_CHUNKS_TOTAL (LCR_RENDERER_CHUNK_RESOLUTION * \
|
||||
LCR_RENDERER_CHUNK_RESOLUTION * LCR_RENDERER_CHUNK_RESOLUTION)
|
||||
|
||||
#define LCR_RENDERER_LOD_BLOCKS 64
|
||||
#define LCR_RENDERER_MODEL_COUNT 8
|
||||
|
||||
struct
|
||||
{
|
||||
S3L_Scene scene;
|
||||
|
||||
S3L_Model3D mapModel; ///< whole map model
|
||||
S3L_Model3D models[8];
|
||||
/**< 0, 1, 2, 3, 4, 5, 6, 7: nearest map chunk models */
|
||||
|
||||
uint8_t loadedChunks[8];
|
||||
/**
|
||||
The scene model array.
|
||||
0, 1, 2, 3, 4, 5, 6, 7: nearest map chunk models
|
||||
*/
|
||||
S3L_Model3D models[LCR_RENDERER_MODEL_COUNT];
|
||||
|
||||
uint8_t loadedChunks[8]; ///< numbers of loaded map chunks
|
||||
|
||||
S3L_Unit mapVerts[LCR_SETTING_MAX_MAP_VERTICES * 3];
|
||||
S3L_Index mapTris[LCR_SETTING_MAX_MAP_TRIANGLES * 3];
|
||||
|
@ -52,7 +57,11 @@ struct
|
|||
*/
|
||||
uint8_t mapTriangleData[LCR_SETTING_MAX_MAP_TRIANGLES];
|
||||
|
||||
uint8_t gridLOD[LCR_RENDERER_LOD_BLOCKS];
|
||||
/**
|
||||
8x8x8 3D grid of bits, each bit says (for each corresponding part of map)
|
||||
whether there is an LOD block or not.
|
||||
*/
|
||||
uint8_t gridOfLODs[LCR_RENDERER_LOD_BLOCKS];
|
||||
|
||||
// pixel function precomputed values:
|
||||
int previousTriID;
|
||||
|
@ -668,7 +677,7 @@ void _LCR_rendererComputeLOD(void)
|
|||
LCR_log("computing LOD");
|
||||
|
||||
for (int i = 0; i < LCR_RENDERER_LOD_BLOCKS; ++i)
|
||||
LCR_renderer.gridLOD[i] = 0;
|
||||
LCR_renderer.gridOfLODs[i] = 0;
|
||||
|
||||
for (int i = 0; i < LCR_currentMap.blockCount; ++i)
|
||||
{
|
||||
|
@ -680,7 +689,7 @@ void _LCR_rendererComputeLOD(void)
|
|||
y /= 8;
|
||||
z /= 8;
|
||||
|
||||
LCR_renderer.gridLOD[z * 8 + y] |= (0x01 << x);
|
||||
LCR_renderer.gridOfLODs[z * 8 + y] |= (0x01 << x);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -696,7 +705,7 @@ uint8_t LCR_rendererInit(void)
|
|||
_LCR_rendererComputeLOD();
|
||||
|
||||
S3L_sceneInit(
|
||||
LCR_renderer.models,8,&LCR_renderer.scene);
|
||||
LCR_renderer.models,LCR_RENDERER_MODEL_COUNT,&LCR_renderer.scene);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1043,9 +1052,9 @@ void LCR_rendererDrawLOD(void)
|
|||
{
|
||||
#if LCR_SETTING_LOD_DISTANCE < 64
|
||||
for (unsigned int i = 0; i < LCR_RENDERER_LOD_BLOCKS; ++i)
|
||||
if (LCR_renderer.gridLOD[i])
|
||||
if (LCR_renderer.gridOfLODs[i])
|
||||
{
|
||||
uint8_t byte = LCR_renderer.gridLOD[i];
|
||||
uint8_t byte = LCR_renderer.gridOfLODs[i];
|
||||
unsigned int bx, by, bz;
|
||||
|
||||
bz = (i / 8) * 8 + 4;
|
||||
|
@ -1071,6 +1080,40 @@ void LCR_rendererDrawLOD(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void LCR_drawLevelFloor(void)
|
||||
{
|
||||
#if LCR_SETTING_FLOOR_PARTICLE_SIZE != 0
|
||||
#define _STEP ((LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT) / LCR_SETTING_FLOOR_PARTICLE_RESOLUTION)
|
||||
|
||||
S3L_Vec4 floorPoint, projectedPoint;
|
||||
|
||||
floorPoint.z = -1 * (LCR_MAP_SIZE_BLOCKS / 2) * LCR_RENDERER_UNIT + _STEP / 2;
|
||||
floorPoint.y = -1 *(LCR_MAP_SIZE_BLOCKS / 2) * (LCR_RENDERER_UNIT / 2);
|
||||
floorPoint.w = LCR_SETTING_RESOLUTION_X / LCR_SETTING_FLOOR_PARTICLE_SIZE;
|
||||
|
||||
for (uint8_t j = 0; j < LCR_SETTING_FLOOR_PARTICLE_RESOLUTION; ++j)
|
||||
{
|
||||
floorPoint.x = -1 * (LCR_MAP_SIZE_BLOCKS / 2) * LCR_RENDERER_UNIT
|
||||
+ _STEP / 2;
|
||||
|
||||
for (uint8_t i = 0; i < LCR_SETTING_FLOOR_PARTICLE_RESOLUTION; ++i)
|
||||
{
|
||||
S3L_project3DPointToScreen(floorPoint,LCR_renderer.scene.camera,
|
||||
&projectedPoint);
|
||||
|
||||
if (projectedPoint.w > 0 && projectedPoint.w < LCR_EFFECTIVE_RESOLUTION_X)
|
||||
LCR_rendererDrawRect(projectedPoint.x,projectedPoint.y,
|
||||
projectedPoint.w,projectedPoint.w,LCR_SETTING_LOD_COLOR,1);
|
||||
|
||||
floorPoint.x += _STEP;
|
||||
}
|
||||
|
||||
floorPoint.z += _STEP;
|
||||
}
|
||||
#undef _STEP
|
||||
#endif
|
||||
}
|
||||
|
||||
void LCR_rendererDraw(void)
|
||||
{
|
||||
LCR_renderer.previousTriID = -1;
|
||||
|
@ -1082,6 +1125,7 @@ void LCR_rendererDraw(void)
|
|||
LCR_renderer.scene.camera.transform.rotation.y,
|
||||
-4 * LCR_renderer.scene.camera.transform.rotation.x);
|
||||
|
||||
LCR_drawLevelFloor();
|
||||
LCR_rendererDrawLOD();
|
||||
|
||||
S3L_drawScene(LCR_renderer.scene);
|
||||
|
|
13
settings.h
13
settings.h
|
@ -20,7 +20,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_FREE_CAMERA_SPEED
|
||||
#define LCR_SETTING_FREE_CAMERA_SPEED 50
|
||||
#define LCR_SETTING_FREE_CAMERA_SPEED 30
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_FREE_CAMERA_TURN_SPEED
|
||||
|
@ -81,4 +81,15 @@
|
|||
#define LCR_SETTING_LOD_COLOR 0x4229
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_FLOOR_PARTICLE_RESOLUTION
|
||||
/** How many level floor particles there will be along one principal axis, 0
|
||||
turns floor particles off. */
|
||||
#define LCR_SETTING_FLOOR_PARTICLE_RESOLUTION 6
|
||||
#endif
|
||||
|
||||
#ifndef LCR_SETTING_FLOOR_PARTICLE_SIZE
|
||||
/** Defines floor particle size in fractions of screen size. */
|
||||
#define LCR_SETTING_FLOOR_PARTICLE_SIZE 32
|
||||
#endif
|
||||
|
||||
#endif // guard
|
||||
|
|
Loading…
Reference in a new issue