
和DeepSeek斗智斗勇了几天,终于让她帮我写完了,无偿分享,粘贴即用:
代码块
PlainText
Shader "Skybox/BlackHole"
{
Properties
{
_AccretionTex ("Accretion Texture", 2D) = "white" {}
_NoiseTex ("Noise Texture", 2D) = "white" {}
_NoiseScale ("Noise Scale", Range(0.1, 20.0)) = 4.0
_NoiseStrength ("Noise Strength", Range(0.0, 2.0)) = 1.41
_TimeScale ("Time Scale", Float) = -4.0
_Exposure ("Exposure", Range(0.0, 5.0)) = 1.0
[Header(Black Hole Direction)]
_Longitude ("Longitude (Degrees)", Range(0.0, 360.0)) = 43.0
_Latitude ("Latitude (Degrees)", Range(-90.0, 90.0)) = 4.0
_Rotation ("Rotation (Degrees)", Range(0.0, 360.0)) = 25.0
_Tilt ("Tilt (Degrees)", Range(-90.0, 90.0)) = -5.0
[Header(Black Hole Size)]
_AngularDiameter ("Angular Diameter (Degrees)", Range(0.5, 120.0)) = 6.0
_BlackHoleDistance ("Distance", Range(1.0, 100.0)) = 3.0
_MassScale ("Mass Scale", Range(0.0, 20.0)) = 5.0
_MassCoefficient ("Mass Coefficient", Range(0.0, 10.0)) = 2.0
_MaxSteps ("Max Steps", Range(50, 500)) = 256
_TextureScale ("Texture Scale", Range(0.1, 20.0)) = 1.3
_CaptureSoftness ("Capture Softness", Range(0.01, 10.0)) = 1.0
[Header(Disk Appearance)]
_DiskRadiusScale ("Disk Radius Scale", Range(2.0, 20.0)) = 4.0
_DiskIntensity ("Disk Intensity", Range(0.0, 2.0)) = 0.6
_DiskSoftness ("Disk Softness", Range(0.0, 1.0)) = 1.0
_GlowIntensity ("Glow Intensity", Range(0.0, 1.0)) = 0.2
_TorusTubeRadius("Torus Tube Radius", Range(0.0, 2.0)) = 1
_DiskCloudCenter ("Disk Cloud Center", Range(0.0, 10.0)) = 1
_DiskCloudWidth("Disk Cloud Width", Range(0.0, 10.0)) = 1
_DiskTubeScale("Disk Tube Scale", Range(1.0, 100.0)) = 32
_DiskInnerColor ("Disk Inner Color", Color) = (0.9921, 0.9975, 1.0, 1.0)
_DiskOuterColor ("Disk Outer Color", Color) = (1.0, 0.9975, 0.9960, 1.0)
_DiskAngularFade ("Angular Fade Width (Deg)", Range(0.0, 90.0)) = 8.0
[Header(Integration Scaling)]
_DiskStepScale ("Disk Step Scale", Float) = 80.0
_GlowStepScale ("Glow Step Scale", Float) = 40.0
_CloudStepScale ("Cloud Step Scale", Float) = 30.0
[Header(Photon Ring)]
_PhotonRingIntensity ("Photon Ring Intensity", Range(0.0, 5.0)) = 1.0
_PhotonRingWidth ("Ring Width", Range(0.001, 0.5)) = 0.1
_PhotonRingColor ("Ring Color", Color) = (1.0, 1.0, 1.0, 1.0)
_PhotonRingInnerFade ("Inner Fade", Range(0.0, 1.0)) = 0.6
// ---------- 体积双极喷流(含旋进) ----------
[Header(Volumetric Jet)]
_JetIntensity ("Jet Intensity", Range(0.0, 100.0)) = 0.0
_JetColor ("Jet Color", Color) = (0.61, 0.68, 1.0, 1.0)
_JetTexture ("Jet Texture", 2D) = "white" {}
_JetSpeed ("Flow Speed", Float) = 32.0
_JetLength ("Half Length", Range(0.1, 5.0)) = 4.0
_JetConeAngle ("Cone Angle (Deg)", Range(1.0, 60.0)) = 4.0
_JetBaseRadius ("Base Radius", Range(0.0, 2.0)) = 0.05
_JetHoleRadius ("Hole Ratio (0=实心, 1=空心)", Range(0.0, 1.0)) = 0.45
_JetNoiseStrength ("Noise Strength", Range(0.0, 1.0)) = 1.0
_JetNoiseScale ("Noise Scale", Range(0.1, 5.0)) = 0.1
_JetNoiseVerticalScale ("Noise Vertical Scale", Range(0.1, 5.0)) = 3.8
_JetEdgeSharpness ("Edge Sharpness", Range(0.0, 1.0)) = 0
// 旋进参数
_JetPrecessionAngle ("Precession Angle (Deg)", Range(0.0, 45.0)) = 0.0
_JetPrecessionSpeed ("Precession Speed (Deg/s)", Range(-100.0, 100.0)) = 0.0
_JetPrecessionPhase ("Precession Phase (Deg)", Range(0.0, 360.0)) = 0.0
// 螺旋喷流开关
[Toggle] _JetSpiral ("Use Spiral Jet", Float) = 0
// 喷流起始端淡入长度
_JetFadeIn ("Fade In Length", Range(0.0, 5.0)) = 2.0
// 螺旋样式调节参数
[Header(Spiral Jet Settings)]
_JetSpiralTurns ("Spiral Turns", Range(0.5, 10.0)) = 2.0
_JetSpiralWidth ("Spiral Width (Angle)", Range(0.05, 1.5)) = 0.3
_JetSpiralRotationSpeed ("Spiral Rotation Speed", Range(-15.0, 15.0)) = 5.0
_JetSpiralArms ("Spiral Arms", Range(1, 4)) = 2
[Header(Gravity Wave Distortion)]
_GravityWaveStrength ("Wave Strength", Range(0.0, 0.5)) = 0.05
_GravityWaveSpeed ("Wave Speed", Float) = 0.5
_GravityWaveFreq ("Wave Frequency", Float) = 2.0
[Header(Background)]
_StarIntensity ("Star Intensity", Range(0.0, 2.0)) = 2.0
_StarRotationSpeed ("Star Rotation Speed", Range(-10.0, 10.0)) = 0.02
_NebulaRotationSpeed ("Nebula Rotation Speed", Range(-10.0, 10.0)) = 0.01
_StarTwinkleStrength ("Star Twinkle Strength", Range(0.0, 1.0)) = 1.0
_StarTwinkleSpeed ("Star Twinkle Speed", Range(0.1, 10.0)) = 4.0
_NebulaIntensity ("Nebula Intensity", Range(0.0, 1.0)) = 0.4
_NebulaScale ("Nebula Scale", Range(0.1, 5.0)) = 1.77
_NebulaColor1 ("Nebula Color 1", Color) = (1.0, 0.9, 0.8213, 1.0)
_NebulaColor2 ("Nebula Color 2", Color) = (0.3, 0.2, 0.3, 1)
_NebulaColor3 ("Nebula Color 3", Color) = (0.0, 0.05, 0.1, 1)
_NebulaDetail ("Nebula Detail", Range(0.0, 1.0)) = 1.0
_NebulaWarp ("Nebula Warp", Range(0.0, 1.5)) = 1.5
_NebulaContrast ("Nebula Contrast", Range(0.5, 2.0)) = 1.2
_NebulaFlatten ("Nebula Flatten", Range(0.1, 5.0)) = 1.8
_StarGlowIntensity ("Star Glow Intensity", Range(0.0, 5.0)) = 0.6
_StarGlowRadius ("Star Glow Radius", Range(1, 50.0)) = 25.0
_StarColorfulIntensity ("Colorful Intensity", Range(0.0, 1.0)) = 1.0
_StarTintColor ("Star Tint Color", Color) = (1, 1, 1, 1)
_StarColorBlend ("Color Style Blend", Range(0.0, 1.0)) = 0.6
[Header(Skybox Texture)]
_SkyboxCubemap ("Skybox Cubemap", Cube) = "" {}
_SkyboxBlend ("Skybox Texture Blend", Range(0.0, 1.0)) = 0.0
_SkyboxExposure ("Skybox Texture Exposure", Range(0.0, 5.0)) = 1.0
[Header(Background Gradient)]
_GradientTopColor ("Gradient Top Color", Color) = (1.0, 0.9444, 0.9213, 1.0)
_GradientBottomColor ("Gradient Bottom Color", Color) = (0.1, 0.01, 0.1, 1.0)
_GradientBlend ("Gradient Blend", Range(0.0, 1.0)) = 0.05
_GradientPower ("Gradient Power", Range(0.1, 10.0)) = 6.3
[Header(Galaxy Milky Way)]
_GalaxyIntensity ("Galaxy Intensity", Range(0.0, 2.0)) = 1.0
_GalaxyCenterLongitude ("Center Longitude (Deg)", Range(0.0, 360.0)) = 41.0
_GalaxyCenterLatitude ("Center Latitude (Deg)", Range(-90.0, 90.0)) = -9.0
_GalaxyTilt ("Tilt (Deg)", Range(0.0, 360.0)) = 355.0
_GalaxyBandScale ("Band Scale", Range(0.5, 5.0)) = 1.44
_GalaxyWidthScale ("Width Scale", Range(0.2, 5.0)) = 1.0
_GalaxyCoreIntensity ("Core Glow Intensity", Range(0.0, 2.0)) = 0.6
_GalaxyCoreScale ("Core Glow Scale", Range(0.5, 5.0)) = 4.45
_GalaxyDustOpacity ("Dark Band Opacity", Range(0.0, 5.0)) = 1.36
_GalaxyCloudShadow ("Cloud Shadow", Range(-3.0, 1.0)) = 0.2
_GalaxyCloudBright ("Cloud Bright", Range(-3.0, 3.0)) = 0.8
_GalaxyCloudFluffStrength ("Cloud Fluff Strength", Range(0.0, 3.0)) = 2.0
_GalaxyCloudFluffScale ("Cloud Fluff Scale", Range(0.5, 20.0)) = 15.4
_GalaxyCloudFluffWarp ("Cloud Fluff Warp", Range(0.0, 2.0)) = 0.41
_GalaxyColor1 ("Light Color", Color) = (1.0, 0.8889, 0.8207, 1)
_GalaxyColor2 ("Dark Color", Color) = (0.3647, 0.3177, 0.3177, 1)
_GalaxyColor3 ("Cloud Color", Color) = (1.0, 0.6385, 0.4182, 1)
_GalaxyDarkCloudColorBlend ("Dark Cloud Color Blend", Range(0.0, 1.0)) = 0.5
_GalaxyCloudOuterFade ("Cloud Outer Fade", Range(0.0, 1.0)) = 0.8
_GalaxyDarkBandColor ("Dark Band Color", Color) = (0.7735, 0.3854, 0.1873, 1.0)
_GalaxyDarkBandColorBlend ("Dark Band Color Blend", Range(0.0, 1.0)) = 0.6
_GalaxyBendAmount ("Galaxy Bend Amount", Range(0.0, 1.0)) = 0.02
_GalaxyBendFrequency ("Galaxy Bend Frequency", Range(0.1, 10.0)) = 10.0
_GalaxyStarDensityBoost ("Star Density Boost", Range(0.0, 10.0)) = 5.0
_SmallGalaxyWidth ("Small Galaxy Width", Range(0.01, 0.2)) = 0.144
_SmallGalaxyOffset ("Small Galaxy Offset", Range(0.0, 0.1)) = 0.0134
_SmallGalaxyIntensity ("Small Galaxy Intensity", Range(0.0, 1.0)) = 1.0
_SmallGalaxyColor ("Small Galaxy Color", Color) = (0.8870, 0.6880, 0.5884, 1.0)
_SmallGalaxyNoiseScale ("Small Galaxy Noise Scale", Range(0.5, 5.0)) = 5.0
_SmallGalaxyNoiseOctaves ("Small Galaxy Noise Octaves", Range(1, 6)) = 3
_SmallGalaxyMaskStrength ("Mask Strength", Range(0.0, 1.0)) = 1.0
_SmallGalaxyMaskScale ("Mask Scale", Range(0.5, 5.0)) = 1.4
_SmallGalaxyMaskContrast ("Mask Contrast", Range(0.1, 2.0)) = 1.51
_SmallGalaxyMaskWarp ("Mask Warp", Range(0.0, 2.0)) = 2.0
_SmallGalaxyMaskOffsetX ("Mask Offset X", Range(-5.0, 5.0)) = 1.34
_SmallGalaxyMaskOffsetY ("Mask Offset Y", Range(-5.0, 5.0)) = 0.6
_SmallGalaxySharpness ("Edge Sharpness", Range(0.0, 1.0)) = 0.01
[Toggle] _SmallGalaxyInvertMask ("Invert Mask", Float) = 0
[Header(Meteors)]
_MeteorCount ("Meteor Count", Int) = 5
_MeteorSpeed ("Meteor Speed", Range(0.1, 5.0)) = 1.0
_MeteorLength ("Meteor Length", Range(0.001, 1)) = 1.0
_MeteorIntensity ("Meteor Intensity", Range(0.0, 3.0)) = 1.0
_MeteorDominantLongitude ("Dominant Longitude", Range(0.0, 360.0)) = 173.0
_MeteorDominantLatitude ("Dominant Latitude", Range(-90.0, 90.0)) = -48.0
_MeteorDirectionWeight ("Direction Weight", Range(0.0, 1.0)) = 0.6
_MeteorTailFalloff ("Tail Falloff", Range(0.5, 5.0)) = 4.0
_MeteorFrequency ("Meteor Frequency", Range(0.1, 5.0)) = 2.0
_MeteorDiversity ("Diversity", Range(0.0, 1.0)) = 1.0
[Header(Lens Flare)]
_LensFlareIntensity ("Flare Intensity", Range(0.0, 5.0)) = 0.0
_LensFlareColor ("Flare Color", Color) = (1.0, 0.85, 0.7, 1.0)
_LensFlareSize ("Flare Size", Range(0.1, 2.0)) = 1.0
_LensFlareRotationSpeed ("Rotation Speed", Range(-5.0, 5.0)) = 0.5
}
SubShader
{
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
Cull Off
ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
// ---- 纹理与参数声明 ----
sampler2D _AccretionTex;
sampler2D _NoiseTex;
float _NoiseScale, _NoiseStrength, _TimeScale, _Exposure;
float _Longitude, _Latitude, _Rotation, _Tilt, _AngularDiameter;
float _BlackHoleDistance, _MassScale, _MassCoefficient, _MaxSteps, _TextureScale;
float _DiskRadiusScale, _DiskIntensity, _DiskSoftness, _GlowIntensity;
float _DiskCloudCenter, _DiskCloudWidth, _DiskTubeScale, _TorusTubeRadius;
float4 _DiskInnerColor, _DiskOuterColor;
float _DiskAngularFade; // 新增:吸积盘角度接缝淡出宽度(度)
float _StarIntensity, _StarRotationSpeed, _NebulaRotationSpeed;
float _StarTwinkleStrength, _StarTwinkleSpeed, _NebulaIntensity;
float _NebulaScale, _NebulaDetail, _NebulaWarp, _NebulaContrast, _NebulaFlatten;
float4 _NebulaColor1, _NebulaColor2, _NebulaColor3;
float _StarGlowIntensity, _StarGlowRadius, _StarColorfulIntensity;
float4 _StarTintColor;
float _StarColorBlend;
samplerCUBE _SkyboxCubemap;
float _SkyboxBlend, _SkyboxExposure;
float4 _GradientTopColor, _GradientBottomColor;
float _GradientBlend, _GradientPower;
float _GalaxyIntensity, _GalaxyCenterLongitude, _GalaxyCenterLatitude, _GalaxyTilt;
float _GalaxyBandScale, _GalaxyWidthScale, _GalaxyCoreIntensity, _GalaxyCoreScale;
float _GalaxyDustOpacity, _GalaxyCloudShadow, _GalaxyCloudBright;
float _GalaxyCloudFluffStrength, _GalaxyCloudFluffScale, _GalaxyCloudFluffWarp;
float4 _GalaxyColor1, _GalaxyColor2, _GalaxyColor3;
float _GalaxyDarkCloudColorBlend, _GalaxyCloudOuterFade;
float4 _GalaxyDarkBandColor;
float _GalaxyDarkBandColorBlend;
float _GalaxyBendAmount, _GalaxyBendFrequency, _GalaxyStarDensityBoost;
float _SmallGalaxyWidth, _SmallGalaxyOffset, _SmallGalaxyIntensity;
float4 _SmallGalaxyColor;
float _SmallGalaxyNoiseScale, _SmallGalaxyNoiseOctaves;
float _SmallGalaxyMaskStrength, _SmallGalaxyMaskScale, _SmallGalaxyMaskContrast;
float _SmallGalaxyMaskWarp, _SmallGalaxyMaskOffsetX, _SmallGalaxyMaskOffsetY;
float _SmallGalaxySharpness, _SmallGalaxyInvertMask;
int _MeteorCount;
float _MeteorSpeed, _MeteorLength, _MeteorIntensity;
float _MeteorDominantLongitude, _MeteorDominantLatitude;
float _MeteorDirectionWeight, _MeteorTailFalloff, _MeteorFrequency, _MeteorDiversity;
float _LensFlareIntensity;
float4 _LensFlareColor;
float _LensFlareSize, _LensFlareRotationSpeed;
float _DiskStepScale;
float _GlowStepScale;
float _CloudStepScale;
float _CaptureSoftness;
float _PhotonRingIntensity;
float _PhotonRingWidth;
float4 _PhotonRingColor;
float _PhotonRingInnerFade;
// ---- 喷流参数 ----
float _JetIntensity;
float4 _JetColor;
sampler2D _JetTexture;
float _JetSpeed;
float _JetLength;
float _JetConeAngle;
float _JetBaseRadius;
float _JetHoleRadius;
float _JetNoiseStrength;
float _JetNoiseScale;
float _JetNoiseVerticalScale;
float _JetEdgeSharpness;
// 旋进参数
float _JetPrecessionAngle;
float _JetPrecessionSpeed;
float _JetPrecessionPhase;
// 螺旋喷流开关
float _JetSpiral;
// 螺旋样式调节变量
float _JetSpiralTurns;
float _JetSpiralWidth;
float _JetSpiralRotationSpeed;
float _JetSpiralArms;
// 喷流起始端淡入长度
float _JetFadeIn;
float _GravityWaveStrength;
float _GravityWaveSpeed;
float _GravityWaveFreq;
struct appdata
{
float4 vertex : POSITION;
float3 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float3 viewDir : TEXCOORD0;
};
// ---------- 工具函数 ----------
float2x2 mm2(float a) { float c=cos(a), s=sin(a); return float2x2(c,s,-s,c); }
float tri(float x){ return clamp(abs(frac(x)-0.5),0.01,0.49); }
float2 tri2(float2 p){ return float2(tri(p.x)+tri(p.y), tri(p.y+tri(p.x))); }
float hash3(float3 p){ p=frac(p*0.1031); p+=dot(p,p.yzx+33.33); return frac((p.x+p.y)*p.z); }
float noise3d(float3 p){
float3 i=floor(p), f=frac(p); f=f*f*(3.0-2.0*f);
return lerp(lerp(lerp(hash3(i), hash3(i+float3(1,0,0)), f.x),
lerp(hash3(i+float3(0,1,0)), hash3(i+float3(1,1,0)), f.x), f.y),
lerp(lerp(hash3(i+float3(0,0,1)), hash3(i+float3(1,0,1)), f.x),
lerp(hash3(i+float3(0,1,1)), hash3(i+float3(1,1,1)), f.x), f.y), f.z);
}
float fbmWarp(float3 p, float warpAmt, int octaves)
{
float v=0.0, amp=0.5, prev=0.0;
float3 pos=p;
for (int loop=0; loop<octaves; loop++)
{
float n=noise3d(pos+prev*warpAmt);
v+=amp*n;
prev=n-0.5;
pos=pos*2.03+float3(1.7,9.2,4.3);
amp*=0.5;
}
return v*2.064516-0.3;
}
float fbm3D_combined(float3 p, out float n1, out float n2, out float n3)
{
float3 base=p;
float v=0.0, amp=0.5;
for (int i1=0; i1<3; i1++)
{
v += amp * noise3d(base);
base *= 2.03;
amp *= 0.5;
}
n1 = v;
float3 p2 = p * 1.7 + float3(10,20,30);
v=0; amp=0.5;
for (int i2=0; i2<3; i2++)
{
v += amp * noise3d(p2);
p2 *= 2.03;
amp *= 0.5;
}
n2 = v;
float3 p3 = p * 2.3 + float3(5,15,25);
v=0; amp=0.5;
for (int i3=0; i3<3; i3++)
{
v += amp * noise3d(p3);
p3 *= 2.03;
amp *= 0.5;
}
n3 = v;
return n1;
}
float2 hash2D(float2 p){ p=float2(dot(p,float2(127.1,311.7)), dot(p,float2(269.5,183.3))); return -1.0+2.0*frac(sin(p)*43758.5453123); }
float noise2D(float2 p){ float2 i=floor(p), f=frac(p), u=f*f*(3.0-2.0*f); return lerp(lerp(dot(hash2D(i+float2(0,0)), f-float2(0,0)), dot(hash2D(i+float2(1,0)), f-float2(1,0)), u.x), lerp(dot(hash2D(i+float2(0,1)), f-float2(0,1)), dot(hash2D(i+float2(1,1)), f-float2(1,1)), u.x), u.y); }
float fbm2D(float2 p, int oct){ float v=0, amp=0.5; for(int j=0;j<oct;j++){ v+=amp*noise2D(p); p*=2.0; amp*=0.5;} return v; }
float3 nmzHash33(float3 q){ uint3 p=uint3(int3(q)); p=p*uint3(374761393U,1103515245U,668265263U)+p.zxy+p.yzx; p=p.yzx*(p.zxy^(p>>3U)); return float3(p^(p>>16U))*(1.0/4294967295.0); }
float3 rotateY(float3 dir, float angle){ float s=sin(angle), c=cos(angle); return float3(c*dir.x+s*dir.z, dir.y, -s*dir.x+c*dir.z); }
float3 directionFromLatLong(float lonDeg, float latDeg){ float lon=radians(lonDeg), lat=radians(latDeg); return normalize(float3(sin(lon)*cos(lat), sin(lat), cos(lon)*cos(lat))); }
float sdSphere(float3 p, float s){ return length(p)-s; }
float sdTorus(float3 p, float2 t){ float2 q=float2(length(p.xz)-t.x, p.y); return length(q)-t.y; }
// ---------- 完整背景组件 ----------
float3 ComputeGalaxy(float3 dir)
{
float3 centerDir = directionFromLatLong(_GalaxyCenterLongitude, _GalaxyCenterLatitude);
float3 zAxis = centerDir;
float3 refUp = abs(zAxis.y)<0.99 ? float3(0,1,0) : float3(1,0,0);
float3 xAxis = normalize(cross(refUp,zAxis));
float3 yAxis = cross(zAxis,xAxis);
float tiltRad=radians(_GalaxyTilt);
float c=cos(tiltRad), s=sin(tiltRad);
float3 xRot=xAxis*c+yAxis*s; float3 yRot=-xAxis*s+yAxis*c;
xAxis=xRot; yAxis=yRot;
float lx=dot(dir,xAxis), ly=dot(dir,yAxis);
float2 p=float2(lx,ly)*_GalaxyBandScale;
float2 pCenter=p-float2(0.05,0.34);
float ang=0.42;
float2x2 rot=float2x2(cos(ang),sin(ang),-sin(ang),cos(ang));
pCenter=mul(rot,pCenter);
float2 pCenterOrig=pCenter;
pCenter.y*=_GalaxyWidthScale;
pCenter.y+=sin(pCenter.x*_GalaxyBendFrequency)*_GalaxyBendAmount;
float depth=dot(dir,zAxis)*_GalaxyBandScale*0.5;
float n1,n2,n3;
fbm3D_combined(float3(pCenter*_GalaxyCloudFluffScale, depth*_GalaxyCloudFluffScale*0.6), n1, n2, n3);
float wobble = 0.04 * n1;
float yPos = pCenter.y - wobble;
float width = 0.35 + 0.08*sin(pCenter.x*1.5+0.7);
float mainBand = exp(-(yPos*yPos)/(width*width*0.5));
float secondary = exp(-pow((yPos+0.03),2.0)/(width*width*0.3))*0.5;
mainBand = max(mainBand, secondary);
float cloudNoise = n1 * 0.6 + 0.4;
cloudNoise = lerp(1.0, cloudNoise, _GalaxyCloudFluffStrength);
float cloudFactor = cloudNoise * mainBand;
float darkWidth = 0.08+0.03*sin(pCenter.x*2.0+1.2);
float distDark = abs(yPos)/darkWidth;
float darkRaw = 1.0 - exp(-distDark*distDark*2.0);
float darkWarp = 0.02 * n2;
float yDark = pCenter.y - darkWarp;
float distDarkWarp = abs(yDark)/darkWidth;
float darkRawWarp = 1.0 - exp(-distDarkWarp*distDarkWarp*2.0);
darkRaw = min(darkRaw, darkRawWarp);
float darkMask = lerp(1.0, darkRaw, _GalaxyDustOpacity);
float darkOcclusion = 1.0 - darkMask;
float coreGlow = exp(-pCenterOrig.x*pCenterOrig.x*(3.0/_GalaxyCoreScale) - pCenterOrig.y*pCenterOrig.y*(20.0/_GalaxyCoreScale)) * _GalaxyCoreIntensity;
float coreShadow = 1.0 - darkOcclusion*0.8;
float cloudShadow = 1.0 - darkOcclusion*_GalaxyCloudShadow;
float coreBright = coreGlow * coreShadow;
float cloudBright = cloudFactor * cloudShadow;
float density = clamp(coreBright + cloudBright * _GalaxyCloudBright, 0.0, 1.0);
float3 lightColor=_GalaxyColor1.rgb, darkColor=_GalaxyColor2.rgb, cloudColor=_GalaxyColor3.rgb;
float darkCloudBlend = darkOcclusion * _GalaxyDarkCloudColorBlend;
float3 cloudCol = lerp(cloudColor, darkColor, darkCloudBlend);
float outerFade = 1.0 - smoothstep(0.0,0.5,abs(yPos)) * _GalaxyCloudOuterFade;
float3 col = lerp(darkColor, lightColor, density);
float cloudMix = abs(cloudNoise-1.0)*0.6*outerFade;
col = lerp(col, cloudCol, cloudMix*0.5);
float darkBandStrength = darkOcclusion;
col = lerp(col, _GalaxyDarkBandColor.rgb, darkBandStrength*_GalaxyDarkBandColorBlend);
col *= (0.8+0.2*darkMask);
col *= _GalaxyIntensity;
// 小星系
float smallWidth=_SmallGalaxyWidth, smallOffset=_SmallGalaxyOffset, smallIntensity=_SmallGalaxyIntensity;
float smallNoiseScale=_SmallGalaxyNoiseScale;
int smallOct=(int)_SmallGalaxyNoiseOctaves;
float2 smallPos1=pCenter+float2(0,smallOffset);
float2 smallPos2=pCenter-float2(0,smallOffset);
float smallNoise1=fbm2D(smallPos1*smallNoiseScale+float2(3,11), smallOct);
float smallNoise2=fbm2D(smallPos2*smallNoiseScale+float2(7,19), smallOct);
float smallBand1=exp(-(smallPos1.y*smallPos1.y)/(smallWidth*smallWidth*0.5));
float smallBand2=exp(-(smallPos2.y*smallPos2.y)/(smallWidth*smallWidth*0.5));
smallBand1*=(0.6+0.4*smallNoise1);
smallBand2*=(0.6+0.4*smallNoise2);
float smallBand=max(smallBand1,smallBand2);
float sharpness=_SmallGalaxySharpness;
float contrast=1.0+sharpness*10.0;
smallBand=saturate((smallBand-0.5)*contrast+0.5);
float2 maskUV=pCenter*_SmallGalaxyMaskScale+float2(13.0+_SmallGalaxyMaskOffsetX,7.0+_SmallGalaxyMaskOffsetY);
float maskWarpX=fbm2D(maskUV*0.8+float2(0.3,1.7),3)*_SmallGalaxyMaskWarp;
float maskWarpY=fbm2D(maskUV*0.8+float2(5.3,2.7),3)*_SmallGalaxyMaskWarp;
float2 warpedUV=maskUV+float2(maskWarpX,maskWarpY);
float rawMask=fbm2D(warpedUV,4);
float threshold=0.5-_SmallGalaxyMaskStrength*0.45;
float maskContrast=1.0+_SmallGalaxyMaskStrength*6.0;
float mask=saturate((rawMask-threshold)*maskContrast);
mask=saturate((mask-0.5)*_SmallGalaxyMaskContrast+0.5);
if (_SmallGalaxyInvertMask>0.5) mask=1.0-mask;
smallBand=lerp(smallBand, smallBand*(1.0-mask), _SmallGalaxyMaskStrength);
smallBand*=smallIntensity;
col+=smallBand*_SmallGalaxyColor.rgb;
float3 skyBase=float3(0.01,0.02,0.05);
return lerp(skyBase, col, density*0.95+0.05);
}
float3 ComputeNebula(float3 dir)
{
float rotAngle=_Time.y*_NebulaRotationSpeed;
dir=rotateY(dir,rotAngle);
float3 pos=dir*_NebulaScale;
pos.x*=1.2; pos.z*=1.2; pos.y*=_NebulaFlatten;
float warp=_NebulaWarp*0.8;
int oct=(int)(_NebulaDetail*4.0+2.0);
float n=fbmWarp(pos,warp,oct);
n=saturate(n*1.2+0.2);
float n2=fbmWarp(pos*1.7+float3(10,20,30), warp*0.5, max(oct-1,1));
n2=saturate(n2*1.1+0.1);
float detail=fbmWarp(pos*2.3+float3(5,15,25), warp*0.3, 3);
detail=saturate(detail*1.5);
float density=lerp(n, n*detail*0.6+n*0.4, _NebulaDetail);
density=pow(density, 1.0/_NebulaContrast);
float3 colA=lerp(_NebulaColor1.rgb,_NebulaColor2.rgb,n2);
float3 colB=lerp(colA,_NebulaColor3.rgb,smoothstep(0.3,0.8,density));
float3 col=lerp(colA,colB,density*0.8+0.2);
col*=(0.8+0.4*density);
col*=_NebulaIntensity*1.5;
float dark=fbmWarp(pos*1.3+float3(7,13,19), warp*0.2, 3);
dark=saturate(dark*1.0-0.2);
col*=(1.0-dark*0.3);
return col;
}
float3 ComputeStars(float3 dir)
{
float3 centerDir=directionFromLatLong(_GalaxyCenterLongitude,_GalaxyCenterLatitude);
float3 gzAxis=centerDir, gUp=abs(gzAxis.y)<0.99?float3(0,1,0):float3(1,0,0);
float3 gxAxis=normalize(cross(gUp,gzAxis)), gyAxis=cross(gzAxis,gxAxis);
float gTilt=radians(_GalaxyTilt), gc=cos(gTilt), gs=sin(gTilt);
float3 gxRot=gxAxis*gc+gyAxis*gs, gyRot=-gxAxis*gs+gyAxis*gc;
gxAxis=gxRot; gyAxis=gyRot;
float glx=dot(dir,gxAxis), gly=dot(dir,gyAxis);
float2 gp=float2(glx,gly)*_GalaxyBandScale;
float2 gpCenter=gp-float2(0.05,0.34);
float gang=0.42;
float2x2 grot=float2x2(cos(gang),sin(gang),-sin(gang),cos(gang));
gpCenter=mul(grot,gpCenter);
gpCenter.y*=_GalaxyWidthScale;
gpCenter.y+=sin(gpCenter.x*_GalaxyBendFrequency)*_GalaxyBendAmount;
float planeDist=abs(gpCenter.y);
float densityFactor=1.0+_GalaxyStarDensityBoost*exp(-planeDist*planeDist*10.0);
float rotAngle=_Time.y*_StarRotationSpeed;
dir=rotateY(dir,rotAngle);
float3 col=0;
float res=1024.0;
float glowIntensity=_StarGlowIntensity, glowRadius=_StarGlowRadius;
for (int iter=0; iter<4; iter++)
{
float i=float(iter);
float3 q=frac(dir*(0.15*res))-0.5;
float3 id=floor(dir*(0.15*res));
float3 rn=nmzHash33(id);
float dist=length(q);
float c2=1.0-smoothstep(0.0,0.6,dist);
float baseThreshold=0.0005+i*i*0.001;
float adjustedThreshold=baseThreshold*densityFactor;
c2*=step(rn.x, adjustedThreshold);
float twinkle=1.0+_StarTwinkleStrength*sin(_Time.y*_StarTwinkleSpeed+rn.z*6.28318);
c2*=twinkle;
float hueOld=rn.x*0.8+rn.y*0.2;
float3 colorOld=0.5+0.5*cos(6.28318*(hueOld+float3(0,0.33,0.67)));
float3 starColorOld=lerp(float3(1,1,1), colorOld, _StarColorfulIntensity);
starColorOld*=(0.8+0.4*rn.y);
float hueNew=frac(rn.x+rn.y*0.618+rn.z*0.303);
float sat=0.6+0.4*rn.y, bri=0.7+0.6*rn.z;
float3 colorNew=0.5+0.5*cos(6.28318*(hueNew+float3(0,0.33,0.67)));
colorNew=lerp(float3(0.5,0.5,0.5), colorNew, sat)*bri;
float3 starColorNew=lerp(float3(1,1,1), colorNew, _StarColorfulIntensity);
float3 starColor=lerp(starColorOld, starColorNew, _StarColorBlend);
float3 glowColor=starColor;
float3 starLight=starColor*c2;
float glowCore=exp(-dist*dist*glowRadius*12.0)*glowIntensity*1.5;
float glowMid=exp(-dist*dist*glowRadius*3.0)*glowIntensity*0.8;
float glowOut=exp(-dist*dist*glowRadius*0.6)*glowIntensity*0.5;
float glow=(glowCore+glowMid+glowOut)*step(rn.x,0.008+i*i*0.006);
float rainbow=0.5+0.5*cos(6.28318*(dist*2.0+rn.x+float3(0,0.33,0.67)));
glowColor=lerp(glowColor, glowColor*rainbow, 0.3);
float3 glowLight=glowColor*glow;
col+=starLight+glowLight;
dir*=1.3;
}
col*=_StarTintColor.rgb;
return col*col*0.8*_StarIntensity;
}
float rand(float2 co){ return frac(sin(dot(co,float2(12.9898,78.233)))*43758.5453); }
float3 randomDirection(float2 seed)
{
float z=rand(seed)*2.0-1.0;
float a=rand(seed+1.0)*6.2831853;
float r=sqrt(max(0.0,1.0-z*z));
return float3(r*cos(a),r*sin(a),z);
}
float3 ComputeMeteors(float3 dir, float time)
{
float3 col=0;
float3 dominantMoveDir=directionFromLatLong(_MeteorDominantLongitude,_MeteorDominantLatitude);
int maxMeteors=min(_MeteorCount,10);
for (int k=0; k<maxMeteors; k++)
{
float seed=float(k);
float timeOffset=rand(float2(seed,0.0))*100.0;
float cycleBase=3.0+rand(float2(seed,1.0))*10.0;
float freqRand=rand(float2(seed,2.0));
float meteorFreq=_MeteorFrequency*lerp(1.0-_MeteorDiversity*0.3, 1.0+_MeteorDiversity*0.3, freqRand);
float cyclePeriod=cycleBase/max(meteorFreq,0.001);
float localTime=time+timeOffset;
float timeInCycle=fmod(localTime,cyclePeriod);
float cycleID=floor(localTime/cyclePeriod);
float2 run_seed=float2(seed,cycleID);
float feature=rand(run_seed+600.0);
float speedRand=rand(run_seed+700.0);
float speedFactor=lerp(0.8,1.2,feature)+_MeteorDiversity*(speedRand-0.5)*0.4;
speedFactor=clamp(speedFactor,0.6,1.4);
float meteorSpeed=_MeteorSpeed*speedFactor;
meteorSpeed=max(meteorSpeed,0.001);
float lengthRand=rand(run_seed+800.0);
float lengthFactor=lerp(0.7,1.3,feature)+_MeteorDiversity*(lengthRand-0.5)*0.3;
lengthFactor=clamp(lengthFactor,0.5,1.5);
float meteorLen=_MeteorLength*lengthFactor;
meteorLen=max(meteorLen,0.0001);
float intensityRand=rand(run_seed+900.0);
float intensityFactor=lerp(0.6,1.4,feature)+_MeteorDiversity*(intensityRand-0.5)*0.3;
intensityFactor=clamp(intensityFactor,0.4,1.6);
float travelTime=meteorLen/meteorSpeed;
if (timeInCycle>travelTime) continue;
float a=timeInCycle/travelTime;
float3 randomMoveDir=randomDirection(run_seed+50.0);
float3 moveDir=lerp(randomMoveDir, dominantMoveDir, _MeteorDirectionWeight);
moveDir=normalize(moveDir);
float3 baseDir=randomDirection(run_seed+100.0);
baseDir=normalize(baseDir - moveDir*dot(baseDir,moveDir) + 1e-5);
float offset=(a-0.5)*meteorLen;
float3 headVec=baseDir+moveDir*offset;
float3 headDir=normalize(headVec);
float3 zAxis=headDir;
float3 xAxisVec=moveDir - zAxis*dot(moveDir,zAxis);
float3 xAxis=normalize(xAxisVec);
float3 yAxis=normalize(cross(zAxis,xAxis));
float3 local=float3(dot(dir,xAxis), dot(dir,yAxis), dot(dir,zAxis));
if (local.z<=0.0) continue;
float2 proj=local.xy/max(local.z,0.001);
float trailX=clamp(proj.x, -meteorLen, 0.0);
float distToTrail=length(proj-float2(trailX,0.0));
float width=0.002;
float lineMask=smoothstep(width,0.0,distToTrail);
float tailPos=saturate(1.0+trailX/meteorLen);
float brightness=pow(tailPos,_MeteorTailFalloff);
float fade=smoothstep(0.0,0.2,a)*smoothstep(1.0,0.8,a);
float3 meteorCol=float3(rand(run_seed+100.0), rand(run_seed+200.0), rand(run_seed+300.0));
meteorCol=normalize(meteorCol)*1.5;
col+=meteorCol*lineMask*brightness*fade*_MeteorIntensity*intensityFactor;
}
return col;
}
float3 ComputeLensFlare(float3 rd, float3 bhDir, float time)
{
float3 flareCenter=bhDir;
float cosAngle=dot(rd,flareCenter);
float angle=acos(clamp(cosAngle,-1.0,1.0));
float maxAngle=radians(30.0)/_LensFlareSize;
if (angle>=maxAngle) return 0;
float dist=angle/maxAngle;
float falloff=1.0-dist*dist;
float3 upLocal=abs(flareCenter.y)<0.99?float3(0,1,0):float3(1,0,0);
float3 xAxisLocal=normalize(cross(upLocal,flareCenter));
float3 yAxisLocal=cross(flareCenter,xAxisLocal);
float3 localDir=rd-flareCenter*cosAngle;
float lenLocal=length(localDir);
float azimuth=0.0;
if (lenLocal>0.001)
{
float2 proj=float2(dot(localDir,xAxisLocal), dot(localDir,yAxisLocal));
azimuth=atan2(proj.y,proj.x);
}
float rot=time*_LensFlareRotationSpeed;
azimuth+=rot;
float center=exp(-angle*angle*400.0)*2.0;
float rings=0.0;
for (int ri=1; ri<=3; ri++)
{
float ringAngle=radians(float(ri)*5.0)/_LensFlareSize;
float ringWidth=radians(1.5)/_LensFlareSize;
float ringVal=exp(-pow((angle-ringAngle)/ringWidth,2.0));
float3 ringColor=lerp(float3(1,0.8,0.6), float3(0.6,0.8,1), float(ri)/3.0);
rings+=ringVal*0.6*ringColor;
}
float rays=0.0;
int numRays=6;
for (int rj=0; rj<numRays; rj++)
{
float rayAngle=6.28318*float(rj)/float(numRays)+rot*0.5;
float diff=azimuth-rayAngle;
diff=atan2(sin(diff),cos(diff));
float rayVal=exp(-pow(diff*12.0,2.0))*exp(-angle*angle*80.0);
rays+=rayVal;
}
rays*=0.4;
float3 flareCol=(center+rings+rays)*falloff*_LensFlareIntensity;
return flareCol*_LensFlareColor.rgb;
}
// ---------- 顶点着色器 ----------
v2f vert(appdata v)
{
v2f o;
o.pos=UnityObjectToClipPos(v.vertex);
o.viewDir=v.texcoord;
return o;
}
// ---------- 片段着色器 ----------
float4 frag(v2f i) : SV_Target
{
float3 rd=normalize(i.viewDir);
float3 ro=0;
float3 bhDir=directionFromLatLong(_Longitude,_Latitude);
float angularRad=radians(_AngularDiameter)*0.5;
float bhRadius=_BlackHoleDistance*tan(angularRad);
// 构建黑洞局部坐标系
float3 zAxis=bhDir;
float3 up=abs(zAxis.y)<0.99?float3(0,1,0):float3(1,0,0);
float3 xAxis=normalize(cross(up,zAxis));
float3 yAxis=cross(zAxis,xAxis);
float rotRad=radians(_Rotation);
float3 xRot=xAxis*cos(rotRad)+yAxis*sin(rotRad);
float3 yRot=-xAxis*sin(rotRad)+yAxis*cos(rotRad);
xAxis=xRot; yAxis=yRot;
float tiltRad=radians(_Tilt);
float3 yTilt=yAxis*cos(tiltRad)+zAxis*sin(tiltRad);
float3 zTilt=-yAxis*sin(tiltRad)+zAxis*cos(tiltRad);
yAxis=yTilt; zAxis=zTilt;
float3x3 worldToLocal=float3x3(xAxis.x,xAxis.y,xAxis.z,
yAxis.x,yAxis.y,yAxis.z,
zAxis.x,zAxis.y,zAxis.z);
float3 localRo=mul(worldToLocal, ro-bhDir*_BlackHoleDistance);
float3 localRd=mul(worldToLocal, rd);
float bhmass=_MassScale*_MassCoefficient*bhRadius*bhRadius;
float maxDist=_BlackHoleDistance+14.0*bhRadius;
float dt=maxDist/max(_MaxSteps,1.0);
float3 p=localRo;
float3 pv=localRd;
float3 col=0;
float noncaptured=1.0;
float minDistToBH = 1e10;
float3 innerColor=_DiskInnerColor.rgb, outerColor=_DiskOuterColor.rgb;
float diskScale=_DiskRadiusScale;
float torusInner=diskScale*bhRadius;
float torusTubeRadius=(diskScale+1.9)*bhRadius*_TorusTubeRadius;
float cloudCenter=(diskScale+1.0)*bhRadius*_DiskCloudCenter;
float cloudWidth=(0.1875*diskScale)*bhRadius*_DiskCloudWidth;
float captureSoft = _CaptureSoftness * bhRadius;
// ===== 喷流轴定义(在局部坐标系中,沿Y轴,可旋进) =====
float3 localBaseAxis = float3(0,1,0);
float3 localPerp1 = float3(1,0,0);
float3 localPerp2 = float3(0,0,1);
float precessAngleRad = radians(_JetPrecessionAngle);
float precessSpeedRad = radians(_JetPrecessionSpeed);
float precessPhaseRad = radians(_JetPrecessionPhase);
float phi = _Time.y * precessSpeedRad + precessPhaseRad;
float sinPrecess = sin(precessAngleRad);
float3 localJetAxis = localBaseAxis * cos(precessAngleRad)
+ (localPerp1 * cos(phi) + localPerp2 * sin(phi)) * sinPrecess;
localJetAxis = normalize(localJetAxis);
// =============================================
// 局部正交向量(用于螺旋极角)
float3 localJetPerp1, localJetPerp2;
{
float3 arbitrary = abs(localJetAxis.y) < 0.99 ? float3(0,1,0) : float3(1,0,0);
localJetPerp1 = normalize(cross(localJetAxis, arbitrary));
localJetPerp2 = cross(localJetAxis, localJetPerp1);
}
// 锥形喷流参数
float jetConeRad = radians(_JetConeAngle);
float jetTan = tan(jetConeRad);
float jetHalfLen = _JetLength;
float jetBaseR = _JetBaseRadius;
float jetHoleRatio = _JetHoleRadius;
// 螺旋参数
float spiralFreq = 2.0 * 3.1415926 * _JetSpiralTurns / max(jetHalfLen, 0.001);
float spiralRotationSpeed = _JetSpiralRotationSpeed;
float spiralPhase = 0.0;
float spiralSigma = _JetSpiralWidth;
int spiralArms = (int)_JetSpiralArms;
int maxSteps = (int)_MaxSteps;
for (int s=0; s<maxSteps; s++)
{
float stepNoncaptured = noncaptured;
float ds = dt * stepNoncaptured;
p += pv * ds;
float currentDist = length(p);
if (currentDist < minDistToBH) minDistToBH = currentDist;
// ---- 引力弯曲 ----
float3 bhv=-p;
float r=dot(bhv,bhv);
float invR=rsqrt(max(r,0.0001));
float3 accel=bhv*(bhmass*invR*invR*invR);
pv+=accel*dt;
noncaptured=smoothstep(0.0,captureSoft,sdSphere(p,bhRadius));
if (noncaptured<0.001) break;
// ---- 吸积盘采样 ----
float distToBH=length(bhv);
float relDist=(distToBH-bhRadius)/max(bhRadius,0.0001);
float dr=length(bhv.xz);
// 原始角度(范围 -π 到 π),用于接缝淡出
float rawAngle = atan2(bhv.x, bhv.z);
float da = rawAngle;
if (da < 0.0) da += 6.2831853; // 0~2π 用于纹理坐标
// 计算角度接缝淡出因子
float angleDist = abs(rawAngle);
float fadeWidth = radians(_DiskAngularFade);
float angularFade = smoothstep(0.0, fadeWidth, angleDist); // 边界处为0
float2 ra=float2(dr, da*(0.01+(dr-bhRadius)*0.02)+_Time.y*_TimeScale*0.005);
ra*=float2(10.0,20.0)*_TextureScale*float2(0.1,0.5);
ra=frac(ra);
float texVal=tex2Dlod(_AccretionTex,float4(ra,0,0)).r;
float2 noiseUV=float2(dr*_NoiseScale, da*0.5+_Time.y*_TimeScale*0.01);
noiseUV=frac(noiseUV);
float noiseTex=tex2Dlod(_NoiseTex,float4(noiseUV,0,0)).r;
float combinedNoise = lerp(texVal,noiseTex,_NoiseStrength) * angularFade; // 乘以淡出
float diskFactor=4.0/(0.001+5.0*relDist);
diskFactor=min(diskFactor,5.0)*_DiskIntensity;
float noise=combinedNoise*0.7+0.3;
float3 dcol=lerp(innerColor,outerColor,relDist*relDist)*noise*diskFactor;
float torusDist=sdTorus(p*float3(1.0,_DiskTubeScale,1.0), float2(torusInner,torusTubeRadius));
float ringMask=smoothstep(0.0,1.0,-torusDist);
ringMask=lerp(step(0.0,-torusDist), ringMask, _DiskSoftness);
float3 velDir=normalize(pv);
float3 posDir=normalize(p);
float dopplerFactor=1.0+dot(velDir,posDir)*0.3;
float3 dopplerCol=dcol*(dopplerFactor>1.0?float3(1.0,0.9,0.8):float3(0.8,0.9,1.0));
col += dopplerCol * ringMask * ds * _DiskIntensity * _DiskStepScale;
float glow=1.0/(relDist*relDist+0.01);
glow=min(glow,10.0);
col += float3(1.0,0.9,0.85) * glow * ds * 0.005 * _GlowIntensity * _GlowStepScale;
float radial=length(p.xz);
float cloudIntensity=exp(-((radial-cloudCenter)*(radial-cloudCenter))/(cloudWidth*cloudWidth+0.0001));
cloudIntensity*=1.0-smoothstep(0.0,0.3*bhRadius,abs(p.y));
cloudIntensity*=(0.6+0.4*combinedNoise);
col += float3(1.0,0.85,0.7) * cloudIntensity * ds * 0.8 * _DiskIntensity * _CloudStepScale;
// ---- 体积喷流采样(双极圆锥,带旋进) ----
if (_JetIntensity > 0.001)
{
float h = dot(p, localJetAxis);
float absH = abs(h);
float3 proj = localJetAxis * h;
float r_perp = length(p - proj);
if (absH < jetHalfLen)
{
float radiusAtH = jetBaseR + absH * jetTan;
float holeAtH = absH * jetTan * jetHoleRatio;
if (r_perp < radiusAtH && r_perp > holeAtH)
{
float start = lerp(0.0, radiusAtH * 0.9, _JetEdgeSharpness);
float edgeFade = 1.0 - smoothstep(start, radiusAtH, r_perp);
// 使用可调属性 _JetFadeIn 控制底部淡入
float axialRise = smoothstep(0.0, max(_JetFadeIn, 0.001), absH);
float axialFall = 1.0 - smoothstep(0.0, jetHalfLen, absH);
float axialFade = axialRise * axialFall;
float density = edgeFade * axialFade;
if (_JetSpiral > 0.5)
{
float3 radVec = p - proj;
float theta = atan2(dot(radVec, localJetPerp2), dot(radVec, localJetPerp1));
float handedness = (h >= 0.0) ? 1.0 : -1.0;
float rotationSign = -1.0;
float minDiff = 3.1415926;
for (int arm = 0; arm < spiralArms; arm++)
{
float armAngle = spiralFreq * h
+ _Time.y * spiralRotationSpeed * handedness * rotationSign
+ spiralPhase
+ 2.0 * 3.1415926 * float(arm) / float(spiralArms);
float diff = theta - armAngle;
diff = atan2(sin(diff), cos(diff));
minDiff = min(minDiff, abs(diff));
}
float spiralFactor = exp(-(minDiff * minDiff) / (2.0 * spiralSigma * spiralSigma));
density *= spiralFactor;
}
// 3D 噪声
float3 noisePos = p * _JetNoiseScale;
noisePos.y *= _JetNoiseVerticalScale;
noisePos += float3(0, _Time.y * _JetSpeed * 0.5, 0);
float jetNoise = noise3d(noisePos) * 0.5 + 0.5;
jetNoise = lerp(0.5, jetNoise, _JetNoiseStrength);
density *= jetNoise;
// 纹理采样
float angle = atan2(p.x, p.z);
float2 jetUV = float2(angle / 6.2832 + 0.5, (h / jetHalfLen) * 0.5 + 0.5 + _Time.y * _JetSpeed * 0.1);
jetUV = frac(jetUV);
float jetTex = tex2Dlod(_JetTexture, float4(jetUV, 0, 0)).r;
jetTex = lerp(0.8, 1.0, jetTex);
float3 jetCol = _JetColor.rgb * jetTex * density * _JetIntensity;
col += jetCol * ds * 0.5;
}
}
}
}
// ---- 逃逸方向 ----
float3 escapeP=p, escapeV=pv;
float escapeStep=dt*0.5;
for (int i=0; i<30; i++)
{
float dist=length(escapeP);
if (dist>maxDist || noncaptured<0.01) break;
float3 bhv2=-escapeP;
float r2=dot(bhv2,bhv2);
escapeV+=normalize(bhv2)*(bhmass/r2)*escapeStep;
escapeP+=escapeV*escapeStep;
}
float3 escapedDir=normalize(escapeV);
float3 cameraEscapedDir=mul(transpose(worldToLocal), escapedDir);
// ---- 引力波扭曲 ----
if (_GravityWaveStrength > 0.0)
{
float3 upDir = abs(cameraEscapedDir.y) < 0.99 ? float3(0,1,0) : float3(1,0,0);
float3 rightDir = normalize(cross(cameraEscapedDir, upDir));
upDir = cross(rightDir, cameraEscapedDir);
float time = _Time.y * _GravityWaveSpeed;
float freq = _GravityWaveFreq;
float wave1 = sin(dot(cameraEscapedDir, rightDir) * freq + time) * _GravityWaveStrength;
float wave2 = cos(dot(cameraEscapedDir, upDir) * freq * 1.3 + time * 0.7) * _GravityWaveStrength;
cameraEscapedDir = normalize(cameraEscapedDir + rightDir * wave1 + upDir * wave2);
}
// ---- 光子环 ----
float photonRadius = 1.5 * bhRadius;
float distDiff = minDistToBH - photonRadius;
float ringFactor = exp(-(distDiff * distDiff) / (2.0 * _PhotonRingWidth * _PhotonRingWidth * bhRadius * bhRadius));
float innerFade = 1.0 - smoothstep(0.0, _PhotonRingInnerFade * bhRadius, minDistToBH - bhRadius);
float ringBrightness = ringFactor * innerFade * _PhotonRingIntensity;
float3 photonRingColor = _PhotonRingColor.rgb * ringBrightness;
// ---- 背景合成 ----
float3 bgCol = ComputeStars(cameraEscapedDir) + ComputeNebula(cameraEscapedDir);
float3 skyTex = texCUBE(_SkyboxCubemap, cameraEscapedDir).rgb * _SkyboxExposure;
bgCol = lerp(bgCol, skyTex, _SkyboxBlend);
bgCol += ComputeGalaxy(cameraEscapedDir);
float gradFactor = pow(1.0 - abs(cameraEscapedDir.y), _GradientPower);
float3 gradCol = lerp(_GradientBottomColor.rgb, _GradientTopColor.rgb, gradFactor);
bgCol = lerp(bgCol, gradCol, _GradientBlend);
// 引力透镜增亮
float3 toBH = bhDir;
float cosBeta = dot(escapedDir, toBH);
float beta = acos(clamp(cosBeta, -1.0, 1.0));
float alpha = beta * (1.0 + 2.0 * bhmass / (_BlackHoleDistance * _BlackHoleDistance));
float magnification = 1.0 + 0.5 * exp(-alpha * alpha * 200.0);
bgCol *= magnification;
float3 meteorCol = 0;
if (cameraEscapedDir.y > 0.0)
meteorCol = ComputeMeteors(cameraEscapedDir, _Time.y);
// ---- 最终合成 ----
float3 finalCol = bgCol * noncaptured + col * _Exposure + meteorCol + photonRingColor * noncaptured;
finalCol = max(finalCol, 0.0);
finalCol = finalCol / (1.0 + finalCol * 0.5);
float3 lensFlare = ComputeLensFlare(rd, bhDir, _Time.y);
finalCol += lensFlare;
return float4(finalCol, 1.0);
}
ENDCG
}
}
FallBack Off
}
复制成功
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删