fixes
This commit is contained in:
@@ -21,11 +21,6 @@
|
||||
#include "Base/EngineConfiguration.hpp"
|
||||
#include "Controller/FreeCamCameraController.hpp"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "cert-msc50-cpp"
|
||||
#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions"
|
||||
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
using namespace Scene;
|
||||
@@ -38,8 +33,7 @@ namespace OpenVulkano
|
||||
|
||||
struct BillboardControlBlock
|
||||
{
|
||||
glm::vec2 quadSize;
|
||||
glm::vec2 windowSize;
|
||||
Math::Vector2f quadSize;
|
||||
bool isFixedSize;
|
||||
};
|
||||
|
||||
@@ -56,14 +50,16 @@ namespace OpenVulkano
|
||||
|
||||
m_quadBillboardShader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/billboardFromSinglePoint");
|
||||
m_quadBillboardShader.AddShaderProgram(OpenVulkano::ShaderProgramType::GEOMETRY, "Shader/billboardFromSinglePoint");
|
||||
m_quadBillboardShader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/billboard");
|
||||
m_quadBillboardShader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basicTexture");
|
||||
m_quadBillboardShader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription());
|
||||
m_quadBillboardShader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
|
||||
m_quadBillboardShader.AddDescriptorSetLayoutBinding(UniformBuffer::DESCRIPTOR_SET_LAYOUT_BINDING);
|
||||
m_quadBillboardShader.topology = Topology::POINT_LIST;
|
||||
|
||||
m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/billboard");
|
||||
m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/billboard");
|
||||
m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basic");
|
||||
m_shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription());
|
||||
m_shader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
|
||||
m_shader.AddDescriptorSetLayoutBinding(UniformBuffer::DESCRIPTOR_SET_LAYOUT_BINDING);
|
||||
m_shader.cullMode = CullMode::NONE;
|
||||
|
||||
@@ -72,12 +68,13 @@ namespace OpenVulkano
|
||||
constexpr int cntDrawables = quadsCnt + otherCnt;
|
||||
|
||||
m_bbContolBlock.quadSize = { 100.f, 100.f };
|
||||
m_bbContolBlock.windowSize = { 0, 0 }; // will be initialized on first frame
|
||||
m_bbContolBlock.isFixedSize = false;
|
||||
m_uniBuffer.Init(sizeof(BillboardControlBlock), &m_bbContolBlock);
|
||||
m_uniBuffer.setId = 3;
|
||||
m_drawablesPool.resize(cntDrawables);
|
||||
m_nodesPool.resize(cntDrawables);
|
||||
m_geo.reserve(cntDrawables);
|
||||
m_texturedMat.texture = &Texture::PLACEHOLDER;
|
||||
|
||||
for (uint32_t i = 0; i < cntDrawables; i++)
|
||||
{
|
||||
@@ -88,9 +85,12 @@ namespace OpenVulkano
|
||||
geo = new Geometry();
|
||||
geo->Init(1, 0);
|
||||
geo->vertices[0].position = glm::vec3(1 + i, i, 0);
|
||||
geo->vertices[0].color = glm::vec4(1, 0, 0, 1);
|
||||
if (i >= 1 && i <= 3)
|
||||
geo->vertices[0].color = glm::vec4(1, 1, 1, 1);
|
||||
else
|
||||
geo->vertices[0].color = glm::vec4(1, 0, 0, 1);
|
||||
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(-5 + std::rand() % 5, -5 + std::rand() % 5, std::rand() % 5)));
|
||||
m_drawablesPool[i].Init(&m_quadBillboardShader, geo, &m_mat, &m_uniBuffer);
|
||||
m_drawablesPool[i].Init(&m_quadBillboardShader, geo, &m_texturedMat, &m_uniBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -101,7 +101,6 @@ namespace OpenVulkano
|
||||
m_geo.push_back(geo);
|
||||
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);
|
||||
m_nodesPool[i].AddDrawable(&m_drawablesPool[i]);
|
||||
m_nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always);
|
||||
}
|
||||
|
||||
GetGraphicsAppManager()->GetRenderer()->SetScene(&m_scene);
|
||||
@@ -119,14 +118,6 @@ namespace OpenVulkano
|
||||
|
||||
void Tick() override
|
||||
{
|
||||
static bool firstFrame = true;
|
||||
if (firstFrame)
|
||||
{
|
||||
glm::vec2 sz = GetGraphicsAppManager()->GetWindow()->GetSize();
|
||||
m_bbContolBlock.windowSize = sz;
|
||||
m_uniBuffer.updated = true;
|
||||
firstFrame = false;
|
||||
}
|
||||
m_camController.Tick();
|
||||
}
|
||||
|
||||
@@ -145,6 +136,7 @@ namespace OpenVulkano
|
||||
UniformBuffer m_uniBuffer;
|
||||
OpenVulkano::FreeCamCameraController m_camController;
|
||||
Material m_mat;
|
||||
Material m_texturedMat;
|
||||
Shader m_shader;
|
||||
Shader m_quadBillboardShader;
|
||||
std::vector<SimpleDrawable> m_drawablesPool;
|
||||
|
||||
@@ -16,18 +16,19 @@ namespace OpenVulkano::Scene
|
||||
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER, 1, ShaderProgramType::ALL_GRAPHICS };
|
||||
|
||||
DescriptorSetLayoutBinding binding;
|
||||
uint32_t setId = 2;
|
||||
uint32_t setId;
|
||||
ICloseable* renderBuffer = nullptr;
|
||||
size_t size = 0;
|
||||
const void* data = nullptr;
|
||||
UpdateFrequency updateFrequency = UpdateFrequency::Never;
|
||||
bool updated = true;
|
||||
|
||||
void Init(size_t size, const void* data, const DescriptorSetLayoutBinding& binding = DESCRIPTOR_SET_LAYOUT_BINDING)
|
||||
void Init(size_t size, const void* data, uint32_t setId = 2, const DescriptorSetLayoutBinding& binding = DESCRIPTOR_SET_LAYOUT_BINDING)
|
||||
{
|
||||
this->size = size;
|
||||
this->data = data;
|
||||
this->binding = binding;
|
||||
this->setId = setId;
|
||||
}
|
||||
|
||||
UpdateFrequency GetUpdateFrequency() const { return updateFrequency; }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
layout(location = 0) in vec4 color;
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
void main()
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec4 color;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = color;
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
#version 450
|
||||
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 4) in vec3 textureCoordinates;
|
||||
layout(location = 5) in vec4 color;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
layout(location = 1) out vec2 outTexture;
|
||||
|
||||
layout(set = 0, binding = 0) uniform NodeData
|
||||
{
|
||||
@@ -13,15 +16,14 @@ layout(set = 0, binding = 0) uniform NodeData
|
||||
layout(set = 1, binding = 0) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
} cam;
|
||||
|
||||
layout(set = 2, binding = 0) uniform BillboardData
|
||||
layout(set = 3, binding = 0) uniform BillboardData
|
||||
{
|
||||
vec2 size;
|
||||
vec2 windowSize;
|
||||
bool isFixedSize;
|
||||
} billboardInfo;
|
||||
|
||||
@@ -46,10 +48,11 @@ void main() {
|
||||
}
|
||||
else
|
||||
{
|
||||
vec4 billboardPos = vec4(0, 0, 0, 1);
|
||||
vec4 billboardPos = vec4(0.5, 0.5, 0.5, 1);
|
||||
vec4 viewPos = cam.view * node.world * billboardPos;
|
||||
float dist = -viewPos.z;
|
||||
gl_Position = cam.projection * (viewPos + vec4(pos.xy*dist*0.2,0,0));
|
||||
}
|
||||
outColor = color;
|
||||
outTexture = textureCoordinates.xy;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,27 @@ layout(set = 0, binding = 0) uniform NodeData
|
||||
layout(set = 1, binding = 0) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
float nearPlane;
|
||||
float farPlane;
|
||||
float width;
|
||||
float height;
|
||||
float fov;
|
||||
float aspect;
|
||||
float scaleFactor;
|
||||
float pixelScaleFactor;
|
||||
} cam;
|
||||
|
||||
layout(set = 2, binding = 0) uniform BillboardData
|
||||
layout(set = 3, binding = 0) uniform BillboardData
|
||||
{
|
||||
vec2 size;
|
||||
vec2 windowSize;
|
||||
bool isFixedSize;
|
||||
} billboardInfo;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
layout(location = 1) out vec2 tex;
|
||||
|
||||
layout(location = 0) in VS_OUT {
|
||||
vec4 color;
|
||||
@@ -32,7 +40,6 @@ layout(location = 0) in VS_OUT {
|
||||
void main() {
|
||||
// The desired point for the billboard
|
||||
vec3 pos = gl_in[0].gl_Position.xyz;
|
||||
|
||||
if(!billboardInfo.isFixedSize)
|
||||
{
|
||||
vec3 cameraRight = normalize(vec3(cam.view[0][0], cam.view[1][0], cam.view[2][0]));
|
||||
@@ -43,12 +50,19 @@ void main() {
|
||||
vec2(-0.5, -0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
};
|
||||
const vec2 texCoords[4] = {
|
||||
vec2(1, 0),
|
||||
vec2(1, 1),
|
||||
vec2(0, 0),
|
||||
vec2(0, 1)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
vec2 scaledSize = billboardInfo.size / length(billboardInfo.size);
|
||||
gl_Position = cam.viewProjection * vec4(pos + cameraRight * offsets[i].x * scaledSize.x + cameraUp * offsets[i].y * scaledSize.y, 1.0);
|
||||
color = gs_in[0].color;
|
||||
tex = texCoords[i].xy;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
@@ -61,13 +75,20 @@ void main() {
|
||||
vec2(0.5, -0.5),
|
||||
vec2(0.5, 0.5)
|
||||
};
|
||||
const vec2 texCoords[4] = {
|
||||
vec2(0, 0),
|
||||
vec2(0, 1),
|
||||
vec2(1, 0),
|
||||
vec2(1, 1)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
gl_Position = cam.viewProjection * vec4(pos, 1);
|
||||
gl_Position /= gl_Position.w;
|
||||
gl_Position.xy += offsets[i] * vec2(billboardInfo.size.x/billboardInfo.windowSize.x, billboardInfo.size.x/billboardInfo.windowSize.y);
|
||||
gl_Position.xy += offsets[i] * vec2(billboardInfo.size.x/cam.width, billboardInfo.size.x/cam.height);
|
||||
color = gs_in[0].color;
|
||||
tex = texCoords[i].xy;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#version 450
|
||||
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 5) in vec4 color;
|
||||
|
||||
layout(location = 0) out VS_OUT {
|
||||
@@ -13,21 +14,6 @@ layout(set = 0, binding = 0) uniform NodeData
|
||||
mat4 world;
|
||||
} node;
|
||||
|
||||
layout(set = 1, binding = 0) uniform CameraData
|
||||
{
|
||||
mat4 viewProjection;
|
||||
mat4 view;
|
||||
mat4 projection;
|
||||
vec4 camPos;
|
||||
} cam;
|
||||
|
||||
layout(set = 2, binding = 0) uniform BillboardData
|
||||
{
|
||||
vec2 size;
|
||||
vec2 windowSize;
|
||||
bool isFixedSize;
|
||||
} billboardInfo;
|
||||
|
||||
void main() {
|
||||
// single point
|
||||
gl_Position = node.world * vec4(pos, 1);
|
||||
|
||||
Reference in New Issue
Block a user