This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathYUCIStarfieldGenerator.cikernel
executable file
·72 lines (61 loc) · 2.2 KB
/
YUCIStarfieldGenerator.cikernel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Star Nest by Pablo Román Andrioli
// This content is under the MIT License.
//mat2 is not supported by core image, use vec4. https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CIKernelLangRef/ci_gslang_ext.html
vec2 vec2MultiplyMat2(vec2 v, vec4 m) {
return vec2(m.x * v.x + m.y * v.y, m.z * v.x + m.w * v.y);
}
kernel vec4 coreImageKernel(vec4 inputExtent, float inputTime, vec2 inputRotation)
{
const int iterations = 17;
const float formuparam = 0.53;
const int volsteps = 20;
const float stepsize = 0.1;
const float zoom = 0.800;
const float tile = 0.850;
const float speed = 0.010;
const float brightness = 0.0015;
const float darkmatter = 0.300;
const float distfading = 0.730;
const float saturation = 0.850;
vec2 fragCoord = destCoord();
vec2 iResolution = inputExtent.zw;
//get coords and direction
vec2 uv=fragCoord.xy/iResolution.xy-.5;
uv.y*=iResolution.y/iResolution.x;
vec3 dir=vec3(uv*zoom,1.);
float time=inputTime*speed+.25;
//mouse rotation
vec2 iMouse = inputRotation;
float a1=.5+iMouse.x/iResolution.x*2.;
float a2=.8+iMouse.y/iResolution.y*2.;
vec4 rot1=vec4(cos(a1),sin(a1),-sin(a1),cos(a1));
vec4 rot2=vec4(cos(a2),sin(a2),-sin(a2),cos(a2));
dir.xz = vec2MultiplyMat2(dir.xz,rot1);
dir.xy = vec2MultiplyMat2(dir.xy,rot2);
vec3 from=vec3(1.,.5,0.5);
from+=vec3(time*2.,time,-2.);
from.xz = vec2MultiplyMat2(from.xz,rot1);
from.xy = vec2MultiplyMat2(from.xy,rot2);
//volumetric rendering
float s=0.1,fade=1.;
vec3 v=vec3(0.);
for (int r=0; r<volsteps; r++) {
vec3 p=from+s*dir*.5;
p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold
float pa,a=pa=0.;
for (int i=0; i<iterations; i++) {
p=abs(p)/dot(p,p)-formuparam; // the magic formula
a+=abs(length(p)-pa); // absolute sum of average change
pa=length(p);
}
float dm=max(0.,darkmatter-a*a*.001); //dark matter
a*=a*a; // add contrast
if (r>6) { fade*=1.-dm; } // dark matter, don't render near
v+=fade;
v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
fade*=distfading; // distance fading
s+=stepsize;
}
v=mix(vec3(length(v)),v,saturation); //color adjust
return vec4(v*.01,1.);
}