mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
feat: allow passing rgba color to entity skeletons and block wraps
This commit is contained in:
parent
85cc55c63b
commit
ae082abaa2
12 changed files with 55 additions and 40 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
layout (location = 0) in vec3 v_position;
|
layout (location = 0) in vec3 v_position;
|
||||||
layout (location = 1) in vec2 v_texCoord;
|
layout (location = 1) in vec2 v_texCoord;
|
||||||
layout (location = 2) in vec3 v_color;
|
layout (location = 2) in vec4 v_color;
|
||||||
layout (location = 3) in vec4 v_light;
|
layout (location = 3) in vec4 v_light;
|
||||||
layout (location = 4) in vec4 v_normal;
|
layout (location = 4) in vec4 v_normal;
|
||||||
|
|
||||||
|
|
@ -29,8 +29,8 @@ void main() {
|
||||||
|
|
||||||
a_dir = a_modelpos.xyz - u_cameraPos;
|
a_dir = a_modelpos.xyz - u_cameraPos;
|
||||||
vec3 skyLightColor = pick_sky_color(u_skybox, u_dayTime, u_minSkyLight);
|
vec3 skyLightColor = pick_sky_color(u_skybox, u_dayTime, u_minSkyLight);
|
||||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb * v_light.a) * v_color;
|
a_color.rgb = max(a_color.rgb, skyLightColor.rgb * v_light.a) * v_color.rgb;
|
||||||
a_color.a = u_opacity;
|
a_color.a = u_opacity * v_color.a;
|
||||||
|
|
||||||
mat4 viewmodel = u_view * u_model;
|
mat4 viewmodel = u_view * u_model;
|
||||||
a_distance = length(viewmodel * vec4(pos3d, 0.0));
|
a_distance = length(viewmodel * vec4(pos3d, 0.0));
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace rigging {
|
||||||
std::unordered_map<std::string, std::string> textures;
|
std::unordered_map<std::string, std::string> textures;
|
||||||
std::vector<ModelReference> modelOverrides;
|
std::vector<ModelReference> modelOverrides;
|
||||||
bool visible;
|
bool visible;
|
||||||
glm::vec3 tint {1.0f, 1.0f, 1.0f};
|
glm::vec4 tint {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
|
||||||
util::VecInterpolation<3, float> interpolation {false};
|
util::VecInterpolation<3, float> interpolation {false};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ void BlockWrapsRenderer::draw(const DrawContext& pctx) {
|
||||||
u64id_t BlockWrapsRenderer::add(
|
u64id_t BlockWrapsRenderer::add(
|
||||||
const glm::ivec3& position,
|
const glm::ivec3& position,
|
||||||
const std::string& texture,
|
const std::string& texture,
|
||||||
const glm::vec3& tint,
|
const glm::vec4& tint,
|
||||||
float emission
|
float emission
|
||||||
) {
|
) {
|
||||||
u64id_t id = nextWrapper++;
|
u64id_t id = nextWrapper++;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class DrawContext;
|
||||||
struct BlockWrapper {
|
struct BlockWrapper {
|
||||||
glm::ivec3 position;
|
glm::ivec3 position;
|
||||||
std::array<std::string, 6> textureFaces {};
|
std::array<std::string, 6> textureFaces {};
|
||||||
std::array<glm::vec3, 6> tints {};
|
std::array<glm::vec4, 6> tints {};
|
||||||
float emission = 0.0f;
|
float emission = 0.0f;
|
||||||
|
|
||||||
// --- render cache ---
|
// --- render cache ---
|
||||||
|
|
@ -56,7 +56,7 @@ public:
|
||||||
u64id_t add(
|
u64id_t add(
|
||||||
const glm::ivec3& position,
|
const glm::ivec3& position,
|
||||||
const std::string& texture,
|
const std::string& texture,
|
||||||
const glm::vec3& tint,
|
const glm::vec4& tint,
|
||||||
float emission
|
float emission
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ void MainBatch::cube(
|
||||||
const glm::vec3& size,
|
const glm::vec3& size,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const glm::vec4& lights,
|
const glm::vec4& lights,
|
||||||
const glm::vec3 tints[],
|
const glm::vec4 tints[],
|
||||||
float emission,
|
float emission,
|
||||||
uint8_t cullingBits
|
uint8_t cullingBits
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@ class Chunks;
|
||||||
struct MainBatchVertex {
|
struct MainBatchVertex {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec2 uv;
|
glm::vec2 uv;
|
||||||
glm::vec3 tint;
|
glm::vec4 tint;
|
||||||
std::array<uint8_t, 4> color;
|
std::array<uint8_t, 4> color;
|
||||||
std::array<uint8_t, 4> normal;
|
std::array<uint8_t, 4> normal;
|
||||||
|
|
||||||
static constexpr VertexAttribute ATTRIBUTES[] = {
|
static constexpr VertexAttribute ATTRIBUTES[] = {
|
||||||
{VertexAttribute::Type::FLOAT, false, 3},
|
{VertexAttribute::Type::FLOAT, false, 3},
|
||||||
{VertexAttribute::Type::FLOAT, false, 2},
|
{VertexAttribute::Type::FLOAT, false, 2},
|
||||||
{VertexAttribute::Type::FLOAT, false, 3},
|
{VertexAttribute::Type::FLOAT, false, 4},
|
||||||
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
|
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
|
||||||
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
|
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
|
||||||
{{}, 0}};
|
{{}, 0}};
|
||||||
|
|
@ -63,7 +63,7 @@ public:
|
||||||
const glm::vec3& pos,
|
const glm::vec3& pos,
|
||||||
const glm::vec2& uv,
|
const glm::vec2& uv,
|
||||||
const glm::vec4& light,
|
const glm::vec4& light,
|
||||||
const glm::vec3& tint,
|
const glm::vec4& tint,
|
||||||
const glm::vec3& normal,
|
const glm::vec3& normal,
|
||||||
float emission
|
float emission
|
||||||
) {
|
) {
|
||||||
|
|
@ -91,7 +91,7 @@ public:
|
||||||
const glm::vec3& normal,
|
const glm::vec3& normal,
|
||||||
const glm::vec2& size,
|
const glm::vec2& size,
|
||||||
const glm::vec4& light,
|
const glm::vec4& light,
|
||||||
const glm::vec3& tint,
|
const glm::vec4& tint,
|
||||||
const UVRegion& subregion,
|
const UVRegion& subregion,
|
||||||
float emission = 0.0f
|
float emission = 0.0f
|
||||||
) {
|
) {
|
||||||
|
|
@ -152,7 +152,7 @@ public:
|
||||||
const glm::vec3& size,
|
const glm::vec3& size,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const glm::vec4& lights,
|
const glm::vec4& lights,
|
||||||
const glm::vec3 tints[],
|
const glm::vec4 tints[],
|
||||||
float emission,
|
float emission,
|
||||||
uint8_t cullingBits = 0xFF
|
uint8_t cullingBits = 0xFF
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ void ModelBatch::draw(
|
||||||
const model::Mesh& mesh,
|
const model::Mesh& mesh,
|
||||||
const glm::mat4& matrix,
|
const glm::mat4& matrix,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
glm::vec3 tint,
|
const glm::vec4& tint,
|
||||||
const texture_names_map* varTextures,
|
const TextureNamesMap* varTextures,
|
||||||
bool backlight
|
bool backlight
|
||||||
) {
|
) {
|
||||||
setTexture(mesh.texture, varTextures);
|
setTexture(mesh.texture, varTextures);
|
||||||
|
|
@ -97,10 +97,12 @@ void ModelBatch::draw(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelBatch::draw(glm::mat4 matrix,
|
void ModelBatch::draw(
|
||||||
glm::vec3 tint,
|
const glm::mat4& matrix,
|
||||||
const model::Model* model,
|
const glm::vec4& tint,
|
||||||
const texture_names_map* varTextures) {
|
const model::Model* model,
|
||||||
|
const TextureNamesMap* varTextures
|
||||||
|
) {
|
||||||
for (const auto& mesh : model->meshes) {
|
for (const auto& mesh : model->meshes) {
|
||||||
entries.push_back({
|
entries.push_back({
|
||||||
matrix, extract_rotation(matrix), tint, &mesh, varTextures
|
matrix, extract_rotation(matrix), tint, &mesh, varTextures
|
||||||
|
|
@ -134,7 +136,7 @@ void ModelBatch::setLightsOffset(const glm::vec3& offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelBatch::setTexture(const std::string& name,
|
void ModelBatch::setTexture(const std::string& name,
|
||||||
const texture_names_map* varTextures) {
|
const TextureNamesMap* varTextures) {
|
||||||
if (varTextures && !name.empty() && name.at(0) == '$') {
|
if (varTextures && !name.empty() && name.at(0) == '$') {
|
||||||
const auto& found = varTextures->find(name);
|
const auto& found = varTextures->find(name);
|
||||||
if (found == varTextures->end()) {
|
if (found == varTextures->end()) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace model {
|
||||||
struct Model;
|
struct Model;
|
||||||
}
|
}
|
||||||
|
|
||||||
using texture_names_map = std::unordered_map<std::string, std::string>;
|
using TextureNamesMap = std::unordered_map<std::string, std::string>;
|
||||||
|
|
||||||
class ModelBatch {
|
class ModelBatch {
|
||||||
const Assets& assets;
|
const Assets& assets;
|
||||||
|
|
@ -31,22 +31,24 @@ class ModelBatch {
|
||||||
|
|
||||||
std::unique_ptr<MainBatch> batch;
|
std::unique_ptr<MainBatch> batch;
|
||||||
|
|
||||||
void draw(const model::Mesh& mesh,
|
void draw(
|
||||||
const glm::mat4& matrix,
|
const model::Mesh& mesh,
|
||||||
const glm::mat3& rotation,
|
const glm::mat4& matrix,
|
||||||
glm::vec3 tint,
|
const glm::mat3& rotation,
|
||||||
const texture_names_map* varTextures,
|
const glm::vec4& tint,
|
||||||
bool backlight);
|
const TextureNamesMap* varTextures,
|
||||||
|
bool backlight
|
||||||
|
);
|
||||||
|
|
||||||
void setTexture(const std::string& name,
|
void setTexture(const std::string& name,
|
||||||
const texture_names_map* varTextures);
|
const TextureNamesMap* varTextures);
|
||||||
|
|
||||||
struct DrawEntry {
|
struct DrawEntry {
|
||||||
glm::mat4 matrix;
|
glm::mat4 matrix;
|
||||||
glm::mat3 rotation;
|
glm::mat3 rotation;
|
||||||
glm::vec3 tint;
|
glm::vec4 tint;
|
||||||
const model::Mesh* mesh;
|
const model::Mesh* mesh;
|
||||||
const texture_names_map* varTextures;
|
const TextureNamesMap* varTextures;
|
||||||
};
|
};
|
||||||
std::vector<DrawEntry> entries;
|
std::vector<DrawEntry> entries;
|
||||||
public:
|
public:
|
||||||
|
|
@ -58,10 +60,12 @@ public:
|
||||||
);
|
);
|
||||||
~ModelBatch();
|
~ModelBatch();
|
||||||
|
|
||||||
void draw(glm::mat4 matrix,
|
void draw(
|
||||||
glm::vec3 tint,
|
const glm::mat4& matrix,
|
||||||
const model::Model* model,
|
const glm::vec4& tint,
|
||||||
const texture_names_map* varTextures);
|
const model::Model* model,
|
||||||
|
const TextureNamesMap* varTextures
|
||||||
|
);
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void setLightsOffset(const glm::vec3& offset);
|
void setLightsOffset(const glm::vec3& offset);
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ void ParticlesRenderer::renderParticle(
|
||||||
-camera.front,
|
-camera.front,
|
||||||
preset.size * scale,
|
preset.size * scale,
|
||||||
light,
|
light,
|
||||||
glm::vec3(1.0f),
|
glm::vec4(1.0f),
|
||||||
particle.region,
|
particle.region,
|
||||||
preset.lighting ? 0.0f : 1.0f
|
preset.lighting ? 0.0f : 1.0f
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ void PrecipitationRenderer::render(
|
||||||
glm::cross(glm::vec3(0, 1, 0), face.right),
|
glm::cross(glm::vec3(0, 1, 0), face.right),
|
||||||
FACE_SIZE,
|
FACE_SIZE,
|
||||||
light_at(chunks, pos.x, y, pos.z),
|
light_at(chunks, pos.x, y, pos.z),
|
||||||
glm::vec3(1.0f),
|
glm::vec4(1.0f),
|
||||||
calc_uv(pos, face.right, timer, weather)
|
calc_uv(pos, face.right, timer, weather)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,9 @@ static int l_get_color(lua::State* L) {
|
||||||
|
|
||||||
static int l_set_color(lua::State* L) {
|
static int l_set_color(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
skeleton->tint = lua::tovec3(L, 2);
|
skeleton->tint = lua::objlen(L, 2) > 3
|
||||||
|
? lua::tovec4(L, 2)
|
||||||
|
: glm::vec4(lua::tovec3(L, 2), 1.0f);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@ static int l_wrap(lua::State* L) {
|
||||||
auto position = lua::tovec3(L, 1);
|
auto position = lua::tovec3(L, 1);
|
||||||
std::string texture = lua::require_string(L, 2);
|
std::string texture = lua::require_string(L, 2);
|
||||||
float emission = lua::isnumber(L, 3) ? lua::tonumber(L, 3) : 1.0f;
|
float emission = lua::isnumber(L, 3) ? lua::tonumber(L, 3) : 1.0f;
|
||||||
glm::vec3 tint = lua::istable(L, 4) ? lua::tovec3(L, 4) : glm::vec3(1.0f);
|
glm::vec4 tint =
|
||||||
|
lua::istable(L, 4)
|
||||||
|
? (lua::objlen(L, 4) > 3 ? lua::tovec4(L, 4)
|
||||||
|
: glm::vec4(lua::tovec3(L, 4), 1.0f))
|
||||||
|
: glm::vec4(1.0f);
|
||||||
|
|
||||||
return lua::pushinteger(
|
return lua::pushinteger(
|
||||||
L,
|
L,
|
||||||
|
|
@ -72,9 +76,12 @@ static int l_set_tints(lua::State* L) {
|
||||||
if (auto wrapper = renderer->blockWraps->get(lua::tointeger(L, 1))) {
|
if (auto wrapper = renderer->blockWraps->get(lua::tointeger(L, 1))) {
|
||||||
for (int i = 0; i < wrapper->textureFaces.size(); i++) {
|
for (int i = 0; i < wrapper->textureFaces.size(); i++) {
|
||||||
if (lua::isnil(L, 2 + i)) {
|
if (lua::isnil(L, 2 + i)) {
|
||||||
wrapper->tints[i] = glm::vec3(1.0f);
|
wrapper->tints[i] = glm::vec4(1.0f);
|
||||||
} else {
|
} else {
|
||||||
wrapper->tints[i] = lua::tovec3(L, 2 + i);
|
wrapper->tints[i] =
|
||||||
|
lua::objlen(L, 2 + i) > 3
|
||||||
|
? lua::tovec4(L, 2 + i)
|
||||||
|
: glm::vec4(lua::tovec3(L, 2 + i), 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue