Add clamping support to the ortho shader
* Biome tint leaves, tweak fluff texture to be less densemaster
parent
96e03db1d6
commit
cc7163d61b
|
@ -7,8 +7,13 @@ in float useTex;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
uniform vec4 uClipBounds;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
if (uClipBounds.z != 0 && uClipBounds.w != 0
|
||||||
|
&&(gl_FragCoord.x < uClipBounds.x || gl_FragCoord.y < uClipBounds.y
|
||||||
|
|| gl_FragCoord.x > uClipBounds.z || gl_FragCoord.y > uClipBounds.w)) discard;
|
||||||
|
|
||||||
if (useTex > 0.5) {
|
if (useTex > 0.5) {
|
||||||
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
|
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
|
||||||
if (spec.a <= 0) discard;
|
if (spec.a <= 0) discard;
|
||||||
|
|
|
@ -31,10 +31,10 @@ ParticleEntity::ParticleEntity(glm::vec3 pos, BlockDef &block) {
|
||||||
uv += glm::vec4(offX, offY, offX, offY);
|
uv += glm::vec4(offX, offY, offX, offY);
|
||||||
|
|
||||||
std::vector<EntityVertex> vertices {
|
std::vector<EntityVertex> vertices {
|
||||||
{{-0.05, -0.05, 0}, {uv.x, uv.w, 0, 0}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
{{-0.05, -0.05, 0}, {uv.x, uv.w, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
||||||
{{-0.05, 0.05, 0}, {uv.x, uv.y, 0, 0}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
{{-0.05, 0.05, 0}, {uv.x, uv.y, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
||||||
{{ 0.05, 0.05, 0}, {uv.z, uv.y, 0, 0}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
{{ 0.05, 0.05, 0}, {uv.z, uv.y, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
||||||
{{ 0.05, -0.05, 0}, {uv.z, uv.w, 0, 0}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
{{ 0.05, -0.05, 0}, {uv.z, uv.w, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
||||||
};
|
};
|
||||||
std::vector<unsigned int> indices {
|
std::vector<unsigned int> indices {
|
||||||
0, 1, 2, 2, 3, 0,
|
0, 1, 2, 2, 3, 0,
|
||||||
|
|
|
@ -30,10 +30,11 @@ Renderer::Renderer(glm::ivec2 win) :
|
||||||
guiShader = Shader();
|
guiShader = Shader();
|
||||||
guiShader.createFromFile("./assets/shader/ortho/hud.vs", "./assets/shader/ortho/hud.fs");
|
guiShader.createFromFile("./assets/shader/ortho/hud.vs", "./assets/shader/ortho/hud.fs");
|
||||||
|
|
||||||
gu.matrix = camera.getOrthographicMatrix();
|
gu.matrix = camera.getOrthographicMatrix();
|
||||||
gu.ortho = guiShader.get("ortho");
|
gu.ortho = guiShader.get("ortho");
|
||||||
gu.model = guiShader.get("model");
|
gu.model = guiShader.get("model");
|
||||||
gu.bones = guiShader.get("uBones");
|
gu.bones = guiShader.get("uBones");
|
||||||
|
gu.clipBounds = guiShader.get("uClipBounds");
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
@ -169,6 +170,43 @@ void Renderer::swapBuffers() {
|
||||||
window.swapBuffers();
|
window.swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::setShader(Shader& s) {
|
||||||
|
s.use();
|
||||||
|
this->currentShader = &s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::setClearColor(unsigned char r, unsigned char g, unsigned char b) {
|
||||||
|
clearColor = {static_cast<float>(r)/255.f, static_cast<float>(g)/255.f, static_cast<float>(b)/255.f, 1};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::toggleDepthTest(bool enable) {
|
||||||
|
enable ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::clearDepthBuffer() {
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::setModelMatrix(const glm::mat4& modelMatrix) {
|
||||||
|
glUniformMatrix4fv(currentModelUniform, 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::setBones(std::vector<glm::mat4> &transforms) {
|
||||||
|
if (transforms.empty()) return;
|
||||||
|
currentShader->setArr((currentShader == &entity ? entity.uniforms.bones : gu.bones), static_cast<GLsizei>(transforms.size()), transforms.at(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::setClipBounds(glm::vec4 bounds) {
|
||||||
|
guiShader.set(gu.clipBounds, {bounds.x, window.getSize().y - bounds.w, bounds.z, window.getSize().y - bounds.y});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::enableTexture(Texture *texture) {
|
||||||
|
if (texture != activeTexture) {
|
||||||
|
activeTexture = texture;
|
||||||
|
texture->use(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::renderQuad() {
|
void Renderer::renderQuad() {
|
||||||
if (quadVAO == 0) {
|
if (quadVAO == 0) {
|
||||||
float quadVertices[] = {
|
float quadVertices[] = {
|
||||||
|
@ -193,35 +231,3 @@ void Renderer::renderQuad() {
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::setModelMatrix(const glm::mat4& modelMatrix) {
|
|
||||||
glUniformMatrix4fv(currentModelUniform, 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::enableTexture(Texture *texture) {
|
|
||||||
if (texture != activeTexture) {
|
|
||||||
activeTexture = texture;
|
|
||||||
texture->use(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::setShader(Shader& s) {
|
|
||||||
s.use();
|
|
||||||
this->currentShader = &s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::setClearColor(unsigned char r, unsigned char g, unsigned char b) {
|
|
||||||
clearColor = {static_cast<float>(r)/255.f, static_cast<float>(g)/255.f, static_cast<float>(b)/255.f, 1};
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::setBones(std::vector<glm::mat4> &transforms) {
|
|
||||||
if (transforms.empty()) return;
|
|
||||||
currentShader->setArr((currentShader == &entity ? entity.uniforms.bones : gu.bones), static_cast<GLsizei>(transforms.size()), transforms.at(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::toggleDepthTest(bool enable) {
|
|
||||||
enable ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::clearDepthBuffer() {
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
|
||||||
}
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
|
|
||||||
void setModelMatrix(const glm::mat4& modelMatrix);
|
void setModelMatrix(const glm::mat4& modelMatrix);
|
||||||
void setBones(std::vector<glm::mat4>& transforms);
|
void setBones(std::vector<glm::mat4>& transforms);
|
||||||
|
void setClipBounds(glm::vec4 bounds);
|
||||||
void enableTexture(Texture* texture);
|
void enableTexture(Texture* texture);
|
||||||
|
|
||||||
Window window;
|
Window window;
|
||||||
|
|
|
@ -15,4 +15,5 @@ struct GuiUniforms {
|
||||||
GLint model;
|
GLint model;
|
||||||
|
|
||||||
GLint bones;
|
GLint bones;
|
||||||
|
GLint clipBounds;
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,6 +77,11 @@ void Shader::set(int loc, glm::vec3 val) {
|
||||||
glUniform3f(loc, val.x, val.y, val.z);
|
glUniform3f(loc, val.x, val.y, val.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shader::set(int loc, glm::vec4 val) {
|
||||||
|
crashIfInactive();
|
||||||
|
glUniform4f(loc, val.x, val.y, val.z, val.w);
|
||||||
|
}
|
||||||
|
|
||||||
void Shader::set(int loc, glm::mat4 val) {
|
void Shader::set(int loc, glm::mat4 val) {
|
||||||
crashIfInactive();
|
crashIfInactive();
|
||||||
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(val));
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(val));
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
void set(int loc, int val);
|
void set(int loc, int val);
|
||||||
void set(int loc, float val);
|
void set(int loc, float val);
|
||||||
void set(int loc, glm::vec3 val);
|
void set(int loc, glm::vec3 val);
|
||||||
|
void set(int loc, glm::vec4 val);
|
||||||
void set(int loc, glm::mat4 val);
|
void set(int loc, glm::mat4 val);
|
||||||
|
|
||||||
void setArr(int loc, unsigned int count, glm::mat4 &start);
|
void setArr(int loc, unsigned int count, glm::mat4 &start);
|
||||||
|
|
|
@ -42,6 +42,10 @@ glm::ivec2 GuiComponent::getPos() {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiComponent::setHideOverflow(bool hideOverflow) {
|
||||||
|
this->hideOverflow = hideOverflow;
|
||||||
|
}
|
||||||
|
|
||||||
void GuiComponent::add(std::shared_ptr<GuiComponent> component) {
|
void GuiComponent::add(std::shared_ptr<GuiComponent> component) {
|
||||||
component->parent = this;
|
component->parent = this;
|
||||||
component->updatePos();
|
component->updatePos();
|
||||||
|
@ -72,6 +76,8 @@ void GuiComponent::empty() {
|
||||||
void GuiComponent::draw(Renderer& renderer) {
|
void GuiComponent::draw(Renderer& renderer) {
|
||||||
entity.draw(renderer);
|
entity.draw(renderer);
|
||||||
for (const auto& child : children) {
|
for (const auto& child : children) {
|
||||||
|
renderer.setClipBounds(hideOverflow ? glm::vec4 {entity.getPos().x, entity.getPos().y,
|
||||||
|
entity.getPos().x + scale.x, entity.getPos().y + scale.y} : glm::vec4 {});
|
||||||
child->draw(renderer);
|
child->draw(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,4 +171,4 @@ bool GuiComponent::clickEvent(bool left, bool state, glm::ivec2 pos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "../../entity/Entity.h"
|
#include "../../entity/Entity.h"
|
||||||
|
|
||||||
class GuiComponent : public Drawable {
|
class GuiComponent : public Drawable {
|
||||||
|
@ -25,7 +26,9 @@ public:
|
||||||
virtual void setPos(glm::ivec2 pos);
|
virtual void setPos(glm::ivec2 pos);
|
||||||
virtual glm::ivec2 getPos();
|
virtual glm::ivec2 getPos();
|
||||||
|
|
||||||
virtual void update(double delta);
|
void setHideOverflow(bool hideOverflow);
|
||||||
|
|
||||||
|
virtual void update(double delta) override;
|
||||||
|
|
||||||
bool mouseActivity(glm::ivec2 pos);
|
bool mouseActivity(glm::ivec2 pos);
|
||||||
bool leftClickEvent(bool state, glm::ivec2 pos);
|
bool leftClickEvent(bool state, glm::ivec2 pos);
|
||||||
|
@ -68,6 +71,8 @@ protected:
|
||||||
glm::vec4 padding {};
|
glm::vec4 padding {};
|
||||||
glm::ivec2 hitbox {};
|
glm::ivec2 hitbox {};
|
||||||
|
|
||||||
|
bool hideOverflow = false;
|
||||||
|
|
||||||
callback cbLeftClick = nullptr;
|
callback cbLeftClick = nullptr;
|
||||||
callback cbRightClick = nullptr;
|
callback cbRightClick = nullptr;
|
||||||
callback cbHover = nullptr;
|
callback cbHover = nullptr;
|
||||||
|
|
|
@ -21,10 +21,13 @@ std::shared_ptr<GuiRect> GuiRect::fromSerialized(SerialGui::Elem s, ClientGame&
|
||||||
|
|
||||||
std::string background = s.tokens["background"];
|
std::string background = s.tokens["background"];
|
||||||
|
|
||||||
|
bool hideOverflow = s.tokens["overflow"] == "hidden";
|
||||||
|
|
||||||
auto rect = std::make_shared<GuiRect>(s.key);
|
auto rect = std::make_shared<GuiRect>(s.key);
|
||||||
if (background[0] == '#') rect->create(size, padding, Util::hexToColorVec(background));
|
if (background[0] == '#') rect->create(size, padding, Util::hexToColorVec(background));
|
||||||
else if (background.size() > 0) rect->create(size, padding, game.textures[background]);
|
else if (background.size() > 0) rect->create(size, padding, game.textures[background]);
|
||||||
else rect->create(size, padding, glm::vec4 {});
|
else rect->create(size, padding, glm::vec4 {});
|
||||||
|
rect->setHideOverflow(hideOverflow);
|
||||||
rect->setPos(pos);
|
rect->setPos(pos);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ std::shared_ptr<GuiImageButton> GuiImageButton::fromSerialized(SerialGui::Elem s
|
||||||
std::string background_hover = s.tokens["background_hover"];
|
std::string background_hover = s.tokens["background_hover"];
|
||||||
if (background_hover.length() == 0) background_hover = background;
|
if (background_hover.length() == 0) background_hover = background;
|
||||||
|
|
||||||
|
bool hideOverflow = s.tokens["overflow"] == "hidden";
|
||||||
|
|
||||||
std::string content = "";
|
std::string content = "";
|
||||||
if (s.tokens.count("content") && s.tokens["content"].length() >= 2) content = s.tokens["content"].substr(1, s.tokens["content"].size() - 2);
|
if (s.tokens.count("content") && s.tokens["content"].length() >= 2) content = s.tokens["content"].substr(1, s.tokens["content"].size() - 2);
|
||||||
std::string::size_type off = 0;
|
std::string::size_type off = 0;
|
||||||
|
@ -32,6 +34,7 @@ std::shared_ptr<GuiImageButton> GuiImageButton::fromSerialized(SerialGui::Elem s
|
||||||
|
|
||||||
auto button = std::make_shared<GuiImageButton>(s.key);
|
auto button = std::make_shared<GuiImageButton>(s.key);
|
||||||
button->create(size, padding, game.textures[background], game.textures[background_hover]);
|
button->create(size, padding, game.textures[background], game.textures[background_hover]);
|
||||||
|
button->setHideOverflow(hideOverflow);
|
||||||
button->setPos(pos);
|
button->setPos(pos);
|
||||||
|
|
||||||
if (content != "") {
|
if (content != "") {
|
||||||
|
|
|
@ -75,12 +75,11 @@ void Server::update() {
|
||||||
enet_packet_destroy(event.packet);
|
enet_packet_destroy(event.packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& pair : playersUpdated) {
|
for (auto& cid : playersUpdated) {
|
||||||
unsigned int cid = pair.first;
|
|
||||||
auto client = clientList.getClient(cid);
|
auto client = clientList.getClient(cid);
|
||||||
if (client == nullptr) continue;
|
if (client == nullptr) continue;
|
||||||
|
|
||||||
Packet r(PacketType::PLAYER_INFO);
|
Packet r(PacketType::PLAYER_INFO, false);
|
||||||
r.data = Serializer()
|
r.data = Serializer()
|
||||||
.append(client->cid)
|
.append(client->cid)
|
||||||
.append(client->getPos())
|
.append(client->getPos())
|
||||||
|
@ -113,7 +112,7 @@ void Server::handlePlayerPacket(ServerClient &client, Packet& p) {
|
||||||
client.setPitch(d.read<float>());
|
client.setPitch(d.read<float>());
|
||||||
client.setYaw(d.read<float>());
|
client.setYaw(d.read<float>());
|
||||||
|
|
||||||
playersUpdated.emplace(client.cid, true);
|
playersUpdated.emplace(client.cid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PacketType::BLOCK_SET: {
|
case PacketType::BLOCK_SET: {
|
||||||
|
|
|
@ -32,7 +32,7 @@ private:
|
||||||
ClientList clientList;
|
ClientList clientList;
|
||||||
ServerConfig config;
|
ServerConfig config;
|
||||||
|
|
||||||
std::unordered_map<unsigned int, bool> playersUpdated {};
|
std::unordered_set<unsigned int> playersUpdated {};
|
||||||
|
|
||||||
double elapsedSeconds = 0;
|
double elapsedSeconds = 0;
|
||||||
double deltaTime = 0;
|
double deltaTime = 0;
|
||||||
|
|
|
@ -4,11 +4,11 @@ zepha.register_block("zeus:default:leaves", {
|
||||||
name = "Leaves",
|
name = "Leaves",
|
||||||
model = "base:leaf_like",
|
model = "base:leaf_like",
|
||||||
textures = {
|
textures = {
|
||||||
"zeus:default:leaves",
|
"tint(0, zeus:default:leaves)",
|
||||||
"zeus:default:leaves_puff"
|
"tint(0, zeus:default:leaves_puff)"
|
||||||
},
|
},
|
||||||
lowdef_textures = {
|
lowdef_textures = {
|
||||||
"zeus:default:leaves_opaque",
|
"tint(0, zeus:default:leaves_opaque)",
|
||||||
},
|
},
|
||||||
toughness = {
|
toughness = {
|
||||||
hand = 1,
|
hand = 1,
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 762 B |
Binary file not shown.
Before Width: | Height: | Size: 431 B After Width: | Height: | Size: 704 B |
Binary file not shown.
Before Width: | Height: | Size: 893 B After Width: | Height: | Size: 1.2 KiB |
|
@ -46,6 +46,21 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
||||||
position: 163px 10px
|
position: 163px 10px
|
||||||
slot_spacing: 2px 2px
|
slot_spacing: 2px 2px
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rect[player_clamp]
|
||||||
|
position: 41px -8px
|
||||||
|
size: 34px 52px
|
||||||
|
overflow: hidden
|
||||||
|
|
||||||
|
model
|
||||||
|
scale: 86 86
|
||||||
|
position: 15px 52px
|
||||||
|
type: model
|
||||||
|
source: zeus:default:player
|
||||||
|
texture: zeus:default:player
|
||||||
|
anim_range: 0 300
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rect[hot_wheel]
|
rect[hot_wheel]
|
||||||
|
@ -90,15 +105,6 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
||||||
slot_spacing: 2px 2px
|
slot_spacing: 2px 2px
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
model
|
|
||||||
scale: 96 96
|
|
||||||
position: 195 145
|
|
||||||
type: model
|
|
||||||
source: zeus:default:player
|
|
||||||
texture: zeus:default:player
|
|
||||||
anim_range: 0 300
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]], {
|
]], {
|
||||||
|
|
Loading…
Reference in New Issue