Commit 686505bd authored by Shu's avatar Shu 🍠
Browse files

Player's entities

parent 7920e8b4
......@@ -25,12 +25,16 @@
- [ ] Contouring service
- [~] Edit
- [ ] More types
- Sphere
- Anchor
- Prevent suffocation
- [ ] Local prediction
- [~] Occlusion Culling
- [ ] Iterator ray
- [ ] Cast from chunk center
- [x] Transparency
- [ ] Entities
- [~] Entities
- Get models
## Hello universe
......@@ -63,6 +67,7 @@
## Hello darkness
- [ ] Break area part to entity
- [ ] Slash screen
- [ ] Start/Pause menu
- [ ] QUIC protocal
......@@ -70,7 +75,7 @@
- [ ] Octree
- [ ] Better Lod
- [ ] VK
- [ ] Pipeline recreate
- [ ] Instanced draw
- [ ] Pipeline cache
- [ ] Reuse descriptors
- [ ] Secondary buffers
......
......@@ -122,7 +122,7 @@ void main() {
vec3 blendWeights = abs(vs.FaceNormal_modelspace);
blendWeights = blendWeights - plateauSize;
blendWeights = pow(max(blendWeights, 0), vec3(transitionSpeed));
blendWeights = normalize(pow(max(blendWeights, 0), vec3(transitionSpeed)));
vec2 UVx = vs.Position_modelspace.yz * texScale;
vec2 UVy = vs.Position_modelspace.zx * texScale;
vec2 UVz = vs.Position_modelspace.xy * texScale;
......
......@@ -139,7 +139,7 @@ if(TRIPLANAR) {
vec2 UVy = vs.Position_modelspace.zx * texScale;
vec2 UVz = vs.Position_modelspace.xy * texScale;
tex = getTriTexture(TextureAtlas, UVx, UVy, UVz, blendWeights);
tex = getTriTexture(TextureAtlas, UVx, UVy, UVz, normalize(blendWeights));
if(PBR) {
// Whiteout normal blend
......
......@@ -183,11 +183,13 @@ void Client::run(server_handle* const localHandle) {
}
{ // Entities
const auto pass = pipeline->beginEntityPass();
/*const auto draw = [&](const std::vector<glm::mat4>& models, buffer::Abstract *const buffer) {
reports.models_count += models.size();
reports.tris_count += buffer->draw(pass(models));
};*/
//world->getEntitiesModels(draw, frustum, offset, options.voxel_density);
const auto draw = [&](size_t idx, const std::vector<glm::mat4> &models) {
if(const auto buffer = state.contouring->getEntityModel(idx)) {
reports.models_count += models.size();
reports.tris_count += pass(buffer, models);
}
};
world->getEntitiesModels(draw, frustum, offset, options.voxel_density);
}
{
const auto pass = pipeline->beginIndicatorPass();
......
......@@ -4,8 +4,13 @@
#include "../../core/geometry/Frustum.hpp"
#include "../../core/geometry/Ray.hpp"
#include "../../core/geometry/Faces.hpp"
#include "../../core/flags.hpp"
#include <glm/gtc/matrix_transform.hpp>
namespace render { class LodModel; }
namespace render {
class Model;
class LodModel;
}
/// Mesh creation (from world to render)
namespace contouring {
/// Generating mesh from world data
......@@ -43,5 +48,19 @@ namespace contouring {
/// Get buffers hitting occlusion rays with model matrices
/// @note buffers invalidated after update
virtual void getModels(draw_call draw, const glm::ifvec3 &from, float far, const std::vector<glm::vec3> &occlusion, const glm::llvec3 &offset, int density, bool solid) = 0;
/// Get buffer corresponding to entity idx
virtual render::Model* getEntityModel(size_t) = 0;
/// Get entity instance model if in frustum
static _FORCE_INLINE_ bool CullEntity(glm::mat4& out, const glm::vec3& size, const glm::vec3& scale, const glm::ifvec3& pos,
const std::optional<geometry::Frustum>& frustum, const glm::llvec3& offset, int density)
{
const glm::vec3 fPos = (glm::vec3(pos.raw_as_long() - offset * glm::llvec3(density)) + pos.offset) / glm::vec3(density);
if (!frustum.has_value() || frustum.value().contains(geometry::Box::fromMin(fPos, size))) {
out = glm::scale(glm::translate(glm::mat4(1), fPos * (float)density), scale);
return true;
}
return false;
};
};
}
\ No newline at end of file
......@@ -60,6 +60,22 @@ namespace contouring {
}
});
}
{ //TODO: render for chunk(s)
auto pack = [](const glm::vec3 &pos) {
return render::PackedVertexData(meshopt_quantizeHalf(pos.x), meshopt_quantizeHalf(pos.y),
meshopt_quantizeHalf(pos.z), world::materials::textures_map[7],
meshopt_quantizeHalf(pos.x), meshopt_quantizeHalf(pos.y),
meshopt_quantizeHalf(pos.z));
};
playerModel = render::Model::Create(render::Model::Data({
pack({1, 0, 0}), pack({0, 1, 0}), pack({0, 0, 1}),
pack({-1, 0, 0}), pack({0, -1, 0}), pack({0, 0, -1})
}, {
0, 1, 2, 0, 5, 1, 0, 2, 4, 0, 4, 5,
1, 3, 2, 5, 3, 1, 2, 3, 4, 4, 3, 5
}));
}
}
FlatDualMC::~FlatDualMC() {
running = false;
......@@ -361,4 +377,8 @@ namespace contouring {
}
}
render::Model* FlatDualMC::getEntityModel(size_t) {
return playerModel.get();
}
}
......@@ -38,10 +38,14 @@ namespace contouring {
/// @note buffers invalidated after update
void getModels(draw_call draw, const glm::ifvec3 &from, float far, const std::vector<glm::vec3> &occlusion, const glm::llvec3 &offset, int density, bool solid) override;
render::Model* getEntityModel(size_t) override;
protected:
//FIXME: use unique_ptr
robin_hood::unordered_map<area_id, robin_hood::pair<area_info, robin_hood::unordered_map<chunk_pos, std::pair<render::LodModel *, render::LodModel *>>>> buffers;
std::unique_ptr<render::Model> playerModel;
safe_priority_queue_map<area_<chunk_pos>, surrounding::corners, int, area_hash> loadQueue;
safe_queue<std::pair<area_<chunk_pos>, std::pair<render::LodModel::LodData, render::LodModel::LodData>>> loadedQueue;
......
......@@ -87,6 +87,7 @@ bool Renderer::Load(Window& window, const renderOptions& opt, const windowOption
sInstance = new Renderer(opt);
sInstance->setVSync(windOpt.targetFPS < Window::MIN_FPS);
Model::MakeDefault();
LodModel::MakeDefault();
return true;
}
......
......@@ -144,6 +144,13 @@ size_t LodModel::drawInstanced(size_t i) {
return i * count;
}
std::unique_ptr<render::Model> createModel(const Model::Data& data) {
return std::make_unique<Model>(data);
}
void Model::MakeDefault() {
createFunc = createModel;
}
std::unique_ptr<render::LodModel> createLodModel(const LodModel::LodData& data) {
return std::make_unique<LodModel>(data);
}
......
......@@ -42,6 +42,8 @@ public:
Model(const Data&);
~Model();
static void MakeDefault();
size_t draw();
size_t drawInstanced(size_t count);
......
......@@ -315,7 +315,23 @@ size_t CommandCenter::recordModel(uint32_t i, const Subpass &worldPass, const Un
vkCmdDrawIndexed(graphicsBuffers[i], size, 1, modelBuffer->getIndexStart(), 0, 0);
return size;
}
void CommandCenter::startEntityPass(uint32_t) { }
void CommandCenter::startEntityPass(uint32_t, const Subpass&) { }
size_t CommandCenter::recordModels(uint32_t i, const Subpass &entityPass, const std::vector<glm::mat4> &matrices, const Model *const modelBuffer) {
VkBuffer vertexBuffers[] = {modelBuffer->getVertex()};
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers(graphicsBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(graphicsBuffers[i], modelBuffer->getIndex(), 0, VK_INDEX_TYPE_UINT16);
auto size = modelBuffer->getIndexSize();
UniqueCurvaturePush push;
push.curvature = 0;
for(const auto& matrix: matrices) {
push.model = matrix;
vkCmdPushConstants(graphicsBuffers[i], entityPass.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(push), &push);
vkCmdDrawIndexed(graphicsBuffers[i], size, 1, 0, 0, 0);
}
return size * matrices.size();
}
void CommandCenter::startIndicPass(uint32_t idx, const Subpass& indicPass) {
vkCmdNextSubpass(graphicsBuffers[idx], VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(graphicsBuffers[idx], VK_PIPELINE_BIND_POINT_GRAPHICS, indicPass.pipeline);
......
......@@ -26,7 +26,8 @@ public:
void startRecording(uint32_t idx, VkRenderPass, VkExtent2D, const VoxelUBO&);
void startWorldPass(uint32_t idx, const Subpass&);
size_t recordModel(uint32_t idx, const Subpass &worldPass, const UniqueCurvaturePush&, const LodModel *const);
void startEntityPass(uint32_t idx);
void startEntityPass(uint32_t idx, const Subpass &entityPass);
size_t recordModels(uint32_t idx, const Subpass &entityPass, const std::vector<glm::mat4>&, const Model *const);
void startIndicPass(uint32_t idx, const Subpass&);
size_t recordIndicator(uint32_t idx, const Subpass&, glm::mat4 model);
void recordPostprocess(uint32_t idx, const Subpass&, bool skybox);
......
......@@ -23,6 +23,7 @@ public:
// Voxels (world & entity) passes descriptor set
constexpr VkDescriptorSetLayout getVoxelDescriptorSet() const { return voxelDescriptorSet; }
constexpr const Subpass& getWorldPass() const { return worldPass; }
constexpr const Subpass &getEntitiesPass() const { return worldPass; }
constexpr VkDescriptorSetLayout getIndicDescriptorSet() const { return indicDescriptorSet; }
constexpr const Subpass &getIndicPass() const { return indicPass; }
constexpr VkDescriptorSetLayout getSkyDescriptorSet() const { return skyDescriptorSet; }
......
......@@ -415,6 +415,7 @@ bool Renderer::Load(Window& window, const renderOptions& opt, const windowOption
}
sInstance = new Renderer(instance, device, physicalInfo, opt);
Model::MakeDefault();
LodModel::MakeDefault();
return true;
}
......@@ -471,10 +472,14 @@ std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> Rend
std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> Renderer::beginEntityPass() {
assert(currentImage < swapChain->getImageViews().size());
commandCenter->startEntityPass(currentImage);
return [&](render::Model *const, const std::vector<glm::mat4>&) {
return 0; //EntityPass->setup(this, models);
auto& pass = pipeline->getEntitiesPass();
commandCenter->startEntityPass(currentImage, pass);
return [&](render::Model *const rBuffer, const std::vector<glm::mat4>& models) {
auto buffer = dynamic_cast<render::vk::Model *const>(rBuffer);
buffer->setLastUse(currentImage);
return commandCenter->recordModels(currentImage, pass, models, buffer);
};
return [](render::Model *const, const std::vector<glm::mat4> &) { return 0; };
}
std::function<size_t(glm::mat4)> Renderer::beginIndicatorPass() {
......
......@@ -38,6 +38,13 @@ std::unique_ptr<LodModel> LodModel::Create(const LodData& data) {
return std::unique_ptr<LodModel>(new LodModel(data.first.indices.size(), data.second, tmp.at(0).ref, tmp.at(1).ref, std::move(mem)));
}
std::unique_ptr<render::Model> createModelVk(const Model::Data& data) {
return Model::Create(data);
}
void Model::MakeDefault() {
render::Model::createFunc = createModelVk;
}
std::unique_ptr<render::LodModel> createLodModelVk(const LodModel::LodData& data) {
return LodModel::Create(data);
}
......
......@@ -71,8 +71,12 @@ protected:
class Model final: public render::Model, public ShortIndexedVertexBuffer {
public:
constexpr size_t getIndexSize() const { return indexSize; }
static std::unique_ptr<Model> Create(const Data &);
static void MakeDefault();
static VkVertexInputBindingDescription getBindingDescription() {
VkVertexInputBindingDescription description{};
description.binding = 0;
......
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