Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Default vars
- varying vec2 vTexCoord;
- uniform sampler2D uImage0;
- uniform vec2 uResolution;
- uniform float uTime;
- // Black hole vars
- uniform float enable;
- uniform float appdis; // display static if the black hole just appeared or is about to disappear
- // Center
- uniform float blackHoleX;
- uniform float blackHoleY;
- // Radii
- // singularity < horizon
- uniform float horizon;
- uniform float singularity;
- /* General principle :
- We need a way to make the image look like it falls into the black hole as the pixels are closer.
- A solution is to increase the distance of the pixel to the image's plane as it gets closer to the black hole,
- so that pixels right on the horizon are not distorted, and so that pixels right on the singularity are all mapped to the image's pixel
- that is under the center of the black hole.
- To do that, we take the vector between the pixel and the center of the black hole and we remap its length to catch another of the image's pixels
- that is closer to the black hole's center's location.
- Algorithm :
- for each pixel in screen
- (
- dist = distance(pixel, black hole center)
- if dist > horizon
- gl_FragColor = pixel.color
- else if dist > singularity
- (new distance) = f(dist)
- (new pixel) = (pixel - (black hole center)) * (new distance) + (black hole center)
- gl_FragColor = (new pixel).color
- else
- gl_FragColor = black
- )
- f is the scaling function ; it transforms a linear range into an open asymptotic range
- f is caracterized by f(horizon) = 1, lim f(x) = +∞
- x -> singularity
- Here, f : ]singularity, horizon] -> [ 1, +∞ [
- x |-> ____________1____________
- 3.5 ____________________
- / x - singularity
- / ---------------------
- \/ horizon - singularity
- */
- float f(float d)
- {
- return 1. / pow((d - singularity) / (horizon - singularity), 1. / 3.5);
- }
- float rand()
- {
- return fract( sin((vTexCoord.x * vTexCoord.y + uTime) * 136974) * 4123645 ); // Random number generators : keyboard mashing 101
- }
- void main()
- {
- vec2 frustrum = vec2(uResolution.x / uResolution.y, uResolution.y / uResolution.y);
- vec2 uv = vTexCoord - vec2(0.5, 0.5);
- uv *= frustrum;
- vec4 c = vec4(0);
- if(appdis > 0.5)
- c = vec4(rand());
- else if(enable > 0.5)
- {
- vec2 attractionPoint = vec2(blackHoleX, blackHoleY) - vec2(0.5, 0.5);
- //attractionPoint *= frustrum;
- float d = distance(uv, attractionPoint);
- if(d < singularity)
- c = vec4(vec3(0.), 1.);
- else
- {
- if(d < horizon)
- uv = f(d) * (uv - attractionPoint) + attractionPoint;
- c = texture2D(uImage0, uv / frustrum + vec2(0.5, 0.5)) + vec4(cos(uTime * 3) * 0.5 + 0.5, 0, 0, 0);
- }
- }
- else
- c = texture2D(uImage0, vTexCoord);
- gl_FragColor = c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement