nicer particles, adding code so that particles don't penetrate through planets. added not-yet compeleted intersection code.

This commit is contained in:
Andreas Ortmann 2016-10-02 20:10:43 +02:00
parent 57e6e56217
commit 4712926be2
6 changed files with 207 additions and 17 deletions

View file

@ -1,10 +1,13 @@
#version 120
varying vec3 position;
varying vec2 vertex;
varying vec3 velocity;
varying float decay;
varying float explCenterDist;
float pi = 3.14159;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
@ -12,15 +15,28 @@ vec3 hsv2rgb(vec3 c)
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
float hash(float n)
{
return fract(sin(n)*43758.5453);
}
void main()
{
float r = length(vertex);
if (r > 1.0) {
// normalize radius from 0..1
vec2 vn = 2.0*vertex;
float rn = length(vn);
float angle = atan(vn.y, vn.x);
float hs = 20.0;
float removeCorners = 0.5 * (hash(fract(hs*vertex.x)) + hash(fract(hs*vertex.y)));
if (rn+removeCorners > 1.0) {
discard;
}
//float rf = 0.5-0.5*rn;
float rf = 1.0;
float d = decay/(1.0+max(0.0, 1.0-2.0*explCenterDist));
float h = (1.0-d)/6.0;
float h = max(0.0, (1.0-d)/6.0) * rf;
float v = max(0.0, (1.0-log(d)));
float s = max(0.0, min(30.0 * sqrt(decay) * explCenterDist, 1.0));
@ -30,4 +46,5 @@ void main()
gl_FragColor = vec4(hsv2rgb(vec3(h, s, v)), 1.0);
//gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
//gl_FragColor.rgb = vec3(0.5+0.5*(a/pi));
}

View file

@ -14,6 +14,7 @@ varying float decay;
varying vec3 velocity;
varying vec2 vertex;
varying float explCenterDist;
varying vec3 position;
uniform float aspectRatio;
@ -31,9 +32,9 @@ void main()
// faster particles are smaller
// TODO: scale by time too! scale down fast after 3 halfAges
float scaleBySpeed = (1.0 - 0.95*length(in_velocity)/maxVelocity);
float finalSize = size * scaleBySpeed;
float finalSize = size * scaleBySpeed * (1.0-max(0.0, decay-3.0*halfAge)/2.0);
vec2 base = in_geometry;
vec3 p = finalSize*vec3(base, 0.0);
vec3 p = vec3(finalSize*base, 0.0);
vec3 move = (0.2*age + log(1.0+age*5.0)) * in_velocity;
float md = length(move);
if (md > in_maxDist) {
@ -46,6 +47,7 @@ void main()
vertex = base.xy;
velocity = in_velocity;
position = in_position;
explCenterDist = length(explCenter - offset);
}