Commit 5fdff56f authored by Shu's avatar Shu 🍠
Browse files

Raw sphere tool

parent 686505bd
......@@ -14,6 +14,7 @@
- [~] Authentication
- [x] Compression
- [ ] Encryption
- DTLS
- [x] Embedded
- [x] Standalone
......@@ -24,8 +25,10 @@
- [ ] Local prediction
- [ ] Contouring service
- [~] Edit
- [ ] More types
- [ ] Shape iterators
- Cube
- Sphere
- [ ] More types
- Anchor
- Prevent suffocation
- [ ] Local prediction
......
......@@ -6,5 +6,5 @@ layout(location = 0) out vec4 color;
in vec4 Color;
void main(){
color = vec4(Color.xyz, .5);
color = Color;
}
\ No newline at end of file
......@@ -2,14 +2,14 @@
layout(location = 0) in vec3 Position_modelspace;
layout(location = 1) in vec4 Color_model;
uniform mat4 MVP;
uniform vec4 Col;
out vec4 Color;
void main(){
gl_Position = MVP * vec4(Position_modelspace, 1);
Color = Color_model;
Color = Col;
}
......@@ -6,5 +6,5 @@ layout(location = 0) in vec4 Color;
layout(location = 0) out vec4 color;
void main(){
color = vec4(Color.xyz, .5);
color = Color;
}
\ No newline at end of file
......@@ -6,15 +6,15 @@ layout(binding = 0) uniform UniformBufferObject {
} UBO;
layout(push_constant) uniform PushConst {
mat4 model;
vec4 color;
} Push;
layout(location = 0) in vec3 Position_modelspace;
layout(location = 1) in vec4 Color_model;
layout(location = 0) out vec4 Color;
void main(){
gl_Position = UBO.proj * UBO.view * Push.model * vec4(Position_modelspace, 1);
Color = Color_model;
Color = Push.color;
}
......@@ -66,6 +66,8 @@ void Client::run(server_handle* const localHandle) {
const auto ray_result = world->raycast(camera.getRay() * options.voxel_density);
if(auto target = std::get_if<world::Universe::ray_target>(&ray_result)) {
state.look_at = *target;
const auto &tool = options.editor.tool;
state.can_fill = true; //FIXME: world->canFill(target->pos, tool.shape, tool.radius);
} else {
state.look_at = {};
}
......@@ -75,11 +77,11 @@ void Client::run(server_handle* const localHandle) {
ZoneScopedN("Edit");
const auto &tool = options.editor.tool;
if (inputs.isPressing(Mouse::Left))
world->emit(world::action::FillCube(
state.look_at.value().pos, world::Voxel(world::materials::AIR, tool.emptyAir * world::Voxel::DENSITY_MAX), tool.radius));
world->emit(world::action::FillShape(
state.look_at.value().pos, world::Voxel(world::materials::AIR, tool.emptyAir * world::Voxel::DENSITY_MAX), tool.shape, tool.radius));
else if (inputs.isPressing(Mouse::Right))
world->emit(world::action::FillCube(
state.look_at.value().pos, world::Voxel(tool.material, world::Voxel::DENSITY_MAX), tool.radius));
world->emit(world::action::FillShape(
state.look_at.value().pos, world::Voxel(tool.material, world::Voxel::DENSITY_MAX), tool.shape, tool.radius));
}
if (inputs.isDown(Input::Throw)) {
//FIXME: register entity type world->addEntity(entity_id(0), {state.position * options.voxel_density, glm::vec3(10, 0, 0)});
......@@ -196,7 +198,7 @@ void Client::run(server_handle* const localHandle) {
if(state.look_at.has_value()) { // Indicator
const auto model = glm::scale(glm::translate(glm::scale(glm::mat4(1), 1.f / glm::vec3(options.voxel_density)), glm::vec3(state.look_at.value().pos.second + state.look_at.value().offset - offset * glm::llvec3(options.voxel_density)) - glm::vec3(.5 + options.editor.tool.radius)), glm::vec3(1 + options.editor.tool.radius * 2));
reports.models_count++;
reports.tris_count += pass(model);
reports.tris_count += pass(model, options.editor.tool.shape, state.can_fill ? glm::vec4(1, 1, 1, .5) : glm::vec4(1, 0, 0, .5));
}
}
pipeline->postProcess();
......
......@@ -79,6 +79,7 @@ public:
}
editor.visible = config["editor"]["visible"].value_or(editor.visible);
editor.tool.shape = static_cast<world::action::Shape>(config["editor"]["tool"]["shape"].value_or(static_cast<int>(editor.tool.shape)));
editor.tool.radius = config["editor"]["tool"]["radius"].value_or(editor.tool.radius);
editor.tool.material = config["editor"]["tool"]["material"].value_or(editor.tool.material);
editor.tool.emptyAir = config["editor"]["tool"]["empty_air"].value_or(editor.tool.emptyAir);
......@@ -156,6 +157,7 @@ public:
config.insert_or_assign("editor", toml::table({
{"visible", editor.visible},
{"tool", toml::table({
{"shape", static_cast<int>(editor.tool.shape)},
{"radius", editor.tool.radius},
{"material", editor.tool.material},
{"empty_air", editor.tool.emptyAir}
......@@ -205,6 +207,7 @@ public:
struct {
bool visible = false;
struct {
world::action::Shape shape = world::action::Shape::Cube;
int radius = 2;
unsigned short material = 5;
bool emptyAir = true;
......
#pragma once
#include "../../core/flags.hpp"
#include "../../core/world/actions.hpp"
#include <cassert>
#include <memory>
#include <string>
......@@ -73,8 +74,8 @@ public:
virtual std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> beginWorldPass(bool solid) = 0;
/// Get started entity program
virtual std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> beginEntityPass() = 0;
/// Draw cube indicator
virtual std::function<size_t(glm::mat4)> beginIndicatorPass() = 0;
/// Draw line indicator (model, shape, color)
virtual std::function<size_t(glm::mat4, world::action::Shape, glm::vec4)> beginIndicatorPass() = 0;
/// Apply postprocessing
virtual void postProcess() = 0;
/// Finalise frame
......
......@@ -227,6 +227,7 @@ UI::Actions UI::draw(config::client::options &options, state::state &state, cons
ImGui::EndCombo();
}
ImGui::SliderInt("Radius", &options.editor.tool.radius, 0, 10);
ImGui::Combo("Shape", (int*)&options.editor.tool.shape, world::action::SHAPES);
ImGui::Checkbox("Empty air", &options.editor.tool.emptyAir);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Is cleaned area breathable");
......
......@@ -15,10 +15,27 @@ const std::vector<glm::vec3> Shape::SKY_CUBE = {
{-1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f},
{-1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}
};
const std::pair<std::vector<glm::vec3>, std::vector<glm::vec4>> Indicator::CUBE = {{
const std::vector<glm::vec3> Shape::LINE_CUBE = {
{0, 0, 0}, {0, 0, 1}, {0, 0, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 0}, {0, 1, 0}, {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 1, 1},
{1, 1, 1}, {1, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0}, {1, 0, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}, {0, 1, 0}, {1, 1, 0}
}, {
};
constexpr auto SINPIOVER4 = 0.853553391f;
const std::vector<glm::vec3> Shape::LINE_SPHERE = {
{1, .5f, .5f}, {SINPIOVER4, SINPIOVER4, .5f}, {SINPIOVER4, SINPIOVER4, .5f}, {.5f, 1, .5f},
{.5f, 1, .5f}, {1-SINPIOVER4, SINPIOVER4, .5f}, {1-SINPIOVER4, SINPIOVER4, .5f}, {0, .5f, .5f},
{1, .5f, .5f}, {SINPIOVER4, 1-SINPIOVER4, .5f}, {SINPIOVER4, 1-SINPIOVER4, .5f}, {.5f, 0, .5f},
{.5f, 0, .5f}, {1-SINPIOVER4, 1-SINPIOVER4, .5f}, {1-SINPIOVER4, 1-SINPIOVER4, .5f}, {0, .5f, .5f},
{1, .5f, .5f}, {SINPIOVER4, .5f, SINPIOVER4}, {SINPIOVER4, .5f, SINPIOVER4}, {.5f, .5f, 1},
{.5f, .5f, 1}, {1-SINPIOVER4, .5f, SINPIOVER4}, {1-SINPIOVER4, .5f, SINPIOVER4}, {0, .5f, .5f},
{1, .5f, .5f}, {SINPIOVER4, .5f, 1-SINPIOVER4}, {SINPIOVER4, .5f, 1-SINPIOVER4}, {.5f, .5f, 0},
{.5f, .5f, 0}, {1-SINPIOVER4, .5f, 1-SINPIOVER4}, {1-SINPIOVER4, .5f, 1-SINPIOVER4}, {0, .5f, .5f},
{.5f, 1, .5f}, {.5f, SINPIOVER4, SINPIOVER4}, {.5f, SINPIOVER4, SINPIOVER4}, {.5f, .5f, 1},
{.5f, .5f, 1}, {.5f, 1-SINPIOVER4, SINPIOVER4}, {.5f, 1-SINPIOVER4, SINPIOVER4}, {.5f, 0, .5f},
{.5f, 1, .5f}, {.5f, SINPIOVER4, 1-SINPIOVER4}, {.5f, SINPIOVER4, 1-SINPIOVER4}, {.5f, .5f, 0},
{.5f, .5f, 0}, {.5f, 1-SINPIOVER4, 1-SINPIOVER4}, {.5f, 1-SINPIOVER4, 1-SINPIOVER4}, {.5f, 0, .5f}
};
const std::pair<std::vector<glm::vec3>, std::vector<glm::vec4>> ColoredShape::LINE_CUBE = {Shape::LINE_CUBE,
{
{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1},
{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}
}};
......
......@@ -45,14 +45,16 @@ public:
virtual ~Shape() { }
static const std::vector<glm::vec3> SKY_CUBE;
static const std::vector<glm::vec3> LINE_CUBE;
static const std::vector<glm::vec3> LINE_SPHERE;
};
/// Color lines model
class Indicator {
class ColoredShape {
public:
virtual ~Indicator() { }
virtual ~ColoredShape() { }
static const std::pair<std::vector<glm::vec3>, std::vector<glm::vec4>> CUBE;
static const std::pair<std::vector<glm::vec3>, std::vector<glm::vec4>> LINE_CUBE;
};
/// VertexData model with index
......
......@@ -18,7 +18,8 @@ constexpr auto GL_MINOR = 6;
#define TEXTURES_DIR CONTENT_DIR "textures/"
Renderer::Renderer(const renderOptions& options):
IndicatorCubeBuffer(Indicator::CUBE.first, Indicator::CUBE.second) {
IndicatorCubeBuffer(Shape::LINE_CUBE), IndicatorSphereBuffer(Shape::LINE_SPHERE)
{
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
......@@ -122,11 +123,12 @@ std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> Rend
};
}
std::function<size_t(glm::mat4)> Renderer::beginIndicatorPass() {
std::function<size_t(glm::mat4, world::action::Shape, glm::vec4)> Renderer::beginIndicatorPass() {
IndicatorPass->useIt();
return [&](glm::mat4 model) {
IndicatorPass->setup(this, model);
return IndicatorCubeBuffer.draw();
return [&](glm::mat4 model, world::action::Shape shape, glm::vec4 color) {
IndicatorPass->setup(this, model, color);
return shape == world::action::Shape::Cube ?
IndicatorCubeBuffer.draw(GL_LINES) : IndicatorSphereBuffer.draw(GL_LINES);
};
}
......
......@@ -45,7 +45,7 @@ public:
void beginFrame() override;
std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> beginWorldPass(bool solid) override;
std::function<size_t(render::Model *const, const std::vector<glm::mat4>&)> beginEntityPass() override;
std::function<size_t(glm::mat4)> beginIndicatorPass() override;
std::function<size_t(glm::mat4, world::action::Shape, glm::vec4)> beginIndicatorPass() override;
void postProcess() override;
void endFrame() override;
void swapBuffer(Window&) override;
......@@ -72,7 +72,8 @@ private:
std::unique_ptr<pass::EntityProgram> EntityPass;
std::unique_ptr<pass::SkyProgram> SkyPass;
std::unique_ptr<pass::ColorProgram> IndicatorPass;
Indicator IndicatorCubeBuffer;
Shape IndicatorCubeBuffer;
Shape IndicatorSphereBuffer;
glm::mat4 ProjectionMatrix;
glm::mat4 ViewMatrix;
......
......@@ -11,16 +11,16 @@ Shape::Shape(const std::vector<glm::vec3>& pos) {
Shape::~Shape() {
glDeleteBuffers(1, &bufferId);
}
size_t Shape::draw() {
size_t Shape::draw(GLenum format) {
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
glDrawArrays(GL_TRIANGLES, 0, size);
glDrawArrays(format, 0, size);
glDisableVertexAttribArray(0);
return size;
}
Indicator::Indicator(const std::vector<glm::vec3>& pos, const std::vector<glm::vec4>& col) {
ColoredShape::ColoredShape(const std::vector<glm::vec3>& pos, const std::vector<glm::vec4>& col) {
assert(pos.size() == col.size());
size = pos.size();
glGenBuffers(1, &vertexBufferId);
......@@ -30,11 +30,11 @@ Indicator::Indicator(const std::vector<glm::vec3>& pos, const std::vector<glm::v
glBindBuffer(GL_ARRAY_BUFFER, colorBufferId);
glBufferData(GL_ARRAY_BUFFER, col.size() * sizeof(glm::vec4), col.data(), GL_STATIC_DRAW);
}
Indicator::~Indicator() {
ColoredShape::~ColoredShape() {
glDeleteBuffers(1, &colorBufferId);
glDeleteBuffers(1, &vertexBufferId);
}
void Indicator::enableAttribs() {
void ColoredShape::enableAttribs() {
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
......@@ -43,17 +43,17 @@ void Indicator::enableAttribs() {
glBindBuffer(GL_ARRAY_BUFFER, colorBufferId);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void *)0);
}
void Indicator::disableAttribs() {
void ColoredShape::disableAttribs() {
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
}
size_t Indicator::draw() {
size_t ColoredShape::draw() {
enableAttribs();
glDrawArrays(GL_LINES, 0, size);
disableAttribs();
return size;
}
size_t Indicator::drawInstanced(size_t count) {
size_t ColoredShape::drawInstanced(size_t count) {
enableAttribs();
glDrawArraysInstanced(GL_LINES, 0, size, count);
disableAttribs();
......
......@@ -13,17 +13,17 @@ public:
Shape(const std::vector<glm::vec3>&);
~Shape();
size_t draw();
size_t draw(GLenum format);
private:
size_t size;
GLuint bufferId;
};
class Indicator final: public render::Indicator {
class ColoredShape final: public render::ColoredShape {
public:
Indicator(const std::vector<glm::vec3>&, const std::vector<glm::vec4>&);
~Indicator();
ColoredShape(const std::vector<glm::vec3>&, const std::vector<glm::vec4>&);
~ColoredShape();
size_t draw();
size_t drawInstanced(size_t count);
......
......@@ -13,6 +13,7 @@ ColorProgram::ColorProgram(): Program() {
load(shaders);
MVPMatrixID = glGetUniformLocation(ProgramID, "MVP");
ColID = glGetUniformLocation(ProgramID, "Col");
}
ColorProgram::~ColorProgram() { }
......@@ -20,11 +21,15 @@ ColorProgram::~ColorProgram() { }
std::string ColorProgram::getName() const {
return "Color";
}
void ColorProgram::setup(render::gl::Renderer *renderer, glm::mat4 modelMatrix) {
void ColorProgram::setup(render::gl::Renderer *renderer, glm::mat4 modelMatrix, glm::vec4 color) {
const auto mvp = renderer->getProjectionMatrix() * renderer->getViewMatrix() * modelMatrix;
setMVP(&mvp[0][0]);
setCol(&color[0]);
}
void ColorProgram::setMVP(const GLfloat *matrix) {
glUniformMatrix4fv(MVPMatrixID, 1, GL_FALSE, matrix);
}
void ColorProgram::setCol(const GLfloat *color) {
glUniform4fv(ColID, 1, color);
}
......@@ -9,13 +9,15 @@ namespace pass {
ColorProgram();
~ColorProgram();
void setup(render::gl::Renderer *, glm::mat4 modelMatrix);
void setup(render::gl::Renderer *, glm::mat4 modelMatrix, glm::vec4 color);
protected:
std::string getName() const override;
void setMVP(const GLfloat *matrix);
void setCol(const GLfloat *color);
private:
GLuint MVPMatrixID;
GLuint ColID;
};
}
......@@ -32,7 +32,7 @@ void SkyProgram::start(render::gl::Renderer *renderer) {
void SkyProgram::draw(render::gl::Renderer *renderer) {
useIt();
start(renderer);
CubeBuffer.draw();
CubeBuffer.draw(GL_TRIANGLES);
}
void SkyProgram::setView(const GLfloat *matrix) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment