Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/Stars" {
- Properties {
- iterations("_iterations", float) = 17
- formuparam("formuparam", float) = 0.53
- volsteps("volsteps",float) = 20
- stepsize("stepsize", float) = 0.1
- zoom("zoom", float) = 0.800
- tile("tile", float) = 0.850
- speed("speed", float) = 0.010
- brightness("brightness", float) = 0.00015
- darkmatter("darkmatter", float) = 0.30
- distfading("distfading", float) = 0.70
- saturation("saturation", float) = 0.80
- mouse("mouse",Vector) = (0., 0., 0., 0.)
- resolution("resolution",Vector) = (1280, 720, 0., 0.)
- }
- SubShader {
- Pass {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- // uniforms corresponding to properties
- uniform float iterations;
- uniform float formuparam;
- uniform float volsteps;
- uniform float stepsize;
- uniform float zoom;
- uniform float tile;
- uniform float speed;
- uniform float brightness;
- uniform float darkmatter;
- uniform float distfading;
- uniform float saturation;
- uniform float2 mouse;
- uniform float2 resolution;
- float4 vert(appdata_base v) : POSITION {
- return mul (UNITY_MATRIX_MVP, v.vertex);
- }
- float4 frag(float4 sp:WPOS) : COLOR {
- //get coords and direction
- float2 uv = sp.xy/resolution.xy-.5;
- uv.y*=resolution.y/resolution.x;
- float3 dir = float3(uv*zoom,1.);
- float time=_Time*speed+.25;
- //mouse rotation
- float a1=.5+mouse.x/resolution.x*2.;
- float a2=.8+mouse.y/resolution.y*2.;
- float2x2 rot1 = float2x2(cos(a1),sin(a1),-sin(a1),cos(a1));
- float2x2 rot2 = float2x2(cos(a2),sin(a2),-sin(a2),cos(a2));
- dir.xz=mul(rot1, dir.xz);
- dir.xy=mul(rot2, dir.xy);
- float3 from=float3(1.,.5,0.5);
- from+=float3(time*2.,time,-2.);
- from.xz=mul(rot1,from.xz);
- from.xy=mul(rot2,from.xy);
- //volumetric rendering
- float s=0.1,fade=1.;
- float3 v=float3(0,0,0);
- for (int r=0; r<volsteps; r++) {
- float3 p=from+s*dir*.5;
- p = abs(float3(tile,0, 0)-fmod(p,float3(tile*2,0,0))); // 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+=vec3(dm,dm*.5,0.);
- v+=fade;
- v+=float3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
- fade*=distfading; // distance fading
- s+=stepsize;
- }
- v= v * saturation + length(v) * (1.0 - saturation);//mix(float3(length(v)),v,saturation); //color adjust
- return float4(v*.01,1.);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement