This commit is contained in:
2026-04-03 12:34:06 +02:00
parent cd77088dbf
commit 85dbded287
25 changed files with 2711 additions and 165 deletions

View File

@@ -6,11 +6,10 @@
#include "model.hpp"
#include "polygon.hpp"
#include "rendertarget.hpp"
#include <bits/stdc++.h>
#include <cstring>
#include <memory.h>
#define SCREEN_SPACE_SIZE 8.0
#define SCREEN_SPACE_SIZE 2.0
class Renderer {
@@ -22,9 +21,9 @@ class Renderer {
void toScreenSpace(vec3 *np, mat4 matrix) {
vec4 tp = (matrix * vec4(*np, decimal(1.0f)));
tp.x() = tp.x() / tp.z() * decimal(2.0) * decimal(SCREEN_SPACE_SIZE) +
tp.x() = tp.x() / tp.z() * decimal(SCREEN_SPACE_SIZE) +
decimal(SCREEN_SPACE_SIZE);
tp.y() = tp.y() / tp.z() * decimal(2.0) * decimal(SCREEN_SPACE_SIZE) +
tp.y() = tp.y() / tp.z() * decimal(SCREEN_SPACE_SIZE) +
decimal(SCREEN_SPACE_SIZE);
*np = vec3(tp.x(), tp.y(), tp.z());
}
@@ -41,12 +40,6 @@ class Renderer {
decimal((float)(target->height / SCREEN_SPACE_SIZE / 2));
// TODO clear target with memset
if (clearTarget) {
// memset((wchar_t *)target->pixels, 0,
// target->height * target->width * sizeof(target[0]));
target->clearDepth();
target->clearTarget();
}
vec3 verts[model->verts.size()] = {};
@@ -79,22 +72,37 @@ class Renderer {
int startX = std::max<int>(
(testP.bounding[0] * invWidthScale).i >> SHIFT_AMOUNT, 0);
int endX = std::min<int>((testP.bounding[1] * invWidthScale).i >>
SHIFT_AMOUNT,
(uint32_t)target->width - 1);
int endX = std::max<int>(
std::min<int>((testP.bounding[1] * invWidthScale).i >>
SHIFT_AMOUNT,
(uint32_t)target->width - 1),
0);
int startY = std::max<int>(
(testP.bounding[2] * invHeightScale).i >> SHIFT_AMOUNT, 0);
int endY = std::min<int>((testP.bounding[3] * invHeightScale).i >>
SHIFT_AMOUNT,
target->height - 1);
std::cout << "Polys:\n" << testP.baryFactor << "\n";
for (int i = 0; i < 3; i++) {
std::cout << testP.points[i];
}
std::cout << "Boundings:\n";
std::cout << testP.bounding[0] << " " << startX << "\n";
std::cout << testP.bounding[1] << " " << endX << "\n";
std::cout << testP.bounding[2] << " " << startY << "\n";
std::cout << testP.bounding[3] << " " << endY << "\n";
vec3 pos = vec3(testP.bounding[0], testP.bounding[2], 0.0);
for (int x = startX; x < endX; x++) {
for (int y = startY; y < endY; y++) {
for (int x = 0; x < target->width; x++) {
for (int y = 0; y < target->height; y++) {
// for (int x = startX; x < endX; x++) {
// for (int y = startY; y < endY; y++) {
if (testP.depContains(pos)) {
testP.calcBarycentric(pos);
if (testP.contains(pos)) {
testP.calcBarycentric(pos);
// testP.calcBarycentric(pos);
decimal depth = testP.calcDepth();
if (depth < target->getDepth(x, y)) {
// std::cout << factors << std::endl;
@@ -105,8 +113,8 @@ class Renderer {
decimal(0.5);
;
target->setDepth(x, y, depth);
target->set(x, y,
(color * decimal(120.0)) * lightFac);
// target->set(x, y,
// (color * decimal(120.0)) * lightFac);
// target->set(x, y,
// vec3(lightFac * decimal(200.0), 0, 0));
@@ -117,8 +125,8 @@ class Renderer {
// x, y,
// (testP.avgNormal() + vec3(1.0, 1.0, 1.0)) *
// decimal(120.0));
// target->set(x, y,
// testP.barycentrics * decimal(200.0));
target->set(x, y,
testP.barycentrics * decimal(200.0));
// if (!factors.isSmall())
// target->set(x, y, vec3(0., 255.0, 0.));
}