|
Toshihiro Shimizu |
890ddd |
#ifdef GL_ES
|
|
Toshihiro Shimizu |
890ddd |
precision mediump float;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tweaked from http://glsl.heroku.com/e#6015.0
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Posted by Trisomie21
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
uniform mat3 outputToWorld;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
uniform vec4 color;
|
|
Toshihiro Shimizu |
890ddd |
uniform float time;
|
|
Toshihiro Shimizu |
890ddd |
uniform float brightness;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tweaked from http://glsl.heroku.com/e#4982.0
|
|
Toshihiro Shimizu |
890ddd |
float hash( float n ) { return fract(sin(n)*43758.5453); }
|
|
Toshihiro Shimizu |
890ddd |
float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
float noise( in vec2 x )
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vec2 p = floor(x);
|
|
Toshihiro Shimizu |
890ddd |
vec2 f = fract(x);
|
|
Toshihiro Shimizu |
890ddd |
f = f*f*(3.0-2.0*f);
|
|
Toshihiro Shimizu |
890ddd |
float n = p.x + p.y*57.0;
|
|
Toshihiro Shimizu |
890ddd |
float res = mix(mix(hash(n+0.0), hash(n+1.0),f.x), mix(hash(n+57.0), hash(n+58.0),f.x),f.y);
|
|
Toshihiro Shimizu |
890ddd |
return res;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vec3 cloud(vec2 p) {
|
|
Toshihiro Shimizu |
890ddd |
float f = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
f += 0.50000*noise(p*1.0*10.0);
|
|
Toshihiro Shimizu |
890ddd |
f += 0.25000*noise(p*2.0*10.0);
|
|
Toshihiro Shimizu |
890ddd |
f += 0.12500*noise(p*4.0*10.0);
|
|
Toshihiro Shimizu |
890ddd |
f += 0.06250*noise(p*8.0*10.0);
|
|
Toshihiro Shimizu |
890ddd |
f *= f;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return color.rgb * color.a * f * .6;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const float SPEED = 0.01;
|
|
Toshihiro Shimizu |
890ddd |
const float DENSITY = 1.5;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void main( void )
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vec2 pos = .01 * (outputToWorld * vec3(gl_FragCoord.xy, 1.0)).xy;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Nebulous cloud - It's intended as background, ie it doesn't block stars visibility.
|
|
Toshihiro Shimizu |
890ddd |
// Stars ADD to this.
|
|
Toshihiro Shimizu |
890ddd |
vec3 color = cloud(pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Stars Field - this is the idea: each star is drawn in a 'star cell' which results from
|
|
Toshihiro Shimizu |
890ddd |
// FLOORING a point function p(x,y) of the pixel coordinates. A cell's edges correspond to
|
|
Toshihiro Shimizu |
890ddd |
// coordinated lines of the form: p_x(x,y) = int, p_y(x, y) = int.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// The problem lies in finding a function p which is suitable, ie p_x's and p_y's gradients should
|
|
Toshihiro Shimizu |
890ddd |
// be as orthogonal and with finite strictly positive norm as possible.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Changing to polar coordinates is simplest - when the radius (distance from origin)
|
|
Toshihiro Shimizu |
890ddd |
// is high, moving in radius and arc distance is almost orthogonal. Plus, star 'discs' are harder
|
|
Toshihiro Shimizu |
890ddd |
// to spot than star 'rows', since they are curved.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// I think that a suitable deformation of the identity grid based on sin and cos exists,
|
|
Toshihiro Shimizu |
890ddd |
// but couldn't find it... ^.^'
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
float dist = length(pos);
|
|
Toshihiro Shimizu |
890ddd |
vec2 coord = vec2(dist, atan(pos.y, pos.x)/* / (3.1415926*2.0)*/); // Pseudo-polar coordinates
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vec2 p = 40.0 * vec2(coord.x, // radius
|
|
Toshihiro Shimizu |
890ddd |
floor(coord.x + 1.0) * coord.y + // arc distance (floor helps stabilizing cell shapes, and 1.0 to avoid flooring to 0)
|
|
Toshihiro Shimizu |
890ddd |
hash(floor(40.0 * coord.x))); // shifts the star 'discs' along the arc, by a pseudo-random value (helps avoiding 'star rows', at least along the radial direction)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vec2 uv = 2.0 * fract(p) - 1.0; // Pixel position in the cell, in [-1,1]^2 coordinates
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
float cellValue = abs(2.0 * fract(rand(floor(p)) + SPEED * time) - 1.0);
|
|
Toshihiro Shimizu |
890ddd |
float cellBrightness = clamp((cellValue - 0.9) * brightness * 10.0, 0.0, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
color += clamp(
|
|
Toshihiro Shimizu |
890ddd |
(1.0 - 2.0 * length(uv)) * // Comment this line to see the star cells
|
|
Toshihiro Shimizu |
890ddd |
cellBrightness, 0.0, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gl_FragColor = vec4(color, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|