mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 12:57:38 +02:00
93 lines
2.5 KiB
Text
93 lines
2.5 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// particle vertex shader
|
|
//
|
|
// Copyright 2015 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
<@include gpu/Transform.slh@>
|
|
|
|
<$declareStandardTransform()$>
|
|
|
|
struct Radiuses {
|
|
float start;
|
|
float middle;
|
|
float finish;
|
|
float spread;
|
|
};
|
|
struct Colors {
|
|
vec4 start;
|
|
vec4 middle;
|
|
vec4 finish;
|
|
vec4 spread;
|
|
};
|
|
|
|
struct ParticleUniforms {
|
|
Radiuses radius;
|
|
Colors color;
|
|
float lifespan;
|
|
};
|
|
|
|
uniform particleBuffer {
|
|
ParticleUniforms particle;
|
|
};
|
|
|
|
in vec3 inPosition;
|
|
in vec2 inColor; // This is actual Lifetime + Seed
|
|
|
|
out vec4 varColor;
|
|
out vec2 varTexcoord;
|
|
|
|
const int NUM_VERTICES_PER_PARTICLE = 4;
|
|
const vec4 UNIT_QUAD[NUM_VERTICES_PER_PARTICLE] = vec4[NUM_VERTICES_PER_PARTICLE](
|
|
vec4(-1.0, -1.0, 0.0, 0.0),
|
|
vec4(1.0, -1.0, 0.0, 0.0),
|
|
vec4(-1.0, 1.0, 0.0, 0.0),
|
|
vec4(1.0, 1.0, 0.0, 0.0)
|
|
);
|
|
|
|
float bezierInterpolate(float y1, float y2, float y3, float u) {
|
|
// https://en.wikipedia.org/wiki/Bezier_curve
|
|
return (1.0 - u) * (1.0 - u) * y1 + 2.0 * (1.0 - u) * u * y2 + u * u * y3;
|
|
}
|
|
|
|
vec4 interpolate3Vec4(vec4 y1, vec4 y2, vec4 y3, float u) {
|
|
return vec4(bezierInterpolate(y1.x, y2.x, y3.x, u),
|
|
bezierInterpolate(y1.y, y2.y, y3.y, u),
|
|
bezierInterpolate(y1.z, y2.z, y3.z, u),
|
|
bezierInterpolate(y1.w, y2.w, y3.w, u));
|
|
}
|
|
|
|
|
|
void main(void) {
|
|
TransformCamera cam = getTransformCamera();
|
|
TransformObject obj = getTransformObject();
|
|
|
|
// Which icon are we dealing with ?
|
|
int particleID = gl_VertexID / NUM_VERTICES_PER_PARTICLE;
|
|
// Which quad vertex pos?
|
|
int twoTriID = gl_VertexID - particleID * NUM_VERTICES_PER_PARTICLE;
|
|
|
|
// Particle properties
|
|
float age = inColor.x / particle.lifespan;
|
|
float seed = inColor.y;
|
|
|
|
// Pass the texcoord and the z texcoord is representing the texture icon
|
|
varTexcoord = vec2((UNIT_QUAD[twoTriID].xy + 1.0) * 0.5);
|
|
varColor = interpolate3Vec4(particle.color.start, particle.color.middle, particle.color.finish, age);
|
|
|
|
// anchor point in eye space
|
|
float radius = bezierInterpolate(particle.radius.start, particle.radius.middle, particle.radius.finish , age);
|
|
vec4 quadPos = radius * UNIT_QUAD[twoTriID];
|
|
|
|
vec4 anchorPoint;
|
|
<$transformModelToEyePos(cam, obj, inPosition, anchorPoint)$>
|
|
|
|
vec4 eyePos = anchorPoint + quadPos;
|
|
<$transformEyeToClipPos(cam, eyePos, gl_Position)$>
|
|
}
|