Fix some issues found in first-try
This commit is contained in:
parent
0066722dab
commit
0b9a3e1c69
@ -11,7 +11,6 @@ layout(location = 2) in float size;
|
|||||||
layout(location = 3) in vec2 Texcoord;
|
layout(location = 3) in vec2 Texcoord;
|
||||||
layout(location = 4) in vec2 quadcorner;
|
layout(location = 4) in vec2 quadcorner;
|
||||||
|
|
||||||
layout(location = 5) in vec3 rotationvec;
|
|
||||||
layout(location = 6) in float anglespeed;
|
layout(location = 6) in float anglespeed;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -22,7 +21,6 @@ in float size;
|
|||||||
in vec2 Texcoord;
|
in vec2 Texcoord;
|
||||||
in vec2 quadcorner;
|
in vec2 quadcorner;
|
||||||
|
|
||||||
in vec3 rotationvec;
|
|
||||||
float anglespeed;
|
float anglespeed;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -33,6 +31,7 @@ void main(void)
|
|||||||
{
|
{
|
||||||
if (size == 0.0)
|
if (size == 0.0)
|
||||||
{
|
{
|
||||||
|
gl_Position = vec4(0.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tc = Texcoord;
|
tc = Texcoord;
|
||||||
@ -43,41 +42,13 @@ void main(void)
|
|||||||
vec4 viewpos = vec4(0.);
|
vec4 viewpos = vec4(0.);
|
||||||
if (flips == 1)
|
if (flips == 1)
|
||||||
{
|
{
|
||||||
// from http://jeux.developpez.com/faq/math
|
|
||||||
float angle = lifetime * anglespeed;
|
float angle = lifetime * anglespeed;
|
||||||
float sin_a = sin(angle / 2.);
|
float sin_a = sin(mod(angle / 2.0, 6.283185307179586));
|
||||||
float cos_a = cos(angle / 2.);
|
float cos_a = cos(mod(angle / 2.0, 6.283185307179586));
|
||||||
|
vec4 quat = normalize(vec4(vec3(0.0, 1.0, 0.0) * sin_a, cos_a));
|
||||||
vec4 quaternion = normalize(vec4(rotationvec * sin_a, cos_a));
|
|
||||||
float xx = quaternion.x * quaternion.x;
|
|
||||||
float xy = quaternion.x * quaternion.y;
|
|
||||||
float xz = quaternion.x * quaternion.z;
|
|
||||||
float xw = quaternion.x * quaternion.w;
|
|
||||||
float yy = quaternion.y * quaternion.y;
|
|
||||||
float yz = quaternion.y * quaternion.z;
|
|
||||||
float yw = quaternion.y * quaternion.w;
|
|
||||||
float zz = quaternion.z * quaternion.z;
|
|
||||||
float zw = quaternion.z * quaternion.w;
|
|
||||||
|
|
||||||
vec4 col1 = vec4(
|
|
||||||
1. - 2. * ( yy + zz ),
|
|
||||||
2. * ( xy + zw ),
|
|
||||||
2. * ( xz - yw ),
|
|
||||||
0.);
|
|
||||||
vec4 col2 = vec4(
|
|
||||||
2. * ( xy - zw ),
|
|
||||||
1. - 2. * ( xx + zz ),
|
|
||||||
2. * ( yz + xw ),
|
|
||||||
0.);
|
|
||||||
vec4 col3 = vec4(
|
|
||||||
2. * ( xz + yw ),
|
|
||||||
2. * ( yz - xw ),
|
|
||||||
1. - 2. * ( xx + yy ),
|
|
||||||
0.);
|
|
||||||
vec4 col4 = vec4(0., 0., 0., 1.);
|
|
||||||
mat4 rotationMatrix = mat4(col1, col2, col3, col4);
|
|
||||||
vec3 newquadcorner = size * vec3(quadcorner, 0.);
|
vec3 newquadcorner = size * vec3(quadcorner, 0.);
|
||||||
newquadcorner = (rotationMatrix * vec4(newquadcorner, 0.)).xyz;
|
newquadcorner = newquadcorner + 2.0 * cross(cross(newquadcorner,
|
||||||
|
quat.xyz) + quat.w * newquadcorner, quat.xyz);
|
||||||
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
|
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -11,7 +11,6 @@ layout(location = 2) in float size;
|
|||||||
layout(location = 3) in vec2 Texcoord;
|
layout(location = 3) in vec2 Texcoord;
|
||||||
layout(location = 4) in vec2 quadcorner;
|
layout(location = 4) in vec2 quadcorner;
|
||||||
|
|
||||||
layout(location = 5) in vec3 rotationvec;
|
|
||||||
layout(location = 6) in float anglespeed;
|
layout(location = 6) in float anglespeed;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -22,11 +21,9 @@ in float size;
|
|||||||
in vec2 Texcoord;
|
in vec2 Texcoord;
|
||||||
in vec2 quadcorner;
|
in vec2 quadcorner;
|
||||||
|
|
||||||
in vec3 rotationvec;
|
|
||||||
float anglespeed;
|
float anglespeed;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out float lf;
|
|
||||||
out vec2 tc;
|
out vec2 tc;
|
||||||
out vec4 pc;
|
out vec4 pc;
|
||||||
|
|
||||||
@ -34,52 +31,25 @@ void main(void)
|
|||||||
{
|
{
|
||||||
if (size == 0.0)
|
if (size == 0.0)
|
||||||
{
|
{
|
||||||
|
gl_Position = vec4(0.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tc = Texcoord;
|
tc = Texcoord;
|
||||||
lf = lifetime;
|
pc = vec4(vec3(color_from + (color_to - color_from) * lifetime), 1.0) *
|
||||||
pc = vec4(vec3(color_from + (color_to - color_from) * lf), 1.0) * smoothstep(1., 0.8, lf);
|
smoothstep(1., 0.8, lifetime);
|
||||||
#if !defined(sRGB_Framebuffer_Usable) && !defined(Advanced_Lighting_Enabled)
|
#if !defined(sRGB_Framebuffer_Usable) && !defined(Advanced_Lighting_Enabled)
|
||||||
pc.rgb = pow(pc.rgb, vec3(1. / 2.2));
|
pc.rgb = pow(pc.rgb, vec3(1. / 2.2));
|
||||||
#endif
|
#endif
|
||||||
vec4 viewpos = vec4(0.);
|
vec4 viewpos = vec4(0.);
|
||||||
if (flips == 1)
|
if (flips == 1)
|
||||||
{
|
{
|
||||||
// from http://jeux.developpez.com/faq/math
|
|
||||||
float angle = lifetime * anglespeed;
|
float angle = lifetime * anglespeed;
|
||||||
float sin_a = sin(angle / 2.);
|
float sin_a = sin(mod(angle / 2.0, 6.283185307179586));
|
||||||
float cos_a = cos(angle / 2.);
|
float cos_a = cos(mod(angle / 2.0, 6.283185307179586));
|
||||||
|
vec4 quat = normalize(vec4(vec3(0.0, 1.0, 0.0) * sin_a, cos_a));
|
||||||
vec4 quaternion = normalize(vec4(rotationvec * sin_a, cos_a));
|
|
||||||
float xx = quaternion.x * quaternion.x;
|
|
||||||
float xy = quaternion.x * quaternion.y;
|
|
||||||
float xz = quaternion.x * quaternion.z;
|
|
||||||
float xw = quaternion.x * quaternion.w;
|
|
||||||
float yy = quaternion.y * quaternion.y;
|
|
||||||
float yz = quaternion.y * quaternion.z;
|
|
||||||
float yw = quaternion.y * quaternion.w;
|
|
||||||
float zz = quaternion.z * quaternion.z;
|
|
||||||
float zw = quaternion.z * quaternion.w;
|
|
||||||
|
|
||||||
vec4 col1 = vec4(
|
|
||||||
1. - 2. * ( yy + zz ),
|
|
||||||
2. * ( xy + zw ),
|
|
||||||
2. * ( xz - yw ),
|
|
||||||
0.);
|
|
||||||
vec4 col2 = vec4(
|
|
||||||
2. * ( xy - zw ),
|
|
||||||
1. - 2. * ( xx + zz ),
|
|
||||||
2. * ( yz + xw ),
|
|
||||||
0.);
|
|
||||||
vec4 col3 = vec4(
|
|
||||||
2. * ( xz + yw ),
|
|
||||||
2. * ( yz - xw ),
|
|
||||||
1. - 2. * ( xx + yy ),
|
|
||||||
0.);
|
|
||||||
vec4 col4 = vec4(0., 0., 0., 1.);
|
|
||||||
mat4 rotationMatrix = mat4(col1, col2, col3, col4);
|
|
||||||
vec3 newquadcorner = size * vec3(quadcorner, 0.);
|
vec3 newquadcorner = size * vec3(quadcorner, 0.);
|
||||||
newquadcorner = (rotationMatrix * vec4(newquadcorner, 0.)).xyz;
|
newquadcorner = newquadcorner + 2.0 * cross(cross(newquadcorner,
|
||||||
|
quat.xyz) + quat.w * newquadcorner, quat.xyz);
|
||||||
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
|
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Modify this file to change the last-modified date when you add/remove a file.
|
# Modify this file to change the last-modified date when you add/remove a file.
|
||||||
# This will then trigger a new cmake run automatically.
|
# This will then trigger a new cmake run automatically.
|
||||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||||
|
@ -72,7 +72,6 @@ CPUParticleManager::~CPUParticleManager()
|
|||||||
glDeleteVertexArrays(1, &std::get<0>(p.second));
|
glDeleteVertexArrays(1, &std::get<0>(p.second));
|
||||||
glDeleteBuffers(1, &std::get<1>(p.second));
|
glDeleteBuffers(1, &std::get<1>(p.second));
|
||||||
}
|
}
|
||||||
STKParticle::destroyFlipsBuffer();
|
|
||||||
} // ~CPUParticleManager
|
} // ~CPUParticleManager
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -182,11 +181,8 @@ void CPUParticleManager::uploadAll()
|
|||||||
if (flips)
|
if (flips)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, STKParticle::getFlipsBuffer());
|
glBindBuffer(GL_ARRAY_BUFFER, STKParticle::getFlipsBuffer());
|
||||||
glEnableVertexAttribArray(5);
|
|
||||||
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, 16, 0);
|
|
||||||
glVertexAttribDivisorARB(5, 1);
|
|
||||||
glEnableVertexAttribArray(6);
|
glEnableVertexAttribArray(6);
|
||||||
glVertexAttribPointer(6, 1, GL_FLOAT, GL_FALSE, 16, (void*)12);
|
glVertexAttribPointer(6, 1, GL_FLOAT, GL_FALSE, 4, 0);
|
||||||
glVertexAttribDivisorARB(6, 1);
|
glVertexAttribDivisorARB(6, 1);
|
||||||
}
|
}
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
@ -249,7 +245,8 @@ void CPUParticleManager::drawAll()
|
|||||||
if (cur_mat->getShaderType() == Material::SHADERTYPE_ADDITIVE)
|
if (cur_mat->getShaderType() == Material::SHADERTYPE_ADDITIVE)
|
||||||
{
|
{
|
||||||
ParticleRenderer::getInstance()->use();
|
ParticleRenderer::getInstance()->use();
|
||||||
glDisable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@ -260,7 +257,8 @@ void CPUParticleManager::drawAll()
|
|||||||
->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND)
|
->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND)
|
||||||
{
|
{
|
||||||
ParticleRenderer::getInstance()->use();
|
ParticleRenderer::getInstance()->use();
|
||||||
glDisable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
@ -607,6 +607,7 @@ DrawCalls::DrawCalls()
|
|||||||
DrawCalls::~DrawCalls()
|
DrawCalls::~DrawCalls()
|
||||||
{
|
{
|
||||||
CPUParticleManager::kill();
|
CPUParticleManager::kill();
|
||||||
|
STKParticle::destroyFlipsBuffer();
|
||||||
#if !defined(USE_GLES2)
|
#if !defined(USE_GLES2)
|
||||||
delete m_solid_cmd_buffer;
|
delete m_solid_cmd_buffer;
|
||||||
delete m_shadow_cmd_buffer;
|
delete m_shadow_cmd_buffer;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "../../lib/irrlicht/source/Irrlicht/os.h"
|
#include "../../lib/irrlicht/source/Irrlicht/os.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::vector<Vec3> STKParticle::m_flips_data;
|
std::vector<float> STKParticle::m_flips_data;
|
||||||
GLuint STKParticle::m_flips_buffer = 0;
|
GLuint STKParticle::m_flips_buffer = 0;
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
scene::IParticleSystemSceneNode* STKParticle::addParticleNode(
|
scene::IParticleSystemSceneNode* STKParticle::addParticleNode(
|
||||||
@ -353,11 +353,14 @@ void STKParticle::stimulateHeightMap(float dt, unsigned int active_count,
|
|||||||
if (m_flips || new_size != 0.0f)
|
if (m_flips || new_size != 0.0f)
|
||||||
{
|
{
|
||||||
if (new_size != 0.0f)
|
if (new_size != 0.0f)
|
||||||
|
{
|
||||||
|
Buffer->BoundingBox.addInternalPoint(new_particle_position);
|
||||||
|
}
|
||||||
|
if (out != NULL)
|
||||||
{
|
{
|
||||||
out->emplace_back(new_particle_position, new_lifetime,
|
out->emplace_back(new_particle_position, new_lifetime,
|
||||||
new_size);
|
new_size);
|
||||||
}
|
}
|
||||||
Buffer->BoundingBox.addInternalPoint(new_particle_position);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // stimulateHeightMap
|
} // stimulateHeightMap
|
||||||
@ -423,7 +426,8 @@ void STKParticle::stimulateNormal(float dt, unsigned int active_count,
|
|||||||
// artifacts when the framerate is low, and a more accurate
|
// artifacts when the framerate is low, and a more accurate
|
||||||
// formula would need more complex computations.
|
// formula would need more complex computations.
|
||||||
|
|
||||||
new_particle_position = updated_position + dt_from_last_frame * updated_direction;
|
new_particle_position = updated_position + dt_from_last_frame *
|
||||||
|
updated_direction;
|
||||||
new_particle_direction = updated_direction;
|
new_particle_direction = updated_direction;
|
||||||
|
|
||||||
new_lifetime = glslFract(updated_lifetime);
|
new_lifetime = glslFract(updated_lifetime);
|
||||||
@ -454,11 +458,14 @@ void STKParticle::stimulateNormal(float dt, unsigned int active_count,
|
|||||||
if (m_flips || new_size != 0.0f)
|
if (m_flips || new_size != 0.0f)
|
||||||
{
|
{
|
||||||
if (new_size != 0.0f)
|
if (new_size != 0.0f)
|
||||||
|
{
|
||||||
|
Buffer->BoundingBox.addInternalPoint(new_particle_position);
|
||||||
|
}
|
||||||
|
if (out != NULL)
|
||||||
{
|
{
|
||||||
out->emplace_back(new_particle_position, new_lifetime,
|
out->emplace_back(new_particle_position, new_lifetime,
|
||||||
new_size);
|
new_size);
|
||||||
}
|
}
|
||||||
Buffer->BoundingBox.addInternalPoint(new_particle_position);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // stimulateNormal
|
} // stimulateNormal
|
||||||
@ -475,13 +482,13 @@ void STKParticle::updateFlips(unsigned maximum_particle_count)
|
|||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
// 3 half rotation during lifetime at max
|
// 3 half rotation during lifetime at max
|
||||||
m_flips_data.emplace_back(0.0f, 1.0f, 0.0f,
|
m_flips_data.push_back(3.14f * 3.0f * (2.0f * os::Randomizer::frand()
|
||||||
3.14f * 3.0f * (2.0f * os::Randomizer::frand() - 1.0f));
|
- 1.0f));
|
||||||
}
|
}
|
||||||
if (updated)
|
if (updated)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_flips_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, m_flips_buffer);
|
||||||
glBufferData(GL_ARRAY_BUFFER, m_flips_data.size() * 16,
|
glBufferData(GL_ARRAY_BUFFER, m_flips_data.size() * 4,
|
||||||
m_flips_data.data(), GL_STATIC_DRAW);
|
m_flips_data.data(), GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#define HEADER_STK_PARTICLE_HPP
|
#define HEADER_STK_PARTICLE_HPP
|
||||||
|
|
||||||
#include "graphics/gl_headers.hpp"
|
#include "graphics/gl_headers.hpp"
|
||||||
#include "utils/vec3.hpp"
|
|
||||||
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
|
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -72,7 +71,7 @@ private:
|
|||||||
/** Maximum count of particles. */
|
/** Maximum count of particles. */
|
||||||
unsigned m_max_count;
|
unsigned m_max_count;
|
||||||
|
|
||||||
static std::vector<Vec3> m_flips_data;
|
static std::vector<float> m_flips_data;
|
||||||
|
|
||||||
static GLuint m_flips_buffer;
|
static GLuint m_flips_buffer;
|
||||||
|
|
||||||
@ -151,8 +150,11 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
static void destroyFlipsBuffer()
|
static void destroyFlipsBuffer()
|
||||||
{
|
{
|
||||||
glDeleteBuffers(1, &m_flips_buffer);
|
if (m_flips_buffer != 0)
|
||||||
m_flips_buffer = 0;
|
{
|
||||||
|
glDeleteBuffers(1, &m_flips_buffer);
|
||||||
|
m_flips_buffer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
static GLuint getFlipsBuffer() { return m_flips_buffer; }
|
static GLuint getFlipsBuffer() { return m_flips_buffer; }
|
||||||
|
Loading…
Reference in New Issue
Block a user