Skip to content
Snippets Groups Projects
Commit 711d2b88 authored by elom0n's avatar elom0n
Browse files

Merge branch 'changes' into ela_changes

parents 593136e2 59828b4a
No related branches found
No related tags found
1 merge request!106Created initial firework project
...@@ -148,7 +148,7 @@ void main() { ...@@ -148,7 +148,7 @@ void main() {
{ {
const uint tid = atomicAdd(trailIndex, 1) % trails.length(); const uint tid = atomicAdd(trailIndex, 1) % trails.length();
const uint trailLen = 16; // 64 + int(randomData[(tid + id) % randomData.length()] * 32); const uint trailLen = 96 + int(randomData[(tid + id) % randomData.length()] * 32);
const uint startIndex = atomicAdd(pointIndex, trailLen) % points.length(); const uint startIndex = atomicAdd(pointIndex, trailLen) % points.length();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "physics.inc" #include "physics.inc"
layout(location = 0) in vec3 passPos; layout(location = 0) in vec3 passPos;
layout(location = 1) in vec3 passView; layout(location = 1) in vec3 passDir;
layout(location = 2) in vec3 passColor; layout(location = 2) in vec3 passColor;
layout(location = 3) in float passDensity; layout(location = 3) in float passDensity;
layout(location = 4) in flat int passSmokeIndex; layout(location = 4) in flat int passSmokeIndex;
...@@ -16,11 +16,6 @@ layout(set=1, binding=0, std430) readonly buffer randomBuffer { ...@@ -16,11 +16,6 @@ layout(set=1, binding=0, std430) readonly buffer randomBuffer {
float randomData []; float randomData [];
}; };
layout( push_constant ) uniform constants{
mat4 view;
mat4 projection;
};
#define NUM_SMOKE_SAMPLES 16 #define NUM_SMOKE_SAMPLES 16
void main() { void main() {
...@@ -28,10 +23,8 @@ void main() { ...@@ -28,10 +23,8 @@ void main() {
discard; discard;
} }
vec3 dir = -normalize((inverse(view) * vec4(passView, 0)).xyz);
vec3 start = passPos; vec3 start = passPos;
vec3 end = start + dir * 3.5f; vec3 end = start + normalize(passDir) * 3.5f;
vec4 result = vec4(0); vec4 result = vec4(0);
......
...@@ -10,14 +10,14 @@ layout(set=0, binding=0, std430) readonly buffer smokeBuffer { ...@@ -10,14 +10,14 @@ layout(set=0, binding=0, std430) readonly buffer smokeBuffer {
layout(location = 0) in vec3 vertexPos; layout(location = 0) in vec3 vertexPos;
layout(location = 0) out vec3 passPos; layout(location = 0) out vec3 passPos;
layout(location = 1) out vec3 passView; layout(location = 1) out vec3 passDir;
layout(location = 2) out vec3 passColor; layout(location = 2) out vec3 passColor;
layout(location = 3) out float passDensity; layout(location = 3) out float passDensity;
layout(location = 4) out flat int passSmokeIndex; layout(location = 4) out flat int passSmokeIndex;
layout( push_constant ) uniform constants{ layout( push_constant ) uniform constants{
mat4 view; mat4 mvp;
mat4 projection; vec3 camera;
}; };
void main() { void main() {
...@@ -25,10 +25,10 @@ void main() { ...@@ -25,10 +25,10 @@ void main() {
float size = smokes[gl_InstanceIndex].size; float size = smokes[gl_InstanceIndex].size;
vec3 color = smokes[gl_InstanceIndex].color; vec3 color = smokes[gl_InstanceIndex].color;
vec4 viewPos = view * vec4(position + vertexPos * size, 1); vec3 pos = position + vertexPos * size;
passPos = vertexPos; passPos = vertexPos;
passView = viewPos.xyz; passDir = pos - camera;
passColor = color; passColor = color;
if (size > 0.0f) { if (size > 0.0f) {
...@@ -40,5 +40,5 @@ void main() { ...@@ -40,5 +40,5 @@ void main() {
passSmokeIndex = gl_InstanceIndex; passSmokeIndex = gl_InstanceIndex;
// transform position into projected view space // transform position into projected view space
gl_Position = projection * viewPos; gl_Position = mvp * vec4(pos, 1);
} }
\ No newline at end of file
...@@ -22,14 +22,14 @@ layout(location = 3) in uint geomStartIndex [1]; ...@@ -22,14 +22,14 @@ layout(location = 3) in uint geomStartIndex [1];
layout(location = 4) in uint geomUseCount [1]; layout(location = 4) in uint geomUseCount [1];
layout(location = 0) out vec3 passPos; layout(location = 0) out vec3 passPos;
layout(location = 1) out vec3 passView; layout(location = 1) out vec3 passDir;
layout(location = 2) out vec3 passColor; layout(location = 2) out vec3 passColor;
layout(location = 3) out float passDensity; layout(location = 3) out float passDensity;
layout(location = 4) out flat int passSmokeIndex; layout(location = 4) out flat int passSmokeIndex;
layout( push_constant ) uniform constants{ layout( push_constant ) uniform constants{
mat4 view; mat4 mvp;
mat4 projection; vec3 camera;
}; };
void main() { void main() {
...@@ -41,58 +41,54 @@ void main() { ...@@ -41,58 +41,54 @@ void main() {
const uint startIndex = geomStartIndex[0]; const uint startIndex = geomStartIndex[0];
const uint useCount = geomUseCount[0]; const uint useCount = geomUseCount[0];
if (useCount <= 1) { const uint indexOffset = (gl_InvocationID * (INSTANCE_LEN - 1));
return; const uint instanceIndex = startIndex + indexOffset;
}
vec4 viewPositions [2];
for (uint i = 0; i < 2; i++) { uint count = min(INSTANCE_LEN, useCount);
const vec3 position = points[startIndex + i].position;
viewPositions[i] = view * vec4(position, 1); if ((indexOffset >= useCount) && (indexOffset + INSTANCE_LEN > useCount)) {
count = indexOffset - useCount;
} }
vec3 pos = viewPositions[0].xyz; if (count <= 1) {
vec3 dir = normalize(cross(viewPositions[1].xyz - pos, viewPositions[0].xyz)); return;
}
const float trailFactor = mediumDensity / friction; const float trailFactor = mediumDensity / friction;
for (uint i = 0; i < useCount; i++) { for (uint i = 0; i < count; i++) {
const float u = float(i + 1) / float(useCount); const float u = float(indexOffset + i + 1) / float(useCount);
const vec3 position = points[startIndex + i].position; const uint index = (instanceIndex + i) % points.length();
const float size = points[startIndex + i].size;
vec4 viewPos = view * vec4(position, 1); const vec3 position = points[index].position;
const float size = points[index].size;
const vec3 velocity = points[index].velocity;
if (i > 0) { const vec3 dir = normalize(cross(abs(velocity), position - camera));
dir = normalize(cross(viewPos.xyz - pos, viewPos.xyz));
pos = viewPos.xyz;
}
vec3 offset = dir * size; vec3 offset = dir * size;
float density = trailFactor * (1.0f - u * u) / size; float density = trailFactor * (1.0f - u * u) / size;
vec4 v0 = viewPos - vec4(offset, 0); const vec3 p0 = position - offset;
vec4 v1 = viewPos + vec4(offset, 0); const vec3 p1 = position + offset;
passPos = vec3(u, -1.0f, -1.0f); passPos = vec3(u, -1.0f, -1.0f);
passView = v0.xyz; passDir = vec3(-0.1f * u, +0.2f, 2.0f);
passColor = mix(color, trailColor, u); passColor = mix(color, trailColor, u);
passDensity = density; passDensity = density;
passSmokeIndex = int(id); passSmokeIndex = int(id);
gl_Position = projection * v0; gl_Position = mvp * vec4(p0, 1);
EmitVertex(); EmitVertex();
passPos = vec3(u, +1.0f, -1.0f); passPos = vec3(u, +1.0f, -1.0f);
passView = v1.xyz; passDir = vec3(-0.1f * u, -0.2f, 2.0f);
passColor = mix(color, trailColor, u); passColor = mix(color, trailColor, u);
passDensity = density; passDensity = density;
passSmokeIndex = int(id); passSmokeIndex = int(id);
gl_Position = projection * v1; gl_Position = mvp * vec4(p1, 1);
EmitVertex(); EmitVertex();
} }
......
...@@ -68,6 +68,11 @@ struct draw_particles_t { ...@@ -68,6 +68,11 @@ struct draw_particles_t {
uint32_t height; uint32_t height;
}; };
struct draw_smoke_t {
glm::mat4 mvp;
glm::vec3 camera;
};
#define PARTICLE_COUNT (1024) #define PARTICLE_COUNT (1024)
#define SMOKE_COUNT (512) #define SMOKE_COUNT (512)
#define TRAIL_COUNT (2048) #define TRAIL_COUNT (2048)
...@@ -838,13 +843,14 @@ int main(int argc, const char **argv) { ...@@ -838,13 +843,14 @@ int main(int argc, const char **argv) {
core.recordBufferMemoryBarrier(cmdStream, smokeBuffer.getHandle()); core.recordBufferMemoryBarrier(cmdStream, smokeBuffer.getHandle());
glm::mat4 smokeMatrices [2]; draw_smoke_t draw_smoke {
smokeMatrices[0] = camera.getView(); camera.getMVP(),
smokeMatrices[1] = camera.getProjection(); camera.getPosition()
};
core.recordBeginDebugLabel(cmdStream, "Draw smoke", { 1.0f, 0.5f, 1.0f, 1.0f }); core.recordBeginDebugLabel(cmdStream, "Draw smoke", { 1.0f, 0.5f, 1.0f, 1.0f });
vkcv::PushConstants pushConstantsDraw1 (sizeof(glm::mat4) * 2); vkcv::PushConstants pushConstantsDraw1 (sizeof(draw_smoke_t));
pushConstantsDraw1.appendDrawcall(smokeMatrices); pushConstantsDraw1.appendDrawcall(draw_smoke);
core.recordDrawcallsToCmdStream( core.recordDrawcallsToCmdStream(
cmdStream, cmdStream,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment