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;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform vec4 uClipBounds;
|
||||
|
||||
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) {
|
||||
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
|
||||
if (spec.a <= 0) discard;
|
||||
|
|
|
@ -31,10 +31,10 @@ ParticleEntity::ParticleEntity(glm::vec3 pos, BlockDef &block) {
|
|||
uv += glm::vec4(offX, offY, offX, offY);
|
||||
|
||||
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.y, 0, 0}, {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.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, 1}, {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, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
|
||||
};
|
||||
std::vector<unsigned int> indices {
|
||||
0, 1, 2, 2, 3, 0,
|
||||
|
|
|
@ -30,10 +30,11 @@ Renderer::Renderer(glm::ivec2 win) :
|
|||
guiShader = Shader();
|
||||
guiShader.createFromFile("./assets/shader/ortho/hud.vs", "./assets/shader/ortho/hud.fs");
|
||||
|
||||
gu.matrix = camera.getOrthographicMatrix();
|
||||
gu.ortho = guiShader.get("ortho");
|
||||
gu.model = guiShader.get("model");
|
||||
gu.bones = guiShader.get("uBones");
|
||||
gu.matrix = camera.getOrthographicMatrix();
|
||||
gu.ortho = guiShader.get("ortho");
|
||||
gu.model = guiShader.get("model");
|
||||
gu.bones = guiShader.get("uBones");
|
||||
gu.clipBounds = guiShader.get("uClipBounds");
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
@ -169,6 +170,43 @@ void Renderer::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() {
|
||||
if (quadVAO == 0) {
|
||||
float quadVertices[] = {
|
||||
|
@ -193,35 +231,3 @@ void Renderer::renderQuad() {
|
|||
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 setBones(std::vector<glm::mat4>& transforms);
|
||||
void setClipBounds(glm::vec4 bounds);
|
||||
void enableTexture(Texture* texture);
|
||||
|
||||
Window window;
|
||||
|
|
|
@ -15,4 +15,5 @@ struct GuiUniforms {
|
|||
GLint model;
|
||||
|
||||
GLint bones;
|
||||
GLint clipBounds;
|
||||
};
|
||||
|
|
|
@ -77,6 +77,11 @@ void Shader::set(int loc, glm::vec3 val) {
|
|||
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) {
|
||||
crashIfInactive();
|
||||
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(val));
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
void set(int loc, int val);
|
||||
void set(int loc, float val);
|
||||
void set(int loc, glm::vec3 val);
|
||||
void set(int loc, glm::vec4 val);
|
||||
void set(int loc, glm::mat4 val);
|
||||
|
||||
void setArr(int loc, unsigned int count, glm::mat4 &start);
|
||||
|
|
|
@ -42,6 +42,10 @@ glm::ivec2 GuiComponent::getPos() {
|
|||
return pos;
|
||||
}
|
||||
|
||||
void GuiComponent::setHideOverflow(bool hideOverflow) {
|
||||
this->hideOverflow = hideOverflow;
|
||||
}
|
||||
|
||||
void GuiComponent::add(std::shared_ptr<GuiComponent> component) {
|
||||
component->parent = this;
|
||||
component->updatePos();
|
||||
|
@ -72,6 +76,8 @@ void GuiComponent::empty() {
|
|||
void GuiComponent::draw(Renderer& renderer) {
|
||||
entity.draw(renderer);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -165,4 +171,4 @@ bool GuiComponent::clickEvent(bool left, bool state, glm::ivec2 pos) {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "../../entity/Entity.h"
|
||||
|
||||
class GuiComponent : public Drawable {
|
||||
|
@ -25,7 +26,9 @@ public:
|
|||
virtual void setPos(glm::ivec2 pos);
|
||||
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 leftClickEvent(bool state, glm::ivec2 pos);
|
||||
|
@ -68,6 +71,8 @@ protected:
|
|||
glm::vec4 padding {};
|
||||
glm::ivec2 hitbox {};
|
||||
|
||||
bool hideOverflow = false;
|
||||
|
||||
callback cbLeftClick = nullptr;
|
||||
callback cbRightClick = nullptr;
|
||||
callback cbHover = nullptr;
|
||||
|
|
|
@ -21,10 +21,13 @@ std::shared_ptr<GuiRect> GuiRect::fromSerialized(SerialGui::Elem s, ClientGame&
|
|||
|
||||
std::string background = s.tokens["background"];
|
||||
|
||||
bool hideOverflow = s.tokens["overflow"] == "hidden";
|
||||
|
||||
auto rect = std::make_shared<GuiRect>(s.key);
|
||||
if (background[0] == '#') rect->create(size, padding, Util::hexToColorVec(background));
|
||||
else if (background.size() > 0) rect->create(size, padding, game.textures[background]);
|
||||
else rect->create(size, padding, glm::vec4 {});
|
||||
rect->setHideOverflow(hideOverflow);
|
||||
rect->setPos(pos);
|
||||
return rect;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ std::shared_ptr<GuiImageButton> GuiImageButton::fromSerialized(SerialGui::Elem s
|
|||
std::string background_hover = s.tokens["background_hover"];
|
||||
if (background_hover.length() == 0) background_hover = background;
|
||||
|
||||
bool hideOverflow = s.tokens["overflow"] == "hidden";
|
||||
|
||||
std::string content = "";
|
||||
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;
|
||||
|
@ -32,6 +34,7 @@ std::shared_ptr<GuiImageButton> GuiImageButton::fromSerialized(SerialGui::Elem s
|
|||
|
||||
auto button = std::make_shared<GuiImageButton>(s.key);
|
||||
button->create(size, padding, game.textures[background], game.textures[background_hover]);
|
||||
button->setHideOverflow(hideOverflow);
|
||||
button->setPos(pos);
|
||||
|
||||
if (content != "") {
|
||||
|
|
|
@ -75,12 +75,11 @@ void Server::update() {
|
|||
enet_packet_destroy(event.packet);
|
||||
}
|
||||
|
||||
for (auto& pair : playersUpdated) {
|
||||
unsigned int cid = pair.first;
|
||||
for (auto& cid : playersUpdated) {
|
||||
auto client = clientList.getClient(cid);
|
||||
if (client == nullptr) continue;
|
||||
|
||||
Packet r(PacketType::PLAYER_INFO);
|
||||
Packet r(PacketType::PLAYER_INFO, false);
|
||||
r.data = Serializer()
|
||||
.append(client->cid)
|
||||
.append(client->getPos())
|
||||
|
@ -113,7 +112,7 @@ void Server::handlePlayerPacket(ServerClient &client, Packet& p) {
|
|||
client.setPitch(d.read<float>());
|
||||
client.setYaw(d.read<float>());
|
||||
|
||||
playersUpdated.emplace(client.cid, true);
|
||||
playersUpdated.emplace(client.cid);
|
||||
break;
|
||||
}
|
||||
case PacketType::BLOCK_SET: {
|
||||
|
|
|
@ -32,7 +32,7 @@ private:
|
|||
ClientList clientList;
|
||||
ServerConfig config;
|
||||
|
||||
std::unordered_map<unsigned int, bool> playersUpdated {};
|
||||
std::unordered_set<unsigned int> playersUpdated {};
|
||||
|
||||
double elapsedSeconds = 0;
|
||||
double deltaTime = 0;
|
||||
|
|
|
@ -4,11 +4,11 @@ zepha.register_block("zeus:default:leaves", {
|
|||
name = "Leaves",
|
||||
model = "base:leaf_like",
|
||||
textures = {
|
||||
"zeus:default:leaves",
|
||||
"zeus:default:leaves_puff"
|
||||
"tint(0, zeus:default:leaves)",
|
||||
"tint(0, zeus:default:leaves_puff)"
|
||||
},
|
||||
lowdef_textures = {
|
||||
"zeus:default:leaves_opaque",
|
||||
"tint(0, zeus:default:leaves_opaque)",
|
||||
},
|
||||
toughness = {
|
||||
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
|
||||
slot_spacing: 2px 2px
|
||||
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
|
||||
|
||||
rect[hot_wheel]
|
||||
|
@ -90,15 +105,6 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
slot_spacing: 2px 2px
|
||||
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
|
||||
]], {
|
||||
|
|
Loading…
Reference in New Issue