Skip to content
Snippets Groups Projects
Unverified Commit fbd2ebb0 authored by TheJackiMonster's avatar TheJackiMonster
Browse files

Use view space properly

parent 73ad0bc1
No related branches found
No related tags found
1 merge request!106Created initial firework project
...@@ -50,12 +50,8 @@ void main() { ...@@ -50,12 +50,8 @@ void main() {
viewPositions[i] = view * vec4(position, 1); viewPositions[i] = view * vec4(position, 1);
} }
const mat4 viewInv = inverse(view);
vec3 camDir = -normalize((viewInv * vec4(viewPositions[0].xyz, 0)).xyz);
vec3 pos = viewPositions[0].xyz; vec3 pos = viewPositions[0].xyz;
vec3 dir = normalize(cross(viewPositions[1].xyz - pos, camDir)); vec3 dir = normalize(cross(viewPositions[1].xyz - pos, viewPositions[0].xyz));
const float trailFactor = mediumDensity / friction; const float trailFactor = mediumDensity / friction;
...@@ -67,32 +63,33 @@ void main() { ...@@ -67,32 +63,33 @@ void main() {
vec4 viewPos = view * vec4(position, 1); vec4 viewPos = view * vec4(position, 1);
camDir = -normalize((viewInv * vec4(viewPos.xyz, 0)).xyz);
if (i > 0) { if (i > 0) {
dir = normalize(cross(viewPos.xyz - pos, camDir)); dir = normalize(cross(viewPos.xyz - pos, 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);
vec4 v1 = viewPos + vec4(offset, 0);
passPos = vec3(u, -1.0f, -1.0f); passPos = vec3(u, -1.0f, -1.0f);
passView = viewPos.xyz - offset; passView = v0.xyz;
passColor = mix(color, trailColor, u); passColor = mix(color, trailColor, u);
passDensity = density; passDensity = density;
passSmokeIndex = int(id); passSmokeIndex = int(id);
gl_Position = projection * viewPos - vec4(offset, 0); gl_Position = projection * v0;
EmitVertex(); EmitVertex();
passPos = vec3(u, +1.0f, -1.0f); passPos = vec3(u, +1.0f, -1.0f);
passView = viewPos.xyz + offset; passView = v1.xyz;
passColor = mix(color, trailColor, u); passColor = mix(color, trailColor, u);
passDensity = density; passDensity = density;
passSmokeIndex = int(id); passSmokeIndex = int(id);
gl_Position = projection * viewPos + vec4(offset, 0); gl_Position = projection * v1;
EmitVertex(); EmitVertex();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment