Skip to content
Snippets Groups Projects
Commit cecf848f authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#69] Make particles camera facing, to avoid invisible particles from certain angles

parent 12ab54b3
No related branches found
No related tags found
1 merge request!56Resolve "Partikelsystem"
......@@ -38,8 +38,15 @@ namespace vkcv::camera {
m_view = view;
}
const glm::mat4 y_correction(
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
const glm::mat4& Camera::getProjection() const {
return m_projection;
return y_correction * m_projection;
}
void Camera::setProjection(const glm::mat4& projection) {
......@@ -47,13 +54,6 @@ namespace vkcv::camera {
}
glm::mat4 Camera::getMVP() const {
const glm::mat4 y_correction (
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
return y_correction * m_projection * m_view;
}
......
......@@ -19,7 +19,8 @@ layout(std430, binding = 2) coherent buffer buffer_inParticle
};
layout( push_constant ) uniform constants{
mat4 mvp;
mat4 view;
mat4 projection;
};
layout(location = 1) out vec3 passVelocity;
......@@ -30,6 +31,10 @@ void main()
int id = gl_InstanceIndex;
passVelocity = inParticle[id].velocity;
passlifeTime = inParticle[id].lifeTime;
vec3 moved_particle = particle + inParticle[id].position;
gl_Position = mvp * vec4(moved_particle, 1.0);
// particle position in view space
vec4 positionView = view * vec4(inParticle[id].position, 1);
// by adding the triangle position in view space the mesh is always camera facing
positionView.xyz += particle;
// multiply with projection matrix for final position
gl_Position = projection * positionView;
}
\ No newline at end of file
No preview for this file type
......@@ -224,9 +224,11 @@ int main(int argc, const char **argv) {
// particleSystem.updateParticles(deltatime);
cameraManager.update(deltatime);
std::vector<glm::mat4> mvp;
mvp.clear();
mvp.push_back( cameraManager.getActiveCamera().getMVP());
// split view and projection to allow for easy billboarding in shader
glm::mat4 renderingMatrices[2];
renderingMatrices[0] = cameraManager.getActiveCamera().getView();
renderingMatrices[1] = cameraManager.getActiveCamera().getProjection();
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
float random = rdm(rdmEngine);
......@@ -242,7 +244,7 @@ int main(int argc, const char **argv) {
core.recordBufferMemoryBarrier(cmdStream, particleBuffer.getHandle());
vkcv::PushConstantData pushConstantDataDraw((void *) mvp.data(), sizeof(glm::mat4));
vkcv::PushConstantData pushConstantDataDraw((void *) &renderingMatrices[0], 2 * sizeof(glm::mat4));
core.recordDrawcallsToCmdStream(
cmdStream,
particlePass,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment