diff --git a/src/athmosphere.h b/src/athmosphere.h new file mode 100644 index 0000000..e28e71d --- /dev/null +++ b/src/athmosphere.h @@ -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 diff --git a/src/main.c b/src/main.c index 9b6f568..207ca98 100644 --- a/src/main.c +++ b/src/main.c @@ -164,6 +164,17 @@ int main(void) { render(&target, &rocket.model, &drawMat, buffer); 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); printf("\033[H"); printImage(encodeBuff);