add ModelBatch pseudo-lights
This commit is contained in:
parent
6d6313cd10
commit
3d2deaf369
@ -4,6 +4,7 @@
|
||||
#include "../core/Texture.hpp"
|
||||
#include "../../window/Window.hpp"
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
@ -15,7 +16,6 @@ static const vattr attrs[] = {
|
||||
{3}, {2}, {1}, {0}
|
||||
};
|
||||
|
||||
static glm::vec3 SUN_VECTOR (0.411934f, 0.863868f, -0.279161f);
|
||||
inline constexpr glm::vec3 X(1, 0, 0);
|
||||
inline constexpr glm::vec3 Y(0, 1, 0);
|
||||
inline constexpr glm::vec3 Z(0, 0, 1);
|
||||
@ -39,12 +39,16 @@ ModelBatch::~ModelBatch() {
|
||||
void ModelBatch::test(glm::vec3 pos, glm::vec3 size) {
|
||||
float time = static_cast<float>(Window::time());
|
||||
pushMatrix(glm::translate(glm::mat4(1.0f), pos));
|
||||
pushMatrix(glm::rotate(glm::mat4(1.0f), time, glm::vec3(0,1,0)));
|
||||
pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*7*0.1f), glm::vec3(0,1,0)));
|
||||
pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*11*0.1f), glm::vec3(1,0,0)));
|
||||
pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*17*0.1f), glm::vec3(0,0,1)));
|
||||
pushMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, glm::sin(time*2), 0)));
|
||||
box({}, size);
|
||||
popMatrix();
|
||||
popMatrix();
|
||||
popMatrix();
|
||||
popMatrix();
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void ModelBatch::box(glm::vec3 pos, glm::vec3 size) {
|
||||
@ -62,7 +66,7 @@ void ModelBatch::flush() {
|
||||
if (index == 0) {
|
||||
return;
|
||||
}
|
||||
blank->bind();
|
||||
// blank->bind();
|
||||
mesh->reload(buffer.get(), index / VERTEX_SIZE);
|
||||
mesh->draw();
|
||||
index = 0;
|
||||
@ -70,7 +74,7 @@ void ModelBatch::flush() {
|
||||
|
||||
void ModelBatch::pushMatrix(glm::mat4 matrix) {
|
||||
matrices.push_back(combined);
|
||||
combined = matrix * combined;
|
||||
combined = combined * matrix;
|
||||
|
||||
decomposed = {};
|
||||
glm::quat rotation;
|
||||
|
||||
@ -15,7 +15,7 @@ struct DecomposedMat4 {
|
||||
glm::vec3 skew;
|
||||
glm::vec4 perspective;
|
||||
};
|
||||
#include <iostream>
|
||||
|
||||
class ModelBatch {
|
||||
std::unique_ptr<float[]> buffer;
|
||||
size_t capacity;
|
||||
@ -29,6 +29,8 @@ class ModelBatch {
|
||||
|
||||
DecomposedMat4 decomposed {};
|
||||
|
||||
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
|
||||
|
||||
inline void vertex(
|
||||
glm::vec3 pos, glm::vec2 uv, glm::vec4 color
|
||||
) {
|
||||
@ -55,7 +57,10 @@ class ModelBatch {
|
||||
|
||||
inline void plane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
|
||||
norm = decomposed.rotation * norm;
|
||||
glm::vec4 color {norm.x, norm.y, norm.z, 0.0f};
|
||||
float d = glm::dot(norm, SUN_VECTOR);
|
||||
d = 0.8f + d * 0.2f;
|
||||
|
||||
glm::vec4 color {d, d, d, 0.0f};
|
||||
color.r = glm::max(0.0f, color.r);
|
||||
color.g = glm::max(0.0f, color.g);
|
||||
color.b = glm::max(0.0f, color.b);
|
||||
|
||||
@ -193,6 +193,7 @@ void WorldRenderer::renderLevel(
|
||||
|
||||
drawChunks(level->chunks.get(), camera, shader);
|
||||
|
||||
assets->getTexture("gui/menubg")->bind();
|
||||
shader->uniformMatrix("u_model", glm::mat4(1.0f));
|
||||
modelBatch->test(glm::vec3(0, 68, 0), glm::vec3(1.0f));
|
||||
modelBatch->flush();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user