Make depth buffer 8 bit

This commit is contained in:
duarteapcoelho 2022-12-08 15:44:53 +00:00
parent 003955e423
commit 136e536544
3 changed files with 19 additions and 12 deletions

View File

@ -28,13 +28,13 @@ vec3<float> cameraSpeed = {0, 0, 0};
float cameraAngle = 0;
#ifdef GINT
static GALIGNED(32) fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
static GALIGNED(32) unsigned char depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
#include "models.h"
#endif
int main(){
#ifndef GINT
fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
unsigned char depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
#include "models.h"
#endif
Rasterizer::depthBuffer = depthBuffer;

View File

@ -37,7 +37,7 @@ inline int max(int a, int b){
namespace Rasterizer {
Plane clippingPlanes[5];
fp *depthBuffer;
unsigned char *depthBuffer;
fp fov_d = 1;
@ -50,14 +50,21 @@ namespace Rasterizer {
}
void reset(){
unsigned char value = -1;
#if GINT || PRIZM
long v = value | (value << 8) | (value << 16) | (value << 24);
#endif
#if GINT && PIXEL_SIZE == 1
fp v = -1;
fp *depthBuffer_P1 = (fp*) mmu_translate_uram(depthBuffer);
cache_ocbp(depthBuffer, RENDER_WIDTH*RENDER_HEIGHT*sizeof(fp));
dma_memset(depthBuffer_P1, *((uint32_t*)&v), RENDER_WIDTH*RENDER_HEIGHT*sizeof(fp));
unsigned char *depthBuffer_P1 = (unsigned char*) mmu_translate_uram(depthBuffer);
cache_ocbp(depthBuffer, RENDER_WIDTH*RENDER_HEIGHT*sizeof(unsigned char));
dma_memset(depthBuffer_P1, *((uint32_t*)&v), RENDER_WIDTH*RENDER_HEIGHT*sizeof(unsigned char));
#elif PRIZM
for(int i = 0; i < RENDER_WIDTH*RENDER_HEIGHT/4; i++){
*(((long*)depthBuffer) + i) = v;
}
#else
for(int i = 0; i < RENDER_WIDTH*RENDER_HEIGHT; i++){
depthBuffer[i] = -1;
depthBuffer[i] = value;
}
#endif
}
@ -98,7 +105,7 @@ namespace Rasterizer {
}
// Draws a triangle which has a horizontal top or bottom
inline void _drawFlatSideTriangle(vec3<int> points[3], fp z, Color color, bool useDepth){
inline void _drawFlatSideTriangle(vec3<int> points[3], unsigned char z, Color color, bool useDepth){
if(points[0].y == points[1].y && points[1].y == points[2].y && points[2].y == points[0].y){
return;
}
@ -141,7 +148,7 @@ namespace Rasterizer {
#endif
for(int x = minX; x <= maxX; x++){
if(z < depthBuffer[p] || depthBuffer[p] == fp(-1) || !useDepth){
if(z < depthBuffer[p] || !useDepth){
if(useDepth){
depthBuffer[p] = z;
}
@ -181,7 +188,7 @@ namespace Rasterizer {
return;
}
fp z = (points[0].z + points[1].z + points[2].z) / 3;
unsigned char z = (points[0].z + points[1].z + points[2].z) / 3;
if(isShaded){
fp brightness = dot(mat4::toMat3(model->modelMatrix) * triangle.normal, vec3<fp>(I_SQRT_3, -I_SQRT_3, -I_SQRT_3)) * fp(0.6) + fp(0.4);

View File

@ -38,7 +38,7 @@ public:
namespace Rasterizer {
void init();
void reset();
extern fp *depthBuffer;
extern unsigned char *depthBuffer;
extern fp fov_d;
void setFOV(int fov);