102 lines
4.5 KiB
C++
Raw Normal View History

2024-10-18 15:14:18 -04:00
#include <symbols/minecraft.h>
#include <libreborn/libreborn.h>
#include "shading-internal.h"
// PolygonQuad
Vec3 vector_to(const Vec3 &a, const Vec3 &b) {
2024-11-08 02:34:58 -05:00
return Vec3(b.x - a.x, b.y - a.y, b.z - a.z);
2024-10-18 15:14:18 -04:00
}
Vec3 vector_cross(const Vec3 &a, const Vec3 &b) {
2024-11-08 02:34:58 -05:00
return Vec3((a.y * b.z) - (a.z * b.y), (a.z * b.x) - (a.x * b.z), (a.x * b.y) - (a.y * b.x));
2024-10-18 15:14:18 -04:00
}
2024-10-19 05:19:08 -04:00
static void PolygonQuad_render_injection(PolygonQuad_render_t original, PolygonQuad *self, Tesselator &t, const float scale, const int buffer) {
2024-10-18 15:14:18 -04:00
// Set Normal
const Vec3 v0 = vector_to(self->vertices[1].pos, self->vertices[0].pos);
const Vec3 v1 = vector_to(self->vertices[1].pos, self->vertices[2].pos);
const Vec3 n = vector_cross(v1, v0).normalized();
t.normal(n.x, n.y, n.z);
// Call Original Method
original(self, t, scale, buffer);
}
2024-10-19 05:19:08 -04:00
// Specify Normal Before Vertex
#define add_normal_before(type, name) \
2024-10-20 18:10:17 -04:00
template <int nx, int ny, int nz> \
2024-10-19 05:19:08 -04:00
static decltype(auto) type##_##name##_injection(type *self, auto... args) { \
Tesselator::instance.normal(nx, ny, nz); \
return self->name(std::forward<decltype(args)>(args)...); \
} \
2024-10-20 18:10:17 -04:00
template <int nx, int ny, int nz> \
2024-10-19 05:19:08 -04:00
static void add_normal_before_##name(uint32_t addr) { \
std::remove_pointer_t<decltype(type##_##name)>::ptr_type func = type##_##name##_injection<nx, ny, nz>; \
overwrite_call((void *) addr, (void *) func); \
}
add_normal_before(Tesselator, vertexUV)
add_normal_before(Tesselator, vertex)
add_normal_before(Tile, getTexture2)
add_normal_before(TileRenderer, tesselateCrossTexture)
add_normal_before(Tile, updateDefaultShape)
2024-10-18 15:14:18 -04:00
// Init
void _init_normals() {
2024-10-19 05:19:08 -04:00
// PolygonQuad::render
2024-10-18 15:14:18 -04:00
overwrite_calls(PolygonQuad_render, PolygonQuad_render_injection);
2024-10-19 05:19:08 -04:00
// ItemInHandRenderer::renderItem
2024-10-20 18:10:17 -04:00
add_normal_before_vertexUV<0, 0, 1>(0x4bb4c);
add_normal_before_vertexUV<0, 0, -1>(0x4bbbc);
add_normal_before_vertexUV<-1, 0, 0>(0x4bc50);
add_normal_before_vertexUV<1, 0, 0>(0x4bcf0);
add_normal_before_vertexUV<0, 1, 0>(0x4bd90);
add_normal_before_vertexUV<0, -1, 0>(0x4be28);
2024-10-19 05:19:08 -04:00
// TileRenderer::renderTile
2024-10-20 18:10:17 -04:00
add_normal_before_getTexture2<0, -1, 0>(0x5dd2c);
add_normal_before_getTexture2<0, 1, 0>(0x5dd60);
add_normal_before_getTexture2<0, 0, -1>(0x5dd94);
add_normal_before_getTexture2<0, 0, 1>(0x5ddc8);
add_normal_before_getTexture2<-1, 0, 0>(0x5ddfc);
add_normal_before_getTexture2<1, 0, 0>(0x5de30);
add_normal_before_tesselateCrossTexture<0, -1, 0>(0x5de7c);
add_normal_before_updateDefaultShape<0, -1, 0>(0x5dea0);
add_normal_before_getTexture2<0, -1, 0>(0x5df38);
add_normal_before_getTexture2<0, 1, 0>(0x5df68);
add_normal_before_getTexture2<0, 0, -1>(0x5dfac);
add_normal_before_getTexture2<0, 0, 1>(0x5e004);
add_normal_before_getTexture2<-1, 0, 0>(0x5e05c);
add_normal_before_getTexture2<1, 0, 0>(0x5e0b4);
add_normal_before_getTexture2<0, -1, 0>(0x5e1e4);
add_normal_before_getTexture2<0, 1, 0>(0x5e218);
add_normal_before_getTexture2<0, 0, -1>(0x5e248);
add_normal_before_getTexture2<0, 0, 1>(0x5e278);
add_normal_before_getTexture2<-1, 0, 0>(0x5e2a8);
add_normal_before_getTexture2<1, 0, 0>(0x5e2d8);
add_normal_before_getTexture2<0, -1, 0>(0x5e408);
add_normal_before_getTexture2<0, 1, 0>(0x5e43c);
add_normal_before_getTexture2<0, 0, -1>(0x5e46c);
add_normal_before_getTexture2<0, 0, 1>(0x5e49c);
add_normal_before_getTexture2<-1, 0, 0>(0x5e4cc);
add_normal_before_getTexture2<1, 0, 0>(0x5e4fc);
add_normal_before_getTexture2<0, -1, 0>(0x5e60c);
add_normal_before_getTexture2<0, 1, 0>(0x5e640);
add_normal_before_getTexture2<0, 0, -1>(0x5e670);
add_normal_before_getTexture2<0, 0, 1>(0x5e6a0);
add_normal_before_getTexture2<-1, 0, 0>(0x5e6d0);
add_normal_before_getTexture2<1, 0, 0>(0x5e700);
2024-10-19 05:19:08 -04:00
// ArrowRenderer::render
2024-10-20 18:10:17 -04:00
add_normal_before_vertexUV<1, 0, 0>(0x60184);
add_normal_before_vertexUV<-1, 0, 0>(0x601f4);
add_normal_before_vertexUV<0, 0, 1>(0x60288);
2024-10-19 05:19:08 -04:00
// ItemRenderer::render
2024-10-20 18:10:17 -04:00
add_normal_before_vertexUV<0, 1, 0>(0x63394);
2024-10-19 05:19:08 -04:00
// ItemSpriteRenderer::render
2024-10-20 18:10:17 -04:00
add_normal_before_vertexUV<0, 1, 0>(0x63fd0);
2024-10-19 05:19:08 -04:00
// MobRenderer::renderNameTag
2024-10-20 18:10:17 -04:00
add_normal_before_vertex<0, 1, 0>(0x64918);
2024-10-19 05:19:08 -04:00
// PaintingRenderer::renderPainting
2024-10-20 18:10:17 -04:00
add_normal_before_vertexUV<0, 0, -1>(0x64c94);
add_normal_before_vertexUV<0, 0, 1>(0x64d04);
add_normal_before_vertexUV<0, 1, 0>(0x64d74);
add_normal_before_vertexUV<0, -1, 0>(0x64de4);
add_normal_before_vertexUV<-1, 0, 0>(0x64e54);
add_normal_before_vertexUV<1, 0, 0>(0x64ec4);
2024-10-18 15:14:18 -04:00
}