world-wide commit to ruin everything

This commit is contained in:
MihailRis
2022-10-28 22:44:32 +03:00
parent fbce36a05c
commit 8a073e4e8a
57 changed files with 1433 additions and 958 deletions
+122 -8
View File
@@ -1,6 +1,7 @@
#include "Batch2D.h"
#include "Mesh.h"
#include "Texture.h"
#include "Sprite.h"
#include <GL/glew.h>
@@ -86,6 +87,116 @@ void Batch2D::rect(float x, float y, float w, float h){
vertex(x+w, y+h, 1, 1, r,g,b,a);
}
void Batch2D::rect(
float x, float y,
float w, float h,
float ox, float oy,
float angle,
UVRegion region,
bool flippedX,
bool flippedY,
vec4 tint) {
if (index + 6*VERTEX_SIZE >= capacity)
render();
float centerX = w*ox;
float centerY = h*oy;
float acenterX = w-centerX;
float acenterY = h-centerY;
float _x1 = -centerX;
float _y1 = -centerY;
float _x2 = -centerX;
float _y2 = +acenterY;
float _x3 = +acenterX;
float _y3 = +acenterY;
float _x4 = +acenterX;
float _y4 = -centerY;
float x1,y1,x2,y2,x3,y3,x4,y4;
if (angle != 0) {
float s = sin(angle);
float c = cos(angle);
x1 = c * _x1 - s * _y1;
y1 = s * _x1 + c * _y1;
x2 = c * _x2 - s * _y2;
y2 = s * _x2 + c * _y2;
x3 = c * _x3 - s * _y3;
y3 = s * _x3 + c * _y3;
x4 = x1 + (x3 - x2);
y4 = y3 - (y2 - y1);
} else {
x1 = _x1;
y1 = _y1;
x2 = _x2;
y2 = _y2;
x3 = _x3;
y3 = _y3;
x4 = _x4;
y4 = _y4;
}
x1 += x; x2 += x; x3 += x; x4 += x;
y1 += y; y2 += y; y3 += y; y4 += y;
float u1 = region.u1;
float v1 = region.v1;
float u2 = region.u1;
float v2 = region.v2;
float u3 = region.u2;
float v3 = region.v2;
float u4 = region.u2;
float v4 = region.v1;
if (flippedX) {
float temp = u1;
u1 = u3;
u4 = temp;
u2 = u3;
u3 = temp;
}
if (flippedY) {
float temp = v1;
v1 = v2;
v4 = v2;
v2 = temp;
v3 = temp;
}
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
vertex(x2, y2, u2, v2, tint.r, tint.g, tint.b, tint.a);
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
/* Right down triangle */
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
vertex(x4, y4, u4, v4, tint.r, tint.g, tint.b, tint.a);
}
void Batch2D::sprite(Sprite* sprite) {
vec2 position = sprite->position;
vec2 size = sprite->size;
vec2 origin = sprite->origin;
texture(sprite->texture);
rect(
position.x, position.y,
size.x, size.y,
origin.x, origin.y,
sprite->angle,
sprite->region,
sprite->flippedX,
sprite->flippedY,
sprite->color);
}
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint){
float scale = 1.0f / (float)atlasRes;
float u = (index % atlasRes) * scale;
@@ -99,16 +210,19 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
float uf = (index[0] % atlasRes) * scale;
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
if (index[0] + 6*VERTEX_SIZE >= capacity)
if (this->index + 18*VERTEX_SIZE >= capacity)
render();
vec2 points[7] = {vec2(x+(w*0.5f), y+(h*0.5f)),
vec2(x, y+(h*0.25f)),
vec2(x+(w*0.5f), y),
vec2(x+w, y+(h*0.25f)),
vec2(x+w, y+(h*0.75f)),
vec2(x+(w*0.5f), y+h),
vec2(x, y+(h*0.75f))};
float ar = 0.88f;
float ox = x + (w * 0.5f);
float sx = w * 0.5f * ar;
vec2 points[7] = {vec2(ox, y+(h*0.5f)),
vec2(ox-sx, y+(h*0.25f)),
vec2(ox, y),
vec2(ox+sx, y+(h*0.25f)),
vec2(ox+sx, y+(h*0.75f)),
vec2(ox, y+h),
vec2(ox-sx, y+(h*0.75f))};
vec2 uvpoints[8] = {vec2(uu, vu),
vec2(uu+scale, vu),
+13 -1
View File
@@ -4,16 +4,18 @@
#include <stdlib.h>
#include <glm/glm.hpp>
#include "UVRegion.h"
using namespace glm;
class Mesh;
class Texture;
class Sprite;
class Batch2D {
float* buffer;
size_t capacity;
size_t offset;
glm::vec4 color;
Mesh* mesh;
size_t index;
@@ -28,13 +30,23 @@ class Batch2D {
float r, float g, float b, float a);
public:
glm::vec4 color;
Batch2D(size_t capacity);
~Batch2D();
void begin();
void texture(Texture* texture);
void sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint);
void sprite(Sprite* sprite);
void blockSprite(float x, float y, float w, float h, int atlasRes, int index[6], vec4 tint);
void rect(float x, float y,
float w, float h,
float ox, float oy,
float angle, UVRegion region,
bool flippedX, bool flippedY,
vec4 tint);
void rect(float x, float y, float w, float h);
void rect(float x, float y, float w, float h,
float u, float v, float tx, float ty,
+1 -1
View File
@@ -7,7 +7,7 @@
#define VERTEX_SIZE 9
Batch3D::Batch3D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1.0f, 1.0f, 1.0f){
Batch3D::Batch3D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1.0f, 1.0f, 0.0f){
const int attrs[] = {
3, 2, 4, 0 //null terminator
};
+4 -4
View File
@@ -19,9 +19,9 @@ int Font::getGlyphWidth(char c) {
case '.':
case ',':
case ':':
case ';': return 3;
case 't': return 5;
case ' ': return 3;
case ';': return 7;
case 't': return 8;
case ' ': return 7;
}
return 7;
}
@@ -75,7 +75,7 @@ void Font::draw(Batch2D* batch, std::wstring text, int x, int y, int style) {
break;
}
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
batch->sprite(x, y, RES, RES, 16, c, batch->color);
}
else if (charpage > page && charpage < next){
next = charpage;
+37
View File
@@ -0,0 +1,37 @@
#include "Framebuffer.h"
#include <GL/glew.h>
#include "Texture.h"
Framebuffer::Framebuffer(int width, int height) : width(width), height(height) {
glGenFramebuffers(1, &fbo);
bind();
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
texture = new Texture(tex, width, height);
glGenRenderbuffers(1, &depth);
glBindRenderbuffer(GL_RENDERBUFFER, depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
unbind();
}
Framebuffer::~Framebuffer() {
delete texture;
glDeleteFramebuffers(1, &fbo);
}
void Framebuffer::bind() {
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
}
void Framebuffer::unbind() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef SRC_GRAPHICS_FRAMEBUFFER_H_
#define SRC_GRAPHICS_FRAMEBUFFER_H_
class Texture;
class Framebuffer {
unsigned int fbo;
unsigned int depth;
public:
int width;
int height;
Texture* texture;
Framebuffer(int width, int height);
~Framebuffer();
void bind();
void unbind();
};
#endif /* SRC_GRAPHICS_FRAMEBUFFER_H_ */
+17
View File
@@ -0,0 +1,17 @@
#include "Sprite.h"
#include "Texture.h"
Sprite::Sprite(glm::vec2 position, glm::vec2 size, Texture* texture)
: position(position),
size(size),
origin(0.5f, 0.5f),
color(1.0f, 1.0f, 1.0f, 1.0f),
angle(0.0f),
texture(texture),
region() {
}
Sprite::~Sprite() {
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef SRC_GRAPHICS_SPRITE_H_
#define SRC_GRAPHICS_SPRITE_H_
#include <glm/glm.hpp>
#include "UVRegion.h"
class Texture;
class Sprite {
public:
glm::vec2 position;
glm::vec2 size;
glm::vec2 origin;
glm::vec4 color;
float angle;
bool flippedX = false;
bool flippedY = false;
Texture* texture;
UVRegion region;
Sprite(glm::vec2 position, glm::vec2 size, Texture* texture);
virtual ~Sprite();
void setTexture(Texture* texture) {
this->texture = texture;
}
};
#endif /* SRC_GRAPHICS_SPRITE_H_ */
+1
View File
@@ -0,0 +1 @@
#include "UVRegion.h"
+17
View File
@@ -0,0 +1,17 @@
#ifndef SRC_GRAPHICS_UVREGION_H_
#define SRC_GRAPHICS_UVREGION_H_
class UVRegion {
public:
float u1;
float v1;
float u2;
float v2;
UVRegion(float u1, float v1, float u2, float v2)
: u1(u1), v1(v1), u2(u2), v2(v2){}
UVRegion() : u1(0.0f), v1(0.0f), u2(1.0f), v2(1.0f){}
};
#endif /* SRC_GRAPHICS_UVREGION_H_ */
+194 -113
View File
@@ -12,7 +12,7 @@
#define LOCAL_NEG(X, SIZE) (((X) < 0) ? ((SIZE)+(X)) : (X))
#define LOCAL(X, SIZE) ((X) >= (SIZE) ? ((X) - (SIZE)) : LOCAL_NEG(X, SIZE))
#define IS_CHUNK(X,Y,Z) (GET_CHUNK(X,Y,Z) != nullptr)
#define GET_CHUNK(X,Y,Z) (chunks[((CDIV(Y, CHUNK_H)+1) * 3 + CDIV(Z, CHUNK_D) + 1) * 3 + CDIV(X, CHUNK_W) + 1])
#define GET_CHUNK(X,Y,Z) (chunks[(CDIV(Z, CHUNK_D) + 1) * 3 + CDIV(X, CHUNK_W) + 1])
#define LIGHT(X,Y,Z, CHANNEL) (IS_CHUNK(X,Y,Z) ? GET_CHUNK(X,Y,Z)->lightmap->get(LOCAL(X, CHUNK_W), LOCAL(Y, CHUNK_H), LOCAL(Z, CHUNK_D), (CHANNEL)) : 0)
#define VOXEL(X,Y,Z) (GET_CHUNK(X,Y,Z)->voxels[(LOCAL(Y, CHUNK_H) * CHUNK_D + LOCAL(Z, CHUNK_D)) * CHUNK_W + LOCAL(X, CHUNK_W)])
@@ -43,13 +43,7 @@ VoxelRenderer::VoxelRenderer() {
VoxelRenderer::~VoxelRenderer(){
}
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
unsigned int id = vox.id;
if (!id){
return;
}
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
float l;
float uvsize = 1.0f/16.0f;
@@ -61,10 +55,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[3]);
float lr = LIGHT(x,y+1,z, 0) / 15.0f;
float lg = LIGHT(x,y+1,z, 1) / 15.0f;
float lb = LIGHT(x,y+1,z, 2) / 15.0f;
float ls = LIGHT(x,y+1,z, 3) / 15.0f;
const float lr = LIGHT(x,y+1,z, 0) / 15.0f;
const float lg = LIGHT(x,y+1,z, 1) / 15.0f;
const float lb = LIGHT(x,y+1,z, 2) / 15.0f;
const float ls = LIGHT(x,y+1,z, 3) / 15.0f;
float lr0 = (LIGHT(x-1,y+1,z,0) + lr*30 + LIGHT(x-1,y+1,z-1,0) + LIGHT(x,y+1,z-1,0)) / 75.0f;
float lr1 = (LIGHT(x-1,y+1,z,0) + lr*30 + LIGHT(x-1,y+1,z+1,0) + LIGHT(x,y+1,z+1,0)) / 75.0f;
@@ -99,10 +93,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[2]);
float lr = LIGHT(x,y-1,z, 0) / 15.0f;
float lg = LIGHT(x,y-1,z, 1) / 15.0f;
float lb = LIGHT(x,y-1,z, 2) / 15.0f;
float ls = LIGHT(x,y-1,z, 3) / 15.0f;
const float lr = LIGHT(x,y-1,z, 0) / 15.0f;
const float lg = LIGHT(x,y-1,z, 1) / 15.0f;
const float lb = LIGHT(x,y-1,z, 2) / 15.0f;
const float ls = LIGHT(x,y-1,z, 3) / 15.0f;
float lr0 = (LIGHT(x-1,y-1,z-1,0) + lr*30 + LIGHT(x-1,y-1,z,0) + LIGHT(x,y-1,z-1,0)) / 75.0f;
float lr1 = (LIGHT(x+1,y-1,z+1,0) + lr*30 + LIGHT(x+1,y-1,z,0) + LIGHT(x,y-1,z+1,0)) / 75.0f;
@@ -138,10 +132,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[1]);
float lr = LIGHT(x+1,y,z, 0) / 15.0f;
float lg = LIGHT(x+1,y,z, 1) / 15.0f;
float lb = LIGHT(x+1,y,z, 2) / 15.0f;
float ls = LIGHT(x+1,y,z, 3) / 15.0f;
const float lr = LIGHT(x+1,y,z, 0) / 15.0f;
const float lg = LIGHT(x+1,y,z, 1) / 15.0f;
const float lb = LIGHT(x+1,y,z, 2) / 15.0f;
const float ls = LIGHT(x+1,y,z, 3) / 15.0f;
float lr0 = (LIGHT(x+1,y-1,z-1,0) + lr*30 + LIGHT(x+1,y,z-1,0) + LIGHT(x+1,y-1,z,0)) / 75.0f;
float lr1 = (LIGHT(x+1,y+1,z-1,0) + lr*30 + LIGHT(x+1,y,z-1,0) + LIGHT(x+1,y+1,z,0)) / 75.0f;
@@ -176,10 +170,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[0]);
float lr = LIGHT(x-1,y,z, 0) / 15.0f;
float lg = LIGHT(x-1,y,z, 1) / 15.0f;
float lb = LIGHT(x-1,y,z, 2) / 15.0f;
float ls = LIGHT(x-1,y,z, 3) / 15.0f;
const float lr = LIGHT(x-1,y,z, 0) / 15.0f;
const float lg = LIGHT(x-1,y,z, 1) / 15.0f;
const float lb = LIGHT(x-1,y,z, 2) / 15.0f;
const float ls = LIGHT(x-1,y,z, 3) / 15.0f;
float lr0 = (LIGHT(x-1,y-1,z-1,0) + lr*30 + LIGHT(x-1,y,z-1,0) + LIGHT(x-1,y-1,z,0)) / 75.0f;
float lr1 = (LIGHT(x-1,y+1,z+1,0) + lr*30 + LIGHT(x-1,y,z+1,0) + LIGHT(x-1,y+1,z,0)) / 75.0f;
@@ -215,10 +209,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[5]);
float lr = LIGHT(x,y,z+1, 0) / 15.0f;
float lg = LIGHT(x,y,z+1, 1) / 15.0f;
float lb = LIGHT(x,y,z+1, 2) / 15.0f;
float ls = LIGHT(x,y,z+1, 3) / 15.0f;
const float lr = LIGHT(x,y,z+1, 0) / 15.0f;
const float lg = LIGHT(x,y,z+1, 1) / 15.0f;
const float lb = LIGHT(x,y,z+1, 2) / 15.0f;
const float ls = LIGHT(x,y,z+1, 3) / 15.0f;
float lr0 = l*(LIGHT(x-1,y-1,z+1,0) + lr*30 + LIGHT(x,y-1,z+1,0) + LIGHT(x-1,y,z+1,0)) / 75.0f;
float lr1 = l*(LIGHT(x+1,y+1,z+1,0) + lr*30 + LIGHT(x,y+1,z+1,0) + LIGHT(x+1,y,z+1,0)) / 75.0f;
@@ -253,10 +247,10 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
SETUP_UV(block->textureFaces[4]);
float lr = LIGHT(x,y,z-1, 0) / 15.0f;
float lg = LIGHT(x,y,z-1, 1) / 15.0f;
float lb = LIGHT(x,y,z-1, 2) / 15.0f;
float ls = LIGHT(x,y,z-1, 3) / 15.0f;
const float lr = LIGHT(x,y,z-1, 0) / 15.0f;
const float lg = LIGHT(x,y,z-1, 1) / 15.0f;
const float lb = LIGHT(x,y,z-1, 2) / 15.0f;
const float ls = LIGHT(x,y,z-1, 3) / 15.0f;
float lr0 = l*(LIGHT(x-1,y-1,z-1,0) + lr*30 + LIGHT(x,y-1,z-1,0) + LIGHT(x-1,y,z-1,0)) / 75.0f;
float lr1 = l*(LIGHT(x-1,y+1,z-1,0) + lr*30 + LIGHT(x,y+1,z-1,0) + LIGHT(x-1,y,z-1,0)) / 75.0f;
@@ -288,8 +282,82 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
}
}
inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
float l;
float uvsize = 1.0f/16.0f;
Block* block = Block::blocks[id];
unsigned char group = block->drawGroup;
if (!IS_BLOCKED(x,y+1,z,group)){
SETUP_UV(block->textureFaces[3]);
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, 1,1,1,0);
}
if (!IS_BLOCKED(x,y-1,z,group)){
SETUP_UV(block->textureFaces[2]);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, 1,1,1,0);
}
if (!IS_BLOCKED(x+1,y,z,group)){
SETUP_UV(block->textureFaces[1]);
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, 1,1,1,0);
}
if (!IS_BLOCKED(x-1,y,z,group)){
SETUP_UV(block->textureFaces[0]);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, 1,1,1,0);
}
if (!IS_BLOCKED(x,y,z+1,group)){
SETUP_UV(block->textureFaces[5]);
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, 1,1,1,0);
}
if (!IS_BLOCKED(x,y,z-1,group)){
SETUP_UV(block->textureFaces[4]);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, 1,1,1,0);
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, 1,1,1,0);
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, 1,1,1,0);
}
}
inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
@@ -304,101 +372,88 @@ inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const
return;
}
float l;
float uvsize = 1.0f/16.0f;
float lr = LIGHT(x,y,z, 0) / 15.0f;
float lg = LIGHT(x,y,z, 1) / 15.0f;
float lb = LIGHT(x,y,z, 2) / 15.0f;
float ls = LIGHT(x,y,z, 3) / 15.0f;
float lr = LIGHT(x,y,z, 0) / 15.0f;
float lg = LIGHT(x,y,z, 1) / 15.0f;
float lb = LIGHT(x,y,z, 2) / 15.0f;
float ls = LIGHT(x,y,z, 3) / 15.0f;
float lr0 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr1 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr2 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr3 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr4 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr5 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr6 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr7 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr0 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr1 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr2 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr3 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr4 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lr5 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr6 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
float lr7 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
float lg0 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg1 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg2 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg3 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg4 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg5 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg6 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg7 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg0 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg1 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg2 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg3 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg4 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lg5 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg6 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
float lg7 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
float lb0 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb1 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb2 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb3 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb4 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb5 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb6 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb7 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb0 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb1 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb2 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb3 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb4 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float lb5 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb6 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
float lb7 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
float ls0 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls1 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls2 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls3 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls4 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls5 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls6 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls7 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls0 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls1 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls2 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls3 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls4 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
float ls5 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls6 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
float ls7 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
{SETUP_UV(block->textureFaces[1]);
l = 0.95f;
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
{SETUP_UV(block->textureFaces[1]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr3,lg3,lb3,ls3);}
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
{SETUP_UV(block->textureFaces[0]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr3,lg3,lb3,ls3);}
l = 0.85f;
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
{SETUP_UV(block->textureFaces[0]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr3,lg3,lb3,ls3);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);}
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
{SETUP_UV(block->textureFaces[5]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr3,lg3,lb3,ls3);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);}
l = 0.9f;
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
{SETUP_UV(block->textureFaces[5]);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr7,lg7,lb7,ls7);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);}
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
{SETUP_UV(block->textureFaces[4]);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr7,lg7,lb7,ls7);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);}
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
l = 0.8f;
{SETUP_UV(block->textureFaces[4]);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr7,lg7,lb7,ls7);}
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr7,lg7,lb7,ls7);}
}
const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){
@@ -408,9 +463,15 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id == 0)
continue;
if (vox.id == 9 || vox.id == 4 || vox.id == 12 || vox.id == 13)
continue;
_renderBlock(buffer, x, y, z, chunks, vox, index);
Block* block = Block::blocks[vox.id];
if (block->emission[0] || block->emission[1] || block->emission[2]){
continue;
}
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
}
}
}
@@ -419,9 +480,25 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id == 0)
continue;
Block* block = Block::blocks[vox.id];
if (block->emission[0] || block->emission[1] || block->emission[2]){
_renderBlockShadeless(buffer, x, y, z, chunks, vox.id, index);
}
}
}
}
for (int y = 0; y < CHUNK_H; y++){
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id == 0)
continue;
if (vox.id != 9)
continue;
_renderBlock(buffer, x, y, z, chunks, vox, index);
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
}
}
}
@@ -430,7 +507,9 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id != 12 && vox.id != 13)
if (vox.id == 0)
continue;
if (Block::blocks[vox.id]->model != BLOCK_MODEL_GRASS)
continue;
_renderXBlock(buffer, x, y, z, chunks, vox, index);
}
@@ -441,9 +520,11 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id == 0)
continue;
if (vox.id != 4)
continue;
_renderBlock(buffer, x, y, z, chunks, vox, index);
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
}
}
}
+1
View File
@@ -12,6 +12,7 @@ class Chunk;
class VoxelRenderer {
public:
std::vector<float> buffer;
unsigned char lights[27 * 4];
VoxelRenderer();
~VoxelRenderer();