feat: started athmospheare post processing

This commit is contained in:
2026-04-19 20:47:11 +02:00
parent 5432141c0d
commit cf52d23ab8
2 changed files with 41 additions and 0 deletions

30
src/athmosphere.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef ATHMOSPHERE_H
#define ATHMOSPHERE_H
#include "linmath.h"
#include "rendertarget.h"
void renderAthmosphere(render_target *target, const mat4x4 invProj) {
float widthF = 2. / target->width;
float heightF = 2. / target->height;
for (int y = 0; y < target->height; y++) {
for (int x = 0; x < target->width; x++) {
vec4 tmp = {((float)x) * widthF - 1.f, ((float)y) * heightF - 1.0f,
((float)target_get_depth(target, x, y)) / 65536.0f, 1.0f};
// vec4_scale(tmp, tmp, 1.0f / tmp[2]);
vec4 pos;
mat4x4_mul_vec4(pos, invProj, tmp);
vec4_scale(pos, pos, 1.0f / pos[3]);
// pos[2] = -pos[2];
vec4_scale(pos, pos, -.1f);
// vec4_scale(tmp, tmp, -1.f);
// tmp[3] = -tmp[2];
vec3_set(pos, pos[2]);
target_set_color(target, x, y, pos);
}
}
}
#endif

View File

@@ -164,6 +164,17 @@ int main(void) {
render(&target, &rocket.model, &drawMat, buffer); render(&target, &rocket.model, &drawMat, buffer);
renderC = clock() - renderC; renderC = clock() - renderC;
mat4x4 invProj;
mat4x4_invert(invProj, rData.projMat);
athmosC = clock();
// renderAthmosphere(&target, invProj);
athmosC = clock() - athmosC;
if (didHit(rocket)) {
stop = 1;
}
base64encode(&target, encodeBuff); base64encode(&target, encodeBuff);
printf("\033[H"); printf("\033[H");
printImage(encodeBuff); printImage(encodeBuff);