Indicator pass
parent
7cdb3c636f
commit
74e156179f
BIN
resource/content/shaders/Color.fs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Color.fs.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Color.vs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Color.vs.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Sky.fs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Sky.fs.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Sky.vs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Sky.vs.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Tris.fs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Tris.fs.spv (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
BIN
resource/content/shaders/Tris.vs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Tris.vs.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.fs.geo.ins.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.fs.geo.ins.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.fs.geo.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.fs.geo.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.fs.ins.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.fs.ins.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.fs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.fs.spv (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
resource/content/shaders/Voxel.gs.geo.ins.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.gs.geo.ins.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.gs.geo.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.gs.geo.spv (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
resource/content/shaders/Voxel.vs.geo.ins.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.vs.geo.ins.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.vs.geo.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.vs.geo.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.vs.ins.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.vs.ins.spv (Stored with Git LFS)
Binary file not shown.
BIN
resource/content/shaders/Voxel.vs.spv (Stored with Git LFS)
BIN
resource/content/shaders/Voxel.vs.spv (Stored with Git LFS)
Binary file not shown.
|
@ -1,7 +1,11 @@
|
|||
#version 450 core
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
mat4 MVP;
|
||||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} UBO;
|
||||
layout(push_constant) uniform PushConst {
|
||||
mat4 model;
|
||||
} Push;
|
||||
|
||||
layout(location = 0) in vec3 Position_modelspace;
|
||||
|
@ -10,7 +14,7 @@ layout(location = 1) in vec4 Color_model;
|
|||
layout(location = 0) out vec4 Color;
|
||||
|
||||
void main(){
|
||||
gl_Position = Push.MVP * vec4(Position_modelspace, 1);
|
||||
gl_Position = UBO.proj * UBO.view * Push.model * vec4(Position_modelspace, 1);
|
||||
Color = Color_model;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
} UBO;
|
||||
|
||||
layout (location = 0) in vec3 Position_modelspace;
|
||||
|
||||
|
@ -11,7 +11,7 @@ layout (location = 0) out vec3 UV;
|
|||
|
||||
void main(){
|
||||
UV = Position_modelspace;
|
||||
mat4 view = ubo.view;
|
||||
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;
|
||||
gl_Position = (UBO.proj * view * vec4(Position_modelspace, 1.0)).xyww;
|
||||
}
|
|
@ -4,20 +4,20 @@
|
|||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
} UBO;
|
||||
layout(push_constant) uniform PushConst {
|
||||
mat4 model;
|
||||
} Push;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in vec2 inTexCoord;
|
||||
layout(location = 0) in vec3 Position_modelspace;
|
||||
layout(location = 1) in vec3 Color_model;
|
||||
layout(location = 2) in vec2 TexCoord_model;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec2 fragTexCoord;
|
||||
layout(location = 0) out vec3 Color;
|
||||
layout(location = 1) out vec2 TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.proj * ubo.view * Push.model * vec4(inPosition, 1.0);
|
||||
fragColor = inColor;
|
||||
fragTexCoord = inTexCoord;
|
||||
gl_Position = UBO.proj * UBO.view * Push.model * vec4(Position_modelspace, 1.0);
|
||||
Color = Color_model;
|
||||
TexCoord = TexCoord_model;
|
||||
}
|
|
@ -10,13 +10,12 @@ layout (constant_id = 4) const bool BLEND = true;
|
|||
layout (constant_id = 16) const int UNIT_SIZE = 8;
|
||||
|
||||
layout (binding = 0) uniform UniformBufferObject {
|
||||
mat4 Proj;
|
||||
mat4 View;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
|
||||
vec3 LightInvDirection_worldspace;
|
||||
vec3 lightInvDirection_worldspace;
|
||||
|
||||
vec3 FogColor;
|
||||
float FogDepth;
|
||||
vec4 fog; //color.rgb depth.a
|
||||
} UBO;
|
||||
layout (binding = 1) uniform sampler2DArray TextureAtlas;
|
||||
layout (binding = 2) uniform sampler2DArray NormalAtlas;
|
||||
|
@ -181,7 +180,7 @@ if(PBR) {
|
|||
vec3 TextureAmbientColor = vec3(.1) * TextureDiffuseColor * texHOS.y;
|
||||
vec3 TextureSpecularColor = vec3(.8) * texHOS.z;
|
||||
|
||||
vec3 Normal_cameraspace = normalize((UBO.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
|
||||
|
@ -226,7 +225,7 @@ if(PBR) {
|
|||
}
|
||||
if(FOG) {
|
||||
float ratio = exp(vs.Depth * 0.69)-1;
|
||||
color = mix(color, pow(UBO.FogColor, vec3(2.2)), clamp(ratio, 0, 1));
|
||||
color = mix(color, pow(UBO.fog.rgb, vec3(2.2)), clamp(ratio, 0, 1));
|
||||
}
|
||||
color = pow(color, vec3(1.0 / 2.2));
|
||||
if(color.r > 1 || color.g > 1 || color.b > 1) {
|
||||
|
|
|
@ -8,22 +8,21 @@ layout (constant_id = 5) const bool DO_CURVATURE = false;
|
|||
layout (constant_id = 6) const bool CURV_DEPTH = true;
|
||||
|
||||
layout (binding = 0) uniform UniformBufferObject {
|
||||
mat4 Proj;
|
||||
mat4 View;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
|
||||
vec3 LightInvDirection_worldspace;
|
||||
vec3 lightInvDirection_worldspace;
|
||||
|
||||
vec3 FogColor;
|
||||
float FogDepth;
|
||||
vec4 fog; //color.rgb depth.a
|
||||
} UBO;
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
layout(push_constant) uniform PushConst {
|
||||
#ifndef INSTANCED
|
||||
mat4 Model;
|
||||
mat4 model;
|
||||
#endif
|
||||
|
||||
vec4 SphereProj;
|
||||
float Curvature;
|
||||
vec4 sphereProj;
|
||||
float curvature;
|
||||
} Push;
|
||||
|
||||
layout (location = 0) in vec3 Position_modelspace;
|
||||
|
@ -48,27 +47,27 @@ layout (location = 0) out VertexData {
|
|||
|
||||
void main(){
|
||||
#ifndef INSTANCED
|
||||
mat4 Model = Push.Model;
|
||||
mat4 Model = Push.model;
|
||||
#endif
|
||||
|
||||
vs.Position_modelspace = Position_modelspace;
|
||||
|
||||
if(DO_CURVATURE) {
|
||||
if(Push.Curvature > 0) {
|
||||
vec3 Position_areaspace = Position_modelspace + Push.SphereProj.xyz;
|
||||
if(Push.curvature > 0) {
|
||||
vec3 Position_areaspace = Position_modelspace + Push.sphereProj.xyz;
|
||||
vec2 sph = vec2(acos(Position_areaspace.z / length(Position_areaspace.xyz)), atan(Position_areaspace.y, Position_areaspace.x));
|
||||
float radius = CURV_DEPTH ?
|
||||
max(max(abs(Position_areaspace.x), abs(Position_areaspace.y)), abs(Position_areaspace.z)) :
|
||||
Push.SphereProj.w;
|
||||
vs.Position_modelspace = mix(vs.Position_modelspace, vec3(sin(sph.x)*cos(sph.y), sin(sph.x)*sin(sph.y), cos(sph.x)) * radius - Push.SphereProj.xyz, Push.Curvature);
|
||||
Push.sphereProj.w;
|
||||
vs.Position_modelspace = mix(vs.Position_modelspace, vec3(sin(sph.x)*cos(sph.y), sin(sph.x)*sin(sph.y), cos(sph.x)) * radius - Push.sphereProj.xyz, Push.curvature);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 Position_cameraspace = UBO.View * Model * vec4(vs.Position_modelspace, 1);
|
||||
gl_Position = UBO.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;
|
||||
vs.Depth = length(Position_cameraspace.xyz) / UBO.fog.a;
|
||||
}
|
||||
|
||||
vs.Texture = Texture_model;
|
||||
|
@ -83,6 +82,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 = (UBO.View * vec4(UBO.LightInvDirection_worldspace,0)).xyz;
|
||||
vs.LightDirection_cameraspace = (UBO.view * vec4(UBO.lightInvDirection_worldspace,0)).xyz;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ $GLSL $BASEDIR/Sky.frag -o $TARGETDIR/Sky.fs.spv
|
|||
# Voxel
|
||||
$GLSL $BASEDIR/Voxel.vert -o $TARGETDIR/Voxel.vs.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -o $TARGETDIR/Voxel.fs.spv
|
||||
$GLSL $BASEDIR/Voxel.vert -DINSTANCED -o $TARGETDIR/Voxel.vs.ins.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DINSTANCED -o $TARGETDIR/Voxel.fs.ins.spv
|
||||
$GLSL $BASEDIR/Voxel.vert -DINSTANCED -o $TARGETDIR/Voxel.ins.vs.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DINSTANCED -o $TARGETDIR/Voxel.ins.fs.spv
|
||||
|
||||
$GLSL $BASEDIR/Voxel.vert -DGEOMETRY -o $TARGETDIR/Voxel.vs.geo.spv
|
||||
$GLSL $BASEDIR/Voxel.geom -DGEOMETRY -o $TARGETDIR/Voxel.gs.geo.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DGEOMETRY -o $TARGETDIR/Voxel.fs.geo.spv
|
||||
$GLSL $BASEDIR/Voxel.vert -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.vs.geo.ins.spv
|
||||
$GLSL $BASEDIR/Voxel.geom -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.gs.geo.ins.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.fs.geo.ins.spv
|
||||
$GLSL $BASEDIR/Voxel.vert -DGEOMETRY -o $TARGETDIR/Voxel.geo.vs.spv
|
||||
$GLSL $BASEDIR/Voxel.geom -DGEOMETRY -o $TARGETDIR/Voxel.geo.gs.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DGEOMETRY -o $TARGETDIR/Voxel.geo.fs.spv
|
||||
$GLSL $BASEDIR/Voxel.vert -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.geo.ins.vs.spv
|
||||
$GLSL $BASEDIR/Voxel.geom -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.geo.ins.gs.spv
|
||||
$GLSL $BASEDIR/Voxel.frag -DGEOMETRY -DINSTANCED -o $TARGETDIR/Voxel.geo.ins.fs.spv
|
|
@ -7,6 +7,22 @@ using namespace render;
|
|||
std::unique_ptr<Model> (*Model::createFunc)(const Data&) = nullptr;
|
||||
std::unique_ptr<LodModel> (*LodModel::createFunc)(const LodData&) = nullptr;
|
||||
|
||||
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},
|
||||
{ 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},
|
||||
{-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 = {{
|
||||
{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}
|
||||
}, {
|
||||
{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}
|
||||
}};
|
||||
|
||||
void indexVBO(const std::vector<PackedVertexData> &in_vertices, std::vector<glm::u16> &out_indices, std::vector<PackedVertexData> &out_vertices);
|
||||
|
||||
Model::Data::Data(const std::vector<PackedVertexData> &vs, const std::vector<glm::u16> &indices): indices(indices), vertices(vs) { }
|
||||
|
|
|
@ -39,10 +39,20 @@ struct PackedVertexData {
|
|||
};
|
||||
};
|
||||
|
||||
/// Position only buffer
|
||||
class Shape {
|
||||
public:
|
||||
virtual ~Shape() { }
|
||||
|
||||
static const std::vector<glm::vec3> SKY_CUBE;
|
||||
};
|
||||
|
||||
/// Color lines model
|
||||
class Indicator {
|
||||
public:
|
||||
virtual ~Indicator() { }
|
||||
|
||||
static const std::pair<std::vector<glm::vec3>, std::vector<glm::vec4>> CUBE;
|
||||
};
|
||||
|
||||
/// VertexData model with index
|
||||
|
|
|
@ -15,33 +15,7 @@ constexpr auto GL_MAJOR = 4;
|
|||
constexpr auto GL_MINOR = 6;
|
||||
|
||||
Renderer::Renderer(const renderOptions& options):
|
||||
IndicatorCubeBuffer({
|
||||
glm::vec3(0, 0, 0), glm::vec3(0, 0, 1),
|
||||
glm::vec3(0, 0, 1), glm::vec3(0, 1, 1),
|
||||
glm::vec3(0, 1, 1), glm::vec3(0, 1, 0),
|
||||
glm::vec3(0, 1, 0), glm::vec3(0, 0, 0),
|
||||
glm::vec3(1, 0, 0), glm::vec3(1, 0, 1),
|
||||
glm::vec3(1, 0, 1), glm::vec3(1, 1, 1),
|
||||
glm::vec3(1, 1, 1), glm::vec3(1, 1, 0),
|
||||
glm::vec3(1, 1, 0), glm::vec3(1, 0, 0),
|
||||
glm::vec3(0, 0, 0), glm::vec3(1, 0, 0),
|
||||
glm::vec3(0, 0, 1), glm::vec3(1, 0, 1),
|
||||
glm::vec3(0, 1, 1), glm::vec3(1, 1, 1),
|
||||
glm::vec3(0, 1, 0), glm::vec3(1, 1, 0),
|
||||
}, {
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(1, 1, 1, 1), glm::vec4(1, 1, 1, 1),
|
||||
}) {
|
||||
IndicatorCubeBuffer(Indicator::CUBE.first, Indicator::CUBE.second) {
|
||||
glGenVertexArrays(1, &VertexArrayID);
|
||||
glBindVertexArray(VertexArrayID);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace render::gl {
|
||||
|
||||
/// Positions only buffer
|
||||
class Shape final {
|
||||
class Shape final: public render::Shape {
|
||||
public:
|
||||
Shape(const std::vector<glm::vec3>&);
|
||||
~Shape();
|
||||
|
|
|
@ -4,50 +4,7 @@
|
|||
|
||||
using namespace pass;
|
||||
|
||||
const std::vector<glm::vec3> g_cubemap_vertices = {
|
||||
{-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},
|
||||
|
||||
{ 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},
|
||||
|
||||
{-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}
|
||||
};
|
||||
SkyProgram::SkyProgram(): Program(), CubeBuffer(g_cubemap_vertices) {
|
||||
SkyProgram::SkyProgram(): Program(), CubeBuffer(render::gl::Shape::SKY_CUBE) {
|
||||
|
||||
std::vector<std::string> flags;
|
||||
std::vector<Shader*> shaders;
|
||||
|
|
|
@ -32,14 +32,12 @@ CommandCenter::CommandCenter(VkDevice device, const PhysicalDeviceInfo &info, co
|
|||
FATAL("Failed to create texture sampler!");
|
||||
}
|
||||
|
||||
skyCubeBuffer = Shape::Create({
|
||||
{-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},
|
||||
{ 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},
|
||||
{-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}
|
||||
});
|
||||
indicCubeBuffer = Indicator::Create(Indicator::CUBE.first, Indicator::CUBE.second);
|
||||
if (!indicCubeBuffer) {
|
||||
FATAL("Failed to create vertex buffer!");
|
||||
}
|
||||
|
||||
skyCubeBuffer = Shape::Create(Shape::SKY_CUBE);
|
||||
if (!skyCubeBuffer) {
|
||||
FATAL("Failed to create vertex buffer!");
|
||||
}
|
||||
|
@ -99,13 +97,13 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
|||
|
||||
{ // Uniform buffers
|
||||
std::vector<Buffer::requirement> requirements;
|
||||
requirements.resize(framebuffers.size(), Buffer::requirement(sizeof(buffer::vk::UniformBufferObject), Buffer::Usage::UNIFORM));
|
||||
requirements.resize(framebuffers.size(), Buffer::requirement(sizeof(UniformBufferObject), Buffer::Usage::UNIFORM));
|
||||
uniformBuffers.allocate(requirements, true);
|
||||
if (!uniformBuffers) {
|
||||
FATAL("Failed to allocate UBO");
|
||||
}
|
||||
}
|
||||
{ // Voxel Descriptor pool
|
||||
{ // Descriptor pools
|
||||
std::array<VkDescriptorPoolSize, 2> poolSizes{};
|
||||
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
poolSizes[0].descriptorCount = framebuffers.size();
|
||||
|
@ -126,34 +124,38 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
|||
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &skyDescriptorPool) != VK_SUCCESS) {
|
||||
FATAL("Failed to create descriptor pool!");
|
||||
}
|
||||
|
||||
poolInfo.poolSizeCount = 1;
|
||||
poolInfo.pPoolSizes = &poolSizes[0];
|
||||
|
||||
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &indicDescriptorPool) != VK_SUCCESS) {
|
||||
FATAL("Failed to create descriptor pool!");
|
||||
}
|
||||
}
|
||||
{ // Descriptor sets
|
||||
std::vector<VkDescriptorSetLayout> voxLayouts(framebuffers.size(), pipe.getVoxelDescriptorSet());
|
||||
VkDescriptorSetAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
allocInfo.descriptorPool = voxelDescriptorPool;
|
||||
allocInfo.descriptorSetCount = framebuffers.size();
|
||||
allocInfo.pSetLayouts = voxLayouts.data();
|
||||
|
||||
auto allocSets = [&](VkDescriptorPool pool, VkDescriptorSetLayout layout, std::vector<VkDescriptorSet>& out) {
|
||||
std::vector<VkDescriptorSetLayout> layouts(framebuffers.size(), layout);
|
||||
allocInfo.descriptorPool = pool;
|
||||
allocInfo.pSetLayouts = layouts.data();
|
||||
|
||||
voxelDescriptorSets.resize(framebuffers.size());
|
||||
if (vkAllocateDescriptorSets(device, &allocInfo, voxelDescriptorSets.data()) != VK_SUCCESS) {
|
||||
FATAL("Failed to allocate descriptor sets!");
|
||||
}
|
||||
|
||||
std::vector<VkDescriptorSetLayout> skyLayouts(framebuffers.size(), pipe.getSkyDescriptorSet());
|
||||
allocInfo.descriptorPool = skyDescriptorPool;
|
||||
allocInfo.pSetLayouts = skyLayouts.data();
|
||||
|
||||
skyDescriptorSets.resize(framebuffers.size());
|
||||
if (vkAllocateDescriptorSets(device, &allocInfo, skyDescriptorSets.data()) != VK_SUCCESS) {
|
||||
FATAL("Failed to allocate descriptor sets!");
|
||||
}
|
||||
out.resize(framebuffers.size());
|
||||
if (vkAllocateDescriptorSets(device, &allocInfo, out.data()) != VK_SUCCESS) {
|
||||
FATAL("Failed to allocate descriptor sets!");
|
||||
}
|
||||
};
|
||||
allocSets(voxelDescriptorPool, pipe.getVoxelDescriptorSet(), voxelDescriptorSets);
|
||||
allocSets(indicDescriptorPool, pipe.getIndicDescriptorSet(), indicDescriptorSets);
|
||||
allocSets(skyDescriptorPool, pipe.getSkyDescriptorSet(), skyDescriptorSets);
|
||||
|
||||
for (size_t i = 0; i < voxelDescriptorSets.size(); i++) {
|
||||
VkDescriptorBufferInfo bufferInfo{};
|
||||
bufferInfo.buffer = uniformBuffers.at(i);
|
||||
bufferInfo.offset = 0;
|
||||
bufferInfo.range = sizeof(buffer::vk::UniformBufferObject);
|
||||
bufferInfo.range = sizeof(UniformBufferObject);
|
||||
|
||||
std::array<VkWriteDescriptorSet, 2> descriptorWrites{};
|
||||
descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
|
@ -178,6 +180,9 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
|||
descriptorWrites[1].dstSet = skyDescriptorSets[i];
|
||||
descriptorWrites[1].pImageInfo = &skyboxTexture->getDescriptor();
|
||||
vkUpdateDescriptorSets(device, descriptorWrites.size(), descriptorWrites.data(), 0, nullptr);
|
||||
|
||||
descriptorWrites[0].dstSet = indicDescriptorSets[i];
|
||||
vkUpdateDescriptorSets(device, 1, &descriptorWrites[0], 0, nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
|
@ -193,9 +198,6 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
|||
}
|
||||
}
|
||||
|
||||
proj = glm::perspectiveZO(glm::radians(45.0f), extent.width / (float) extent.height, 0.1f, 10.0f);
|
||||
proj[1][1] *= -1;
|
||||
|
||||
freed = false;
|
||||
}
|
||||
void CommandCenter::free() {
|
||||
|
@ -203,6 +205,7 @@ void CommandCenter::free() {
|
|||
vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data());
|
||||
|
||||
vkDestroyDescriptorPool(device, voxelDescriptorPool, ALLOC);
|
||||
vkDestroyDescriptorPool(device, indicDescriptorPool, ALLOC);
|
||||
vkDestroyDescriptorPool(device, skyDescriptorPool, ALLOC);
|
||||
|
||||
colorbuffer.reset();
|
||||
|
@ -219,7 +222,7 @@ void CommandCenter::free() {
|
|||
#include <memory.h>
|
||||
|
||||
void CommandCenter::startRecording(uint32_t idx, VkRenderPass renderPass, VkExtent2D extent, const glm::vec4& clear_color, glm::mat4 view, glm::mat4 proj) {
|
||||
buffer::vk::UniformBufferObject ubo{};
|
||||
UniformBufferObject ubo{};
|
||||
ubo.view = view;
|
||||
ubo.proj = proj;
|
||||
uniformBuffers.write(idx, data_view(&ubo, sizeof(ubo)));
|
||||
|
@ -258,7 +261,7 @@ void CommandCenter::startWorldPass(uint32_t idx, const Subpass &worldPass) {
|
|||
|
||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
|
||||
buffer::vk::ModelPush push{};
|
||||
ModelPush push{};
|
||||
push.model = glm::translate(glm::mat4(1.0f), glm::vec3(98.0f, -2.f, -2.f));
|
||||
push.model = glm::rotate(push.model, time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
vkCmdPushConstants(graphicsBuffers[idx], worldPass.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(push), &push);
|
||||
|
@ -271,7 +274,19 @@ void CommandCenter::recordModel(uint32_t i) {
|
|||
vkCmdDrawIndexed(graphicsBuffers[i], static_cast<uint32_t>(buffer::vk::indices.size()), 1, 0, 0, 0);
|
||||
}
|
||||
void CommandCenter::startEntityPass(uint32_t) { }
|
||||
void CommandCenter::recordIndicator(uint32_t, glm::mat4) { }
|
||||
void CommandCenter::recordIndicator(uint32_t idx, const Subpass& indicPass, glm::mat4 model) {
|
||||
vkCmdNextSubpass(graphicsBuffers[idx], VK_SUBPASS_CONTENTS_INLINE);
|
||||
vkCmdBindPipeline(graphicsBuffers[idx], VK_PIPELINE_BIND_POINT_GRAPHICS, indicPass.pipeline);
|
||||
vkCmdBindDescriptorSets(graphicsBuffers[idx], VK_PIPELINE_BIND_POINT_GRAPHICS, indicPass.layout, 0, 1, &indicDescriptorSets[idx], 0, nullptr);
|
||||
|
||||
ModelPush push{model};
|
||||
vkCmdPushConstants(graphicsBuffers[idx], indicPass.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(push), &push);
|
||||
|
||||
VkBuffer vertexBuffers[] = {indicCubeBuffer->getRef()};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(graphicsBuffers[idx], 0, 1, vertexBuffers, offsets);
|
||||
vkCmdDraw(graphicsBuffers[idx], indicCubeBuffer->size, 1, 0, 0);
|
||||
}
|
||||
void CommandCenter::recordPostprocess(uint32_t idx, const Subpass& skyPass, bool skybox, glm::mat4, glm::mat4) {
|
||||
vkCmdNextSubpass(graphicsBuffers[idx], VK_SUBPASS_CONTENTS_INLINE);
|
||||
if (skybox) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
void startWorldPass(uint32_t idx, const Subpass&);
|
||||
void recordModel(uint32_t idx);
|
||||
void startEntityPass(uint32_t idx);
|
||||
void recordIndicator(uint32_t idx, glm::mat4 model);
|
||||
void recordIndicator(uint32_t idx, const Subpass&, glm::mat4 model);
|
||||
void recordPostprocess(uint32_t idx, const Subpass&, bool skybox, glm::mat4 view, glm::mat4 proj);
|
||||
void submitGraphics(uint32_t, VkSemaphore, VkSemaphore, VkFence);
|
||||
|
||||
|
@ -50,12 +50,15 @@ private:
|
|||
std::unique_ptr<Texture> sampleTexture;
|
||||
std::unique_ptr<ShortIndexedVertexBuffer> modelBuffer;
|
||||
|
||||
VkDescriptorPool indicDescriptorPool;
|
||||
std::vector<VkDescriptorSet> indicDescriptorSets;
|
||||
std::unique_ptr<Indicator> indicCubeBuffer;
|
||||
|
||||
VkDescriptorPool skyDescriptorPool;
|
||||
std::vector<VkDescriptorSet> skyDescriptorSets;
|
||||
std::unique_ptr<TextureCube> skyboxTexture;
|
||||
std::unique_ptr<Shape> skyCubeBuffer;
|
||||
|
||||
glm::mat4 proj;
|
||||
|
||||
bool freed = true;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "../Renderer.hpp"
|
||||
#include "buffer/VertexData.hpp"
|
||||
#include "api/Models.hpp"
|
||||
#include <map>
|
||||
|
||||
#define CONTENT_DIR "content/"
|
||||
#define SHADER_DIR CONTENT_DIR "shaders/"
|
||||
|
@ -67,9 +68,9 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
if (hasSamples) {
|
||||
colorDepthSubpass.pResolveAttachments = &colorAttachmentResolveRef;
|
||||
}
|
||||
std::array<VkSubpassDescription, 2> subpasses = {colorDepthSubpass, colorDepthSubpass};
|
||||
std::array<VkSubpassDescription, 3> subpasses = {colorDepthSubpass, colorDepthSubpass, colorDepthSubpass};
|
||||
|
||||
std::array<VkSubpassDependency, 3> dependencies{};
|
||||
std::array<VkSubpassDependency, 5> dependencies{};
|
||||
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependencies[0].dstSubpass = 0;
|
||||
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
|
@ -93,7 +94,22 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
dependencies[2].dstStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||
dependencies[2].dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
dependencies[2].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
//FIXME: probably needs depth dependency and/or 1->external
|
||||
|
||||
dependencies[3].srcSubpass = 1;
|
||||
dependencies[3].dstSubpass = 2;
|
||||
dependencies[3].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependencies[3].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
dependencies[3].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependencies[3].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
dependencies[3].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
|
||||
dependencies[4].srcSubpass = 1;
|
||||
dependencies[4].dstSubpass = 2;
|
||||
dependencies[4].srcStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||
dependencies[4].srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
dependencies[4].dstStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||
dependencies[4].dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
dependencies[4].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
|
||||
VkRenderPassCreateInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
|
@ -112,6 +128,7 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
FATAL("Failed to create render pass!");
|
||||
}
|
||||
}
|
||||
//MAYBE: use sets (ubo, (samplers, passInfos))
|
||||
{ // Voxel descriptor
|
||||
VkDescriptorSetLayoutBinding samplerLayoutBinding{};
|
||||
samplerLayoutBinding.binding = 1;
|
||||
|
@ -120,7 +137,7 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
samplerLayoutBinding.pImmutableSamplers = nullptr;
|
||||
samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
std::vector<VkDescriptorSetLayoutBinding> bindings = {buffer::vk::UniformBufferObject::getLayoutBinding(), samplerLayoutBinding};
|
||||
std::vector<VkDescriptorSetLayoutBinding> bindings = {UniformBufferObject::getLayoutBinding(), samplerLayoutBinding};
|
||||
VkDescriptorSetLayoutCreateInfo layoutInfo{};
|
||||
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
layoutInfo.bindingCount = bindings.size();
|
||||
|
@ -130,6 +147,17 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
FATAL("Failed to create descriptor set layout!");
|
||||
}
|
||||
}
|
||||
{ // Indicator descriptor
|
||||
VkDescriptorSetLayoutCreateInfo layoutInfo{};
|
||||
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
auto binding = UniformBufferObject::getLayoutBinding();
|
||||
layoutInfo.bindingCount = 1;
|
||||
layoutInfo.pBindings = &binding;
|
||||
|
||||
if (vkCreateDescriptorSetLayout(device, &layoutInfo, ALLOC, &indicDescriptorSet) != VK_SUCCESS) {
|
||||
FATAL("Failed to create descriptor set layout!");
|
||||
}
|
||||
}
|
||||
{ // Sky descriptor
|
||||
VkDescriptorSetLayoutBinding samplerLayoutBinding{};
|
||||
samplerLayoutBinding.binding = 1;
|
||||
|
@ -138,7 +166,7 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
samplerLayoutBinding.pImmutableSamplers = nullptr;
|
||||
samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
std::vector<VkDescriptorSetLayoutBinding> bindings = {buffer::vk::UniformBufferObject::getLayoutBinding(), samplerLayoutBinding};
|
||||
std::vector<VkDescriptorSetLayoutBinding> bindings = {UniformBufferObject::getLayoutBinding(), samplerLayoutBinding};
|
||||
VkDescriptorSetLayoutCreateInfo layoutInfo{};
|
||||
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
layoutInfo.bindingCount = bindings.size();
|
||||
|
@ -149,7 +177,29 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
}
|
||||
}
|
||||
// Common pipeline settings
|
||||
auto setShaders = [&](Subpass &pass, const std::string &shaderName) -> std::vector<VkPipelineShaderStageCreateInfo> {
|
||||
auto makeSpecialization = [](const std::map<uint32_t, data_view>& constants, std::vector<unsigned char>& speData, std::vector<VkSpecializationMapEntry>& speIndex) {
|
||||
//MAYBE: create class
|
||||
VkSpecializationInfo specialization;
|
||||
speData.resize(0);
|
||||
speIndex.resize(0);
|
||||
speData.reserve(constants.size()); //NOTE: Lower bound
|
||||
speIndex.reserve(constants.size());
|
||||
for(auto& constant: constants) {
|
||||
VkSpecializationMapEntry entry;
|
||||
entry.constantID = constant.first;
|
||||
entry.size = constant.second.size;
|
||||
entry.offset = speData.size();
|
||||
speData.resize(speData.size() + entry.size);
|
||||
memcpy(speData.data() + entry.offset, static_cast<const uint8_t*>(constant.second.ptr), entry.size);
|
||||
}
|
||||
specialization.dataSize = speData.size();
|
||||
specialization.pData = speData.data();
|
||||
specialization.mapEntryCount = speIndex.size();
|
||||
specialization.pMapEntries = speIndex.data();
|
||||
return specialization;
|
||||
};
|
||||
auto setShaders = [&](Subpass &pass, const std::string &shaderName, bool geometry = false, const VkSpecializationInfo* specialization = nullptr) -> std::vector<VkPipelineShaderStageCreateInfo>
|
||||
{
|
||||
auto createShaderModule = [&](const data::file_content &code) {
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
|
@ -162,13 +212,14 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
}
|
||||
return shaderModule;
|
||||
};
|
||||
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
|
||||
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
data::file_content vsFile({SHADER_DIR + shaderName + ".vs.spv"});
|
||||
vertShaderStageInfo.module = pass.vsShader = createShaderModule(vsFile);
|
||||
vertShaderStageInfo.pName = "main";
|
||||
vertShaderStageInfo.pSpecializationInfo = nullptr; //TODO: pass constants
|
||||
vertShaderStageInfo.pSpecializationInfo = specialization;
|
||||
|
||||
VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
|
||||
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
|
@ -176,11 +227,21 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
data::file_content fsFile({SHADER_DIR + shaderName + ".fs.spv"});
|
||||
fragShaderStageInfo.module = pass.fsShader = createShaderModule(fsFile);
|
||||
fragShaderStageInfo.pName = "main";
|
||||
fragShaderStageInfo.pSpecializationInfo = nullptr; //TODO: pass constants
|
||||
fragShaderStageInfo.pSpecializationInfo = specialization;
|
||||
|
||||
//TODO: geometry
|
||||
if (geometry) {
|
||||
VkPipelineShaderStageCreateInfo geomShaderStageInfo{};
|
||||
geomShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
geomShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
data::file_content fsFile({SHADER_DIR + shaderName + ".gs.spv"});
|
||||
geomShaderStageInfo.module = pass.fsShader = createShaderModule(fsFile);
|
||||
geomShaderStageInfo.pName = "main";
|
||||
geomShaderStageInfo.pSpecializationInfo = specialization;
|
||||
|
||||
return {vertShaderStageInfo, fragShaderStageInfo};
|
||||
return {vertShaderStageInfo, geomShaderStageInfo, fragShaderStageInfo};
|
||||
} else {
|
||||
return {vertShaderStageInfo, fragShaderStageInfo};
|
||||
}
|
||||
};
|
||||
auto setLayout = [&](Subpass& pass, const std::vector<VkDescriptorSetLayout>& layout, const std::vector<VkPushConstantRange>& push = {}) {
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||
|
@ -288,7 +349,7 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
};*/
|
||||
VkPushConstantRange pushRange{};
|
||||
pushRange.offset = 0;
|
||||
pushRange.size = sizeof(buffer::vk::ModelPush);
|
||||
pushRange.size = sizeof(ModelPush);
|
||||
pushRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
setLayout(worldPass, {voxelDescriptorSet}, {pushRange});
|
||||
auto shaderStages = setShaders(worldPass, "Tris");
|
||||
|
@ -327,12 +388,54 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
FATAL("Failed to create graphics pipeline!");
|
||||
}
|
||||
}
|
||||
{ // Sky pipeline
|
||||
{ // Indicator pipeline
|
||||
VkPushConstantRange pushRange{};
|
||||
pushRange.offset = 0;
|
||||
pushRange.size = sizeof(buffer::vk::SkyPush);
|
||||
pushRange.size = sizeof(ModelPush);
|
||||
pushRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
setLayout(skyPass, {skyDescriptorSet}, {pushRange});
|
||||
setLayout(indicPass, {indicDescriptorSet}, {pushRange});
|
||||
auto shaderStages = setShaders(indicPass, "Color");
|
||||
|
||||
VkPipelineInputAssemblyStateCreateInfo lineInputAssembly{};
|
||||
lineInputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
lineInputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||||
lineInputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
auto bindingDescription = Indicator::getBindingDescription();
|
||||
vertexInputInfo.vertexBindingDescriptionCount = 1;
|
||||
vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
|
||||
auto attributeDescriptions = Indicator::getAttributeDescription();
|
||||
vertexInputInfo.vertexAttributeDescriptionCount = attributeDescriptions.size();
|
||||
vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipelineInfo{};
|
||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
pipelineInfo.stageCount = shaderStages.size();
|
||||
pipelineInfo.pStages = shaderStages.data();
|
||||
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
||||
pipelineInfo.pInputAssemblyState = &lineInputAssembly;
|
||||
pipelineInfo.pViewportState = &viewportState;
|
||||
pipelineInfo.pRasterizationState = &rasterizer;
|
||||
pipelineInfo.pMultisampleState = &multisampling;
|
||||
pipelineInfo.pDepthStencilState = &depthStencil;
|
||||
pipelineInfo.pColorBlendState = &colorBlending;
|
||||
pipelineInfo.pDynamicState = nullptr;
|
||||
|
||||
pipelineInfo.layout = indicPass.layout;
|
||||
pipelineInfo.renderPass = renderPass;
|
||||
pipelineInfo.subpass = 1;
|
||||
|
||||
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
pipelineInfo.basePipelineIndex = -1;
|
||||
|
||||
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, ALLOC, &indicPass.pipeline) != VK_SUCCESS) {
|
||||
FATAL("Failed to create graphics pipeline!");
|
||||
}
|
||||
}
|
||||
{ // Sky pipeline
|
||||
setLayout(skyPass, {skyDescriptorSet}, {});
|
||||
auto shaderStages = setShaders(skyPass, "Sky");
|
||||
|
||||
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
|
||||
|
@ -361,7 +464,7 @@ Pipeline::Pipeline(VkDevice device, const PhysicalDeviceInfo &info, const render
|
|||
|
||||
pipelineInfo.layout = skyPass.layout;
|
||||
pipelineInfo.renderPass = renderPass;
|
||||
pipelineInfo.subpass = 1;
|
||||
pipelineInfo.subpass = 2;
|
||||
|
||||
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
pipelineInfo.basePipelineIndex = -1;
|
||||
|
@ -383,6 +486,7 @@ Pipeline::~Pipeline() {
|
|||
destroy(skyPass);
|
||||
|
||||
vkDestroyDescriptorSetLayout(device, voxelDescriptorSet, ALLOC);
|
||||
vkDestroyDescriptorSetLayout(device, indicDescriptorSet, ALLOC);
|
||||
vkDestroyDescriptorSetLayout(device, skyDescriptorSet, ALLOC);
|
||||
vkDestroyRenderPass(device, renderPass, ALLOC);
|
||||
}
|
|
@ -22,6 +22,8 @@ public:
|
|||
// Voxels (world & entity) passes descriptor set
|
||||
constexpr VkDescriptorSetLayout getVoxelDescriptorSet() const { return voxelDescriptorSet; }
|
||||
constexpr const Subpass& getWorldPass() const { return worldPass; }
|
||||
constexpr VkDescriptorSetLayout getIndicDescriptorSet() const { return indicDescriptorSet; }
|
||||
constexpr const Subpass &getIndicPass() const { return indicPass; }
|
||||
constexpr VkDescriptorSetLayout getSkyDescriptorSet() const { return skyDescriptorSet; }
|
||||
constexpr const Subpass& getSkyPass() const { return skyPass; }
|
||||
|
||||
|
@ -31,9 +33,11 @@ private:
|
|||
VkRenderPass renderPass;
|
||||
|
||||
VkDescriptorSetLayout voxelDescriptorSet;
|
||||
VkDescriptorSetLayout indicDescriptorSet;
|
||||
VkDescriptorSetLayout skyDescriptorSet;
|
||||
|
||||
Subpass worldPass;
|
||||
Subpass indicPass;
|
||||
Subpass skyPass;
|
||||
};
|
||||
}
|
|
@ -442,7 +442,7 @@ std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> Rend
|
|||
size_t Renderer::drawIndicatorCube(glm::mat4 model) {
|
||||
assert(currentImage < swapChain->getImageViews().size());
|
||||
|
||||
commandCenter->recordIndicator(currentImage, model);
|
||||
commandCenter->recordIndicator(currentImage, pipeline->getIndicPass(), model);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,27 @@ std::unique_ptr<Shape> Shape::Create(const std::vector<glm::vec3>& vertices) {
|
|||
return std::unique_ptr<Shape>(new Shape(tmp.ref, std::move(mem), vertices.size()));
|
||||
}
|
||||
|
||||
std::unique_ptr<Indicator> Indicator::Create(const std::vector<glm::vec3>& vert, const std::vector<glm::vec4>& cols) {
|
||||
assert(vert.size() == cols.size());
|
||||
std::vector<Vertex> vertices;
|
||||
vertices.reserve(vert.size());
|
||||
for (size_t i = 0; i < vert.size(); i++) {
|
||||
vertices.push_back(Vertex{vert.at(i), cols.at(i)});
|
||||
}
|
||||
|
||||
vk::Buffer::info tmp;
|
||||
data_view view(vertices);
|
||||
auto mem = createBuffer(view.size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, view, tmp);
|
||||
return std::unique_ptr<Indicator>(new Indicator(vertices.size(), tmp.ref, std::move(mem)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Model> Model::Create(const Data& data) {
|
||||
std::vector<vk::Buffer::info> tmp;
|
||||
data_view vertices(data.vertices);
|
||||
data_view indices(data.indices);
|
||||
auto mem = createBuffers({{vertices.size, Usage::VERTEX, vertices}, {indices.size, Usage::INDEX, indices}}, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, tmp);
|
||||
return std::unique_ptr<Model>(new Model(data.indices.size(), tmp.at(0).ref, tmp.at(1).ref, std::move(mem)));
|
||||
}
|
||||
std::unique_ptr<LodModel> LodModel::Create(const LodData& data) {
|
||||
std::vector<vk::Buffer::info> tmp;
|
||||
data_view vertices(data.first.vertices);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace render::vk {
|
||||
|
||||
/// Positions only buffer
|
||||
class Shape final: public Buffer {
|
||||
class Shape final: public render::Shape, public Buffer {
|
||||
public:
|
||||
const size_t size;
|
||||
|
||||
|
@ -33,36 +33,52 @@ protected:
|
|||
Buffer(ref, std::move(mem)), size(size) { }
|
||||
};
|
||||
|
||||
/*class Indicator final: public render::Indicator {
|
||||
class Indicator final: public render::Indicator, public Buffer {
|
||||
public:
|
||||
Indicator(const std::vector<glm::vec3>&, const std::vector<glm::vec4>&);
|
||||
~Indicator();
|
||||
const size_t size;
|
||||
|
||||
size_t draw();
|
||||
size_t drawInstanced(size_t count);
|
||||
static std::unique_ptr<Indicator> Create(const std::vector<glm::vec3>&, const std::vector<glm::vec4>&);
|
||||
|
||||
private:
|
||||
size_t size;
|
||||
GLuint vertexBufferId;
|
||||
GLuint colorBufferId;
|
||||
struct Vertex {
|
||||
alignas(16) glm::vec3 pos;
|
||||
alignas(16) glm::vec4 color;
|
||||
};
|
||||
|
||||
static VkVertexInputBindingDescription getBindingDescription() {
|
||||
VkVertexInputBindingDescription description{};
|
||||
description.binding = 0;
|
||||
description.stride = sizeof(Vertex);
|
||||
description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
return description;
|
||||
}
|
||||
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescription() {
|
||||
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
|
||||
attributeDescriptions[0].binding = 0;
|
||||
attributeDescriptions[0].location = 0;
|
||||
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[0].offset = offsetof(Vertex, pos);
|
||||
attributeDescriptions[1].binding = 0;
|
||||
attributeDescriptions[1].location = 1;
|
||||
attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
attributeDescriptions[1].offset = offsetof(Vertex, color);
|
||||
return attributeDescriptions;
|
||||
}
|
||||
|
||||
protected:
|
||||
Indicator(size_t size, VkBuffer ref, memory::ptr mem): Buffer(ref, std::move(mem)), size(size) {}
|
||||
|
||||
void enableAttribs();
|
||||
void disableAttribs();
|
||||
};
|
||||
|
||||
class Model final: public render::Model {
|
||||
class Model final: public render::Model, public ShortIndexedVertexBuffer {
|
||||
public:
|
||||
Model(const Data&);
|
||||
~Model();
|
||||
static std::unique_ptr<Model> Create(const Data &);
|
||||
|
||||
size_t draw();
|
||||
size_t drawInstanced(size_t count);
|
||||
protected:
|
||||
Model(size_t size, VkBuffer vertex, VkBuffer index, memory::ptr mem):
|
||||
ShortIndexedVertexBuffer(vertex, index, std::move(mem)), indexSize(size) { }
|
||||
|
||||
private:
|
||||
size_t indexSize;
|
||||
GLuint vertexBufferId;
|
||||
GLuint indexBufferId;
|
||||
};*/
|
||||
};
|
||||
class LodModel final: public render::LodModel, public ShortIndexedVertexBuffer {
|
||||
public:
|
||||
static std::unique_ptr<LodModel> Create(const LodData&);
|
||||
|
@ -79,4 +95,23 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
struct UniformBufferObject {
|
||||
alignas(16) glm::mat4 view;
|
||||
alignas(16) glm::mat4 proj;
|
||||
|
||||
static VkDescriptorSetLayoutBinding getLayoutBinding() {
|
||||
VkDescriptorSetLayoutBinding uboLayoutBinding{};
|
||||
uboLayoutBinding.binding = 0;
|
||||
uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
uboLayoutBinding.descriptorCount = 1;
|
||||
uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
uboLayoutBinding.pImmutableSamplers = nullptr;
|
||||
return uboLayoutBinding;
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelPush {
|
||||
alignas(16) glm::mat4 model;
|
||||
};
|
||||
|
||||
}
|
|
@ -53,28 +53,4 @@ const std::vector<uint16_t> indices = {
|
|||
4, 5, 6, 6, 7, 4
|
||||
};
|
||||
|
||||
struct UniformBufferObject {
|
||||
alignas(16) glm::mat4 view;
|
||||
alignas(16) glm::mat4 proj;
|
||||
|
||||
static VkDescriptorSetLayoutBinding getLayoutBinding() {
|
||||
VkDescriptorSetLayoutBinding uboLayoutBinding{};
|
||||
uboLayoutBinding.binding = 0;
|
||||
uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
uboLayoutBinding.descriptorCount = 1;
|
||||
uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
uboLayoutBinding.pImmutableSamplers = nullptr;
|
||||
return uboLayoutBinding;
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelPush {
|
||||
alignas(16) glm::mat4 model;
|
||||
};
|
||||
|
||||
struct SkyPush {
|
||||
alignas(16) glm::mat4 view;
|
||||
alignas(16) glm::mat4 proj;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue