// ORBITAL / original analytic worlds. D3D11 ps_5_0, no resources. // gTune = (floor variant 0..2, animation rate 0..2, emission 0..2, tilt radians). // Zero rate still moves. gTime.x is seconds; camera is never replaced. // Suggested eye / at / vertical FOV degrees / camera speed / tune: // 0: (0,3.8,-12) / (0,0,0) / 44 / TRACK .35 / (0,1,1,.22), ONE flyby. // 1: (0,2.9,-13) / (0,0,0) / 46 / ORBIT .07 / (1,.8,1,-.18). // 2: (0,1,-11) / (0,0,0) / 48 / TRACK .30 / (2,1,1,.15). // Bounds centered at origin: 0 sphere R=5.7 (planet R=2.6), // 1 sphere R=6.5 (opaque core R=1.48); 2 sphere R=5.3. // Keep camera outside those bounds; slow track/orbit gives strong parallax. // Transparent sheets composite in ray order, behind nearest opaque surface. // Depth is nearest visible layer at .05/viewZ, sky is infinite (zero). cbuffer Scene : register(b0) { float4 gTime; float4 gCam; float4 gDir; float4 gTune; float4 gSync; float4 gVoice; }; struct VSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; }; struct PSOut { float4 color : SV_Target; float depth : SV_Depth; }; static const float PI = 3.14159265359; static const float FAR_T = 1e5; static const float3 CYAN = float3(.12,.78,1.0); static const float3 AMBER = float3(1.0,.43,.105); static const float3 PINK = float3(.78,.095,.45); static const float3 SUN = float3(-.57735,.57735,-.57735); float hash31(float3 p) { p = frac(p * .1031); p += dot(p, p.yzx + 33.33); return frac((p.x + p.y) * p.z); } float noise3(float3 p) { float3 b = floor(p), f = frac(p); f = f*f*(3.0-2.0*f); return lerp(lerp(lerp(hash31(b), hash31(b+float3(1,0,0)), f.x), lerp(hash31(b+float3(0,1,0)), hash31(b+float3(1,1,0)), f.x), f.y), lerp(lerp(hash31(b+float3(0,0,1)), hash31(b+float3(1,0,1)), f.x), lerp(hash31(b+float3(0,1,1)), hash31(b+1.0), f.x), f.y), f.z); } float2 rotate2(float2 p, float a) { float s, c; sincos(a,s,c); return float2(c*p.x-s*p.y, s*p.x+c*p.y); } float3 localPoint(float3 p) { p.xy = rotate2(p.xy, -.32-clamp(gTune.w,-.8,.8)); return p; } // Analytic interval also handles a camera inside a sphere. float2 sphere(float3 ro, float3 rd, float radius) { float b = dot(ro,rd), h = b*b-dot(ro,ro)+radius*radius; if (h < 0.0) return float2(FAR_T,-FAR_T); h = sqrt(h); return float2(-b-h,-b+h); } float firstHit(float2 hit) { return hit.x > .001 ? hit.x : (hit.y > .001 ? hit.y : FAR_T); } // World-fixed far stars on cube faces; filtered footprints, no screen noise. float3 sky(float3 d, float footprint) { float3 a = abs(d); float2 uv; float face; if (a.x >= a.y && a.x >= a.z) { uv=d.yz/a.x; face=d.x>0?1.0:2.0; } else if (a.y >= a.z) { uv=d.xz/a.y; face=d.y>0?3.0:4.0; } else { uv=d.xy/a.z; face=d.z>0?5.0:6.0; } float2 st = uv*125.0, cell=floor(st), f=frac(st); float h=hash31(float3(cell,face)); float2 center=.25+.5*float2(hash31(float3(cell,face+12.0)),hash31(float3(cell,face+31.0))); float w=max(.035,footprint*125.0); float star=exp(-dot(f-center,f-center)/(w*w)) * min(1.0,.008/(w*w)); star *= smoothstep(.986,.999,h); float dust=pow(saturate(1.0-abs(d.y+.22*d.x-.13)*3.0),6.0); float n=noise3(d*7.0); return float3(.004,.007,.016) + dust*n*float3(.021,.012,.034) + lerp(float3(.42,.68,1.0),float3(1.0,.7,.4),h)*star*1.8; } float annulus(float r, float lo, float hi, float aa) { return smoothstep(lo-aa,lo+aa,r)*(1.0-smoothstep(hi-aa,hi+aa,r)); } // Fade frequencies beyond the ray footprint before evaluating narrow grooves. float wave(float phase, float frequency, float width) { return .5+.5*sin(phase)*saturate(1.0-frequency*width*.32); } float ringDensity(float r, float width) { float bands=.38+.28*wave(r*39.0,39.0,width)+.30*wave(r*113.0,113.0,width); float gap=1.0-.94*exp(-pow((r-4.23)/max(.055,width),2.0)); return bands*gap*annulus(r,3.22,5.55,max(.012,width)); } float3 planet(float3 p, float3 rd, float time, float px) { float3 n=p/2.6, q=n; q.xz=rotate2(q.xz,time*.095); float turbulence=noise3(q*8.0)+.38*noise3(q*23.0); float lat=q.y*33.0+(turbulence-.65)*3.0; float bands=.5+.5*sin(lat); float fine=wave(lat*3.6+q.x*5.0,120.0,px); float3 alb=lerp(float3(.12,.22,.31),float3(.83,.49,.22),bands); alb=lerp(alb,float3(.76,.72,.56),.32*fine); // A local oval storm travels with the rotating atmosphere. float2 storm=float2(q.x+.37,(q.y+.19)*2.8); float vortex=exp(-dot(storm,storm)*95.0)*smoothstep(.15,.6,-q.z); alb=lerp(alb,float3(.70,.16,.095),vortex*.85); float light=saturate(dot(n,SUN)); float shadow=1.0; float ts=-p.y/SUN.y; if (ts>0.0) shadow=1.0-.83*ringDensity(length((p+SUN*ts).xz),.02); float rim=pow(1.0-saturate(dot(n,-rd)),3.5); float3 col=alb*(.10+.94*light*shadow); col+=CYAN*rim*(.12+.48*light)*(.97+.03*saturate(gSync.y)); return col; } // Three differently oriented sheets; true plane intersections, no screen halos. float3 sheetNormal(int id) { if (id==0) return float3(0,1,0); if (id==1) return normalize(float3(.13,.24,1.0)); return normalize(float3(-.64,1.0,.31)); } float4 sheet(float3 p, float3 rd, int id, int mode, float time, float px) { float3 normal=sheetNormal(id); float3 u=normalize(cross(normal,float3(1,0,0))); float3 v=cross(normal,u); float2 q=float2(dot(p,u),dot(p,v)); float r=length(q), angle=atan2(q.y,q.x); float width=max(.008,px/max(.12,abs(dot(rd,normal)))); float4 result=float4(0,0,0,0); if (mode==0) { float density=ringDensity(r,width); float3 c=lerp(float3(.22,.40,.48),float3(.85,.60,.31),wave(r*9.0,9.0,width)); float shadow=firstHit(sphere(p+SUN*.01,SUN,2.6)).98?float3(0,0,1):float3(0,1,0); float3 right=normalize(cross(worldUp,fw)), up=cross(fw,right); float2 uv=(input.uv*2.0-1.0)*float2(gTime.w,-1.0); uv=rotate2(uv,gDir.w); float3 worldRay=normalize(fw+(right*uv.x+up*uv.y)*gCam.w); float footprint=max(length(ddx(worldRay)),length(ddy(worldRay))); float3 ro=localPoint(gCam.xyz), rd=localPoint(worldRay); int mode=(int)clamp(floor(gTune.x),0.0,2.0); float time=gTime.x*(.55+.45*clamp(gTune.y,0.0,2.0)); float exposure=.65+.35*clamp(gTune.z,0.0,2.0); float3 col=sky(worldRay,footprint); float nearest=FAR_T; [branch] if (mode<2) { float radius=mode==0?2.6:1.48; float t=firstHit(sphere(ro,rd,radius)); if (t=5) break; float h=hash31(float3(float(j),7.0,2.0)); float orbit=mode==0?5.55:(3.0+2.85*h); float a=float(j)*2.39996+time*(.085+.06*h); float3 center=float3(cos(a)*orbit,(mode==0?.11:1.15)*sin(a*2.0+float(j)),sin(a)*orbit); float size=(mode==0?.035:.065)+h*h*(mode==0?.075:.15); float3 axes=float3(size,size*(.55+.45*h),size*.76); float3 er=(ro-center)/axes, ed=rd/axes; float len=length(ed); float hit=firstHit(sphere(er,ed/len,1.0)); t=hit1e-5?-dot(ro,normal)/denom:FAR_T; distances[k]=(hit>.001 && hit.02) nearest=min(nearest,t); } } // Analytic atmosphere shell: only its segment in FRONT of opaque matter. if (mode==0) { float2 atmo=sphere(ro,rd,2.66); float start=max(.001,atmo.x), end=min(opaque,atmo.y); if (end>start) { float mid=(start+end)*.5; float3 p=ro+rd*mid; float light=.12+.88*saturate(dot(normalize(p),SUN)); // A foreground ring attenuates the atmosphere as well. float visibility=1.0; float planeT=abs(rd.y)>1e-5?-ro.y/rd.y:FAR_T; if (planeT>0.0 && planeTend) break; float3 p=ro+rd*t; float2 field=filaments(p,time); float eps=max(.0015,footprint*t*.42); if (field.x