Commit a774e99d authored by Shu's avatar Shu 🍠
Browse files

WIP: Vulkan skybox (bug on intel mesa ???)

parent 07d12b34
#version 450 core
layout(push_constant) uniform PushConstants {
mat4 View;
mat4 Projection;
} Push;
layout(binding = 0) uniform UniformBufferObject {
mat4 view;
mat4 proj;
} ubo;
layout (location = 0) in vec3 Position_modelspace;
......@@ -11,5 +11,7 @@ layout (location = 0) out vec3 UV;
void main(){
UV = Position_modelspace;
gl_Position = (Push.Projection * Push.View * vec4(Position_modelspace, 1.0)).xyww;
mat4 view = ubo.view;
view[3] = vec4(0.0f, 0.0f, 0.0f, 1.0f);
gl_Position = (ubo.proj * view * vec4(Position_modelspace, 1.0)).xyww;
}
\ No newline at end of file
......@@ -2,10 +2,12 @@
#extension GL_ARB_separate_shader_objects : enable
layout(binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
} ubo;
layout(push_constant) uniform PushConst {
mat4 model;
} Push;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
......@@ -15,7 +17,7 @@ layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragTexCoord;
void main() {
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
gl_Position = ubo.proj * ubo.view * Push.model * vec4(inPosition, 1.0);
fragColor = inColor;
fragTexCoord = inTexCoord;
}
\ No newline at end of file
......@@ -10,26 +10,18 @@ layout (constant_id = 4) const bool BLEND = true;
layout (constant_id = 16) const int UNIT_SIZE = 8;
layout (binding = 0) uniform UniformBufferObject {
vec3 FogColor;
float FogDepth;
mat4 Proj;
mat4 View;
vec3 LightInvDirection_worldspace;
vec3 FogColor;
float FogDepth;
} UBO;
layout (binding = 1) uniform sampler2DArray TextureAtlas;
layout (binding = 2) uniform sampler2DArray NormalAtlas;
layout (binding = 3) uniform sampler2DArray HOSAtlas;
layout(push_constant) uniform PushConstants {
mat4 Proj;
mat4 View;
#ifndef INSTANCED
mat4 Model;
#endif
vec4 SphereProj;
float Curvature;
} Push;
#ifdef GEOMETRY
layout (location = 0) in GeometryData
#else
......@@ -189,7 +181,7 @@ if(PBR) {
vec3 TextureAmbientColor = vec3(.1) * TextureDiffuseColor * texHOS.y;
vec3 TextureSpecularColor = vec3(.8) * texHOS.z;
vec3 Normal_cameraspace = normalize((Push.View * vec4(worldNormal,0)).xyz);
vec3 Normal_cameraspace = normalize((UBO.View * vec4(worldNormal,0)).xyz);
// Light emission properties
// You probably want to put them as uniforms
......
......@@ -8,15 +8,16 @@ layout (constant_id = 5) const bool DO_CURVATURE = false;
layout (constant_id = 6) const bool CURV_DEPTH = true;
layout (binding = 0) uniform UniformBufferObject {
vec3 FogColor;
float FogDepth;
mat4 Proj;
mat4 View;
vec3 LightInvDirection_worldspace;
vec3 FogColor;
float FogDepth;
} UBO;
layout(push_constant) uniform PushConstants {
mat4 Proj; //MAYBE: move Proj View to UBO
mat4 View;
#ifndef INSTANCED
mat4 Model;
#endif
......@@ -63,8 +64,8 @@ if(DO_CURVATURE) {
}
}
vec4 Position_cameraspace = Push.View * Model * vec4(vs.Position_modelspace, 1);
gl_Position = Push.Proj * Position_cameraspace;
vec4 Position_cameraspace = UBO.View * Model * vec4(vs.Position_modelspace, 1);
gl_Position = UBO.Proj * Position_cameraspace;
if(FOG) {
vs.Depth = length(Position_cameraspace.xyz) / UBO.FogDepth;
......@@ -82,6 +83,6 @@ if(PBR) {
vs.EyeDirection_cameraspace = vec3(0,0,0) - Position_cameraspace.xyz;
// Vector that goes from the vertex to the light, in camera space
vs.LightDirection_cameraspace = (Push.View * vec4(UBO.LightInvDirection_worldspace,0)).xyz;
vs.LightDirection_cameraspace = (UBO.View * vec4(UBO.LightInvDirection_worldspace,0)).xyz;
}
}
......@@ -30,7 +30,6 @@ void Client::run(server_handle* const localHandle) {
auto world = world::client::Load(options.connection, localHandle, options.world, options.contouring);
state.contouring = world->getContouring();
//TODO: loop
do {
window.startFrame();
FrameMark;
......@@ -131,9 +130,8 @@ void Client::run(server_handle* const localHandle) {
{ // Chunks
const auto pass = pipeline->beginWorldPass();
const auto draw = [&](glm::mat4 model, render::LodModel *const buffer, const contouring::Abstract::area_info &area, const voxel_pos &pos) {
pipeline->setCurvature(glm::vec4(pos, std::get<1>(area)), std::get<2>(area));
reports.models_count++;
reports.tris_count += pass(buffer, model);
reports.tris_count += pass(buffer, model, glm::vec4(pos, std::get<1>(area)), std::get<2>(area));
};
if (options.culling > 0) {
std::vector<glm::vec3> occlusion;
......@@ -166,9 +164,9 @@ void Client::run(server_handle* const localHandle) {
reports.models_count++;
reports.tris_count += pipeline->drawIndicatorCube(model);
}
pipeline->endPass();
pipeline->postProcess();
render::UI::Get()->render();
pipeline->endFrame();
}
{ // Swap buffers
......
......@@ -14,6 +14,7 @@ void Camera::updateProjection() {
void Camera::update() {
const auto &offset = origin->position.offset;
// FIXME: up inverted after backflip
const auto axis = origin->getAxis();
// Camera matrix
ViewMatrix = glm::lookAt(
......
......@@ -64,13 +64,16 @@ public:
/// Start new frame and setup
virtual void beginFrame() = 0;
/// Get started world program
virtual std::function<size_t(render::LodModel *const, glm::mat4)> beginWorldPass() = 0;
/// (vertex buffer, model matrix, sphereProj, curvature)
virtual std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> beginWorldPass() = 0;
/// Get started entity program
virtual std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> beginEntityPass() = 0;
/// Draw cube indicator
virtual size_t drawIndicatorCube(glm::mat4 model) = 0;
/// Apply postprocessing
virtual void endPass() = 0;
virtual void postProcess() = 0;
/// Finalise frame
virtual void endFrame() = 0;
/// Swap displayed image
virtual void swapBuffer(Window &) = 0;
......@@ -78,7 +81,6 @@ public:
virtual void lookFrom(const Camera &) = 0;
virtual void setClearColor(glm::vec4) = 0;
virtual void setCurvature(glm::vec4, float) = 0;
virtual void reloadShaders(const passOptions &) = 0;
virtual void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) = 0;
......
......@@ -3,6 +3,8 @@
using namespace render;
std::unique_ptr<Texture> (*Texture::loadFunc)(const std::string&, const sampling&) = nullptr;
std::unique_ptr<TextureCube> (*TextureCube::loadFunc)(const std::array<std::string, 6>&, const Texture::sampling &) = nullptr;
std::unique_ptr<TextureArray> (*TextureArray::loadFunc)(const std::vector<std::string>&, const Texture::sampling &) = nullptr;
#include <stdio.h>
#include <string.h>
......
......@@ -73,20 +73,24 @@ public:
};
struct requirement: properties {
requirement(const properties& props, Layout layout, Usage usage, Aspect aspect,
int samples = 1, bool optimal = true): properties(props), layout(layout),
usage(usage), aspect(aspect), samples(samples), optimal(optimal)
int samples = 1, uint32_t layers = 1, bool cube = false, bool optimal = true):
properties(props), layout(layout), usage(usage), aspect(aspect), samples(samples),
layers(layers), cube(cube), optimal(optimal)
{
assert(samples > 0 && (std::ceil(std::log2(samples)) == std::floor(std::log2(samples))) && "Samples must be pow2");
assert(!cube || layers == 6);
}
Layout layout;
Usage usage;
Aspect aspect;
//NOTE: matches VkSampleCountFlagBits
int samples;
uint32_t layers;
bool cube;
bool optimal;
static requirement Texture(const properties &props) {
return requirement(props, Layout::SHADER_READ_ONLY, Usage::SAMPLED, Aspect::COLOR); }
static requirement Texture(const properties &props, uint32_t arraySize = 1, bool cube = false) {
return requirement(props, Layout::SHADER_READ_ONLY, Usage::SAMPLED, Aspect::COLOR, 1, arraySize, cube); }
};
static std::optional<properties> Read(const std::string&, std::vector<unsigned char>& data);
......@@ -120,4 +124,36 @@ public:
protected:
static std::unique_ptr<Texture> (*loadFunc)(const std::string&, const sampling&);
};
/// Const 6 dept image (single textureCube) with sampler
class TextureCube: public Image {
public:
/// Only supports dds files
/// DXT3(BC2) DXT5(BC3)
static _FORCE_INLINE_ std::unique_ptr<TextureCube> LoadFromFiles(const std::array<std::string, 6> &paths, const Texture::sampling &props) {
assert(loadFunc != nullptr && "Uninitialized renderer");
return loadFunc(paths, props);
}
protected:
static std::unique_ptr<TextureCube> (*loadFunc)(const std::array<std::string, 6>&, const Texture::sampling&);
};
/// Const image array (textureArray) with sampler
class TextureArray: public Image {
public:
/// Only supports dds files
/// DXT3(BC2) DXT5(BC3)
static _FORCE_INLINE_ std::unique_ptr<TextureArray> LoadFromFiles(const std::vector<std::string> &paths, const Texture::sampling &props) {
assert(loadFunc != nullptr && "Uninitialized renderer");
return loadFunc(paths, props);
}
constexpr uint32_t getSize() const { return size; }
protected:
TextureArray(uint32_t size): size(size) { }
uint32_t size;
static std::unique_ptr<TextureArray> (*loadFunc)(const std::vector<std::string>&, const Texture::sampling&);
};
}
\ No newline at end of file
......@@ -115,11 +115,11 @@ void Renderer::beginFrame() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
std::function<size_t(render::LodModel *const, glm::mat4)> Renderer::beginWorldPass() {
std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> Renderer::beginWorldPass() {
WorldPass->useIt();
WorldPass->start(this);
return [&](render::LodModel *const buf, glm::mat4 model) {
WorldPass->setup(this, model);
return [&](render::LodModel *const buf, glm::mat4 model, glm::vec4 sph, float curv) {
WorldPass->setup(model, sph, curv);
return dynamic_cast<LodModel *const>(buf)->draw();
};
}
......@@ -128,7 +128,7 @@ std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> Rend
EntityPass->useIt();
EntityPass->start(this);
return [&](render::Model *const buf, const std::vector<glm::mat4> &models) {
EntityPass->setup(this, models);
EntityPass->setup(models);
return dynamic_cast<Model *const>(buf)->drawInstanced(models.size());
};
}
......@@ -139,11 +139,12 @@ size_t Renderer::drawIndicatorCube(glm::mat4 model) {
return IndicatorCubeBuffer.draw();
}
void Renderer::endPass() {
void Renderer::postProcess() {
if(SkyEnable) {
SkyPass->draw(this);
}
}
void Renderer::endFrame() { }
void Renderer::swapBuffer(Window& w) {
TracyGpuZone("Swap");
......@@ -188,7 +189,3 @@ void Renderer::setClearColor(glm::vec4 c) {
FogColor = c;
glClearColor(c.r, c.g, c.b, c.a);
}
void Renderer::setCurvature(glm::vec4 sp, float c) {
SphereProj = sp;
Curvature = c;
}
\ No newline at end of file
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