-Subproject commit b3f731d5e1152dd81b3b19366c2b81481e25dd7e
+Subproject commit 0a3fe3553f0e6fe9a9cd8d8994c15c873d247e34
} else if (name == "texture") {
in.ReadString(tex_name);
type.texture = tex_index.GetID(tex_name);
- } else if (name == "color") {
- in.ReadVec(type.color);
+ } else if (name == "rgb_mod") {
+ in.ReadVec(type.rgb_mod);
+ } else if (name == "hsl_mod") {
+ in.ReadVec(type.hsl_mod);
} else if (name == "outline") {
in.ReadVec(type.outline_color);
} else if (name == "label") {
"#version 330 core\n"
"layout(location = 0) in vec3 vtx_position;\n"
"layout(location = 1) in vec3 vtx_tex_uv;\n"
- "layout(location = 2) in vec3 vtx_color;\n"
- "layout(location = 3) in float vtx_light;\n"
+ "layout(location = 2) in vec3 vtx_hsl_mod;\n"
+ "layout(location = 3) in vec3 vtx_rgb_mod;\n"
+ "layout(location = 4) in float vtx_light;\n"
"uniform mat4 MV;\n"
"uniform mat4 MVP;\n"
"out vec3 frag_tex_uv;\n"
- "out vec3 frag_color;\n"
+ "out vec3 frag_hsl_mod;\n"
+ "out vec3 frag_rgb_mod;\n"
"out vec3 vtx_viewspace;\n"
"out float frag_light;\n"
"void main() {\n"
"gl_Position = MVP * vec4(vtx_position, 1);\n"
"frag_tex_uv = vtx_tex_uv;\n"
- "frag_color = vtx_color;\n"
+ "frag_hsl_mod = vtx_hsl_mod;\n"
+ "frag_rgb_mod = vtx_rgb_mod;\n"
"vtx_viewspace = (MV * vec4(vtx_position, 1)).xyz;\n"
"frag_light = vtx_light;\n"
"}\n"
GL_FRAGMENT_SHADER,
"#version 330 core\n"
"in vec3 frag_tex_uv;\n"
- "in vec3 frag_color;\n"
+ "in vec3 frag_hsl_mod;\n"
+ "in vec3 frag_rgb_mod;\n"
"in vec3 vtx_viewspace;\n"
"in float frag_light;\n"
"uniform sampler2DArray tex_sampler;\n"
"uniform float fog_density;\n"
"out vec3 color;\n"
+ "vec3 rgb2hsl(vec3 c) {\n"
+ "vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0);\n"
+ "vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n"
+ "vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n"
+ "float d = q.x - min(q.w, q.y);\n"
+ "float e = 1.0e-10;\n"
+ "return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"
+ "}\n"
+ "vec3 hsl2rgb(vec3 c) {\n"
+ "vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);\n"
+ "vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n"
+ "return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n"
+ "}\n"
"void main() {\n"
"vec3 tex_color = texture(tex_sampler, frag_tex_uv).rgb;\n"
- "vec3 base_color = tex_color * frag_color;\n"
+ "vec3 hsl_color = rgb2hsl(tex_color);\n"
+ "hsl_color.x += frag_hsl_mod.x;\n"
+ "hsl_color.y *= frag_hsl_mod.y;\n"
+ "hsl_color.z *= frag_hsl_mod.z;\n"
+ "vec3 base_color = hsl2rgb(hsl_color) * frag_rgb_mod;\n"
"float light_power = clamp(pow(0.8, 15 - frag_light), 0, 1);\n"
"vec3 fog_color = vec3(0, 0, 0);\n"
"float e = 2.718281828;\n"
public:
using Position = glm::vec3;
using TexCoord = glm::vec3;
- using Color = glm::vec3;
+ using ColorMod = glm::vec3;
using Light = float;
using Index = unsigned int;
using Positions = std::vector<Position>;
using TexCoords = std::vector<TexCoord>;
- using Colors = std::vector<Color>;
+ using ColorMods = std::vector<ColorMod>;
using Lights = std::vector<Light>;
using Indices = std::vector<Index>;
enum Attribute {
ATTRIB_VERTEX,
ATTRIB_TEXCOORD,
- ATTRIB_COLOR,
+ ATTRIB_HSL,
+ ATTRIB_RGB,
ATTRIB_LIGHT,
ATTRIB_INDEX,
ATTRIB_COUNT,
Positions vertices;
TexCoords tex_coords;
- Colors colors;
+ ColorMods hsl_mods;
+ ColorMods rgb_mods;
Lights lights;
Indices indices;
void Clear() noexcept {
vertices.clear();
tex_coords.clear();
- colors.clear();
+ hsl_mods.clear();
+ rgb_mods.clear();
lights.clear();
indices.clear();
}
void Reserve(size_t p, size_t i) {
vertices.reserve(p);
tex_coords.reserve(p);
- colors.reserve(p);
+ hsl_mods.reserve(p);
+ rgb_mods.reserve(p);
lights.reserve(p);
indices.reserve(i);
}
public:
using Position = glm::vec3;
using TexCoord = glm::vec3;
- using Color = glm::vec3;
+ using ColorMod = glm::vec3;
using Normal = glm::vec3;
using Index = unsigned int;
using Positions = std::vector<Position>;
using TexCoords = std::vector<TexCoord>;
- using Colors = std::vector<Color>;
+ using ColorMods = std::vector<ColorMod>;
using Normals = std::vector<Normal>;
using Indices = std::vector<Index>;
enum Attribute {
ATTRIB_VERTEX,
ATTRIB_TEXCOORD,
- ATTRIB_COLOR,
+ ATTRIB_HSL,
+ ATTRIB_RGB,
ATTRIB_NORMAL,
ATTRIB_INDEX,
ATTRIB_COUNT,
Positions vertices;
TexCoords tex_coords;
- Colors colors;
+ ColorMods hsl_mods;
+ ColorMods rgb_mods;
Normals normals;
Indices indices;
void Clear() noexcept {
vertices.clear();
tex_coords.clear();
- colors.clear();
+ hsl_mods.clear();
+ rgb_mods.clear();
normals.clear();
indices.clear();
}
void Reserve(size_t p, size_t i) {
vertices.reserve(p);
tex_coords.reserve(p);
- colors.reserve(p);
+ hsl_mods.reserve(p);
+ rgb_mods.reserve(p);
normals.reserve(p);
indices.reserve(i);
}
{
CuboidShape shape(skeletons[0]->Bounds());
shape.Vertices(buf, 3.0f);
- buf.colors.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f });
+ buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
+ buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f });
models[0].Update(buf);
skeletons[0]->SetNodeModel(&models[0]);
}
CuboidShape shape(skeletons[1]->Bounds());
buf.Clear();
shape.Vertices(buf, 0.0f);
- buf.colors.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
+ buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
+ buf.rgb_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
models[1].Update(buf);
skeletons[1]->SetNodeModel(&models[1]);
}
StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f });
buf.Clear();
shape.Vertices(buf, 1.0f);
- buf.colors.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f });
+ buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
+ buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f });
models[2].Update(buf);
skeletons[2]->SetNodeModel(&models[2]);
}
CuboidShape shape(skeletons[3]->Bounds());
buf.Clear();
shape.Vertices(buf, 2.0f);
- buf.colors.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f });
+ buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
+ buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f });
models[3].Update(buf);
skeletons[3]->SetNodeModel(&models[3]);
}
if (buf.tex_coords.size() < buf.vertices.size()) {
std::cerr << "EntityModel: not enough tex coords!" << std::endl;
}
- if (buf.colors.size() < buf.vertices.size()) {
- std::cerr << "EntityModel: not enough colors!" << std::endl;
+ if (buf.hsl_mods.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
+ }
+ if (buf.rgb_mods.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
}
if (buf.normals.size() < buf.vertices.size()) {
std::cerr << "EntityModel: not enough normals!" << std::endl;
vao.Bind();
vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
- vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+ vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
+ vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
if (buf.tex_coords.size() < buf.vertices.size()) {
std::cerr << "BlockModel: not enough tex coords!" << std::endl;
}
- if (buf.colors.size() < buf.vertices.size()) {
- std::cerr << "BlockModel: not enough colors!" << std::endl;
+ if (buf.hsl_mods.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
+ }
+ if (buf.rgb_mods.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
}
if (buf.lights.size() < buf.vertices.size()) {
std::cerr << "BlockModel: not enough lights!" << std::endl;
vao.Bind();
vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
- vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+ vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
+ vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
const Shape *shape;
float texture;
- glm::vec3 color;
+ glm::vec3 hsl_mod;
+ glm::vec3 rgb_mod;
glm::vec3 outline_color;
/// a string to display to the user
}
} fill;
- explicit BlockType(
- bool v = false,
- const glm::vec3 &color = { 1, 1, 1 },
- const Shape *shape = &DEFAULT_SHAPE
- ) noexcept;
+ BlockType() noexcept;
static const NullShape DEFAULT_SHAPE;
}
-BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s) noexcept
-: shape(s)
+BlockType::BlockType() noexcept
+: shape(&DEFAULT_SHAPE)
, texture(0)
-, color(col)
+, hsl_mod(0.0f, 1.0f, 1.0f)
+, rgb_mod(1.0f, 1.0f, 1.0f)
, outline_color(-1, -1, -1)
, label("some block")
, id(0)
, luminosity(0)
-, visible(v)
-, block_light(false)
-, collision(false)
-, collide_block(false)
+, visible(true)
+, block_light(true)
+, collision(true)
+, collide_block(true)
, generate(false)
, min_solidity(0.5f)
, mid_solidity(0.75f)
EntityModel::Index idx_offset
) const noexcept {
shape->Vertices(buf, transform, texture, idx_offset);
- buf.colors.insert(buf.colors.end(), shape->VertexCount(), color);
+ buf.hsl_mods.insert(buf.hsl_mods.end(), shape->VertexCount(), hsl_mod);
+ buf.rgb_mods.insert(buf.rgb_mods.end(), shape->VertexCount(), rgb_mod);
}
void BlockType::FillBlockModel(
BlockModel::Index idx_offset
) const noexcept {
shape->Vertices(buf, transform, texture, idx_offset);
- buf.colors.insert(buf.colors.end(), shape->VertexCount(), color);
+ buf.hsl_mods.insert(buf.hsl_mods.end(), shape->VertexCount(), hsl_mod);
+ buf.rgb_mods.insert(buf.rgb_mods.end(), shape->VertexCount(), rgb_mod);
}
void BlockType::FillOutlineModel(OutlineModel::Buffer &buf) const noexcept {
BlockTypeRegistry::BlockTypeRegistry() {
- Add(BlockType());
+ BlockType air;
+ air.visible = false;
+ air.block_light = false;
+ air.collision = false;
+ air.collide_block = false;
+ Add(air);
}
Block::Type BlockTypeRegistry::Add(const BlockType &t) {