Cut 10b: unified 3D flow field, sorted-tile volumetrics, GPU kite sparks, and capsule beams
This commit is contained in:
parent
42b17c168e
commit
ffe777b9d4
17 changed files with 3611 additions and 1203 deletions
|
|
@ -21,6 +21,11 @@ public partial class AtmosphereSystem : Node
|
|||
private CanvasLayer _filmGrainLayer = null!;
|
||||
private ColorRect _filmGrainRect = null!;
|
||||
private ShaderMaterial _filmGrainMat = null!;
|
||||
private Texture3Drd? _flowTexRd;
|
||||
private ImageTexture3D? _dummyFlowTex;
|
||||
private VolumetricCompositorEffect? _volumetricEffect;
|
||||
private Compositor? _compositor;
|
||||
private VolumetricEmitterPool _emitterPool = new();
|
||||
private bool _initialized;
|
||||
|
||||
public WorldEnvironment WorldEnvironment => _worldEnv;
|
||||
|
|
@ -29,6 +34,8 @@ public partial class AtmosphereSystem : Node
|
|||
public FogVolume ValleyFogVolume => _valleyFog;
|
||||
public CanvasLayer FilmGrainLayer => _filmGrainLayer;
|
||||
public AtmosphereLutBaker.BakedAtmosphere? CurrentBaked { get; private set; }
|
||||
public VolumetricCompositorEffect? VolumetricEffect => _volumetricEffect;
|
||||
public VolumetricEmitterPool EmitterPool => _emitterPool;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -122,6 +129,34 @@ public partial class AtmosphereSystem : Node
|
|||
Name = "WorldEnv",
|
||||
Environment = _env
|
||||
};
|
||||
|
||||
Vector3 defaultInvExtent = new(
|
||||
1f / (VolumetricCompositorEffect.FlowDimX * VolumetricCompositorEffect.FlowVoxelSizeMeters),
|
||||
1f / (VolumetricCompositorEffect.FlowDimY * VolumetricCompositorEffect.FlowVoxelSizeMeters),
|
||||
1f / (VolumetricCompositorEffect.FlowDimZ * VolumetricCompositorEffect.FlowVoxelSizeMeters));
|
||||
RegisterGlobalParamIfMissing("rtd_flow_origin", RenderingServer.GlobalShaderParameterType.Vec3, Vector3.Zero);
|
||||
RegisterGlobalParamIfMissing("rtd_flow_inv_extent", RenderingServer.GlobalShaderParameterType.Vec3, defaultInvExtent);
|
||||
|
||||
if (RenderingServer.GetRenderingDevice() is not null)
|
||||
{
|
||||
_flowTexRd = new Texture3Drd();
|
||||
RegisterGlobalParamIfMissing("rtd_flow_field", RenderingServer.GlobalShaderParameterType.Sampler3D, _flowTexRd);
|
||||
_volumetricEffect = new VolumetricCompositorEffect(_flowTexRd, _emitterPool);
|
||||
_compositor = new Compositor
|
||||
{
|
||||
CompositorEffects = new Godot.Collections.Array<CompositorEffect> { _volumetricEffect }
|
||||
};
|
||||
_worldEnv.Compositor = _compositor;
|
||||
}
|
||||
else
|
||||
{
|
||||
var dummyImg = Image.CreateEmpty(1, 1, false, Image.Format.Rgbah);
|
||||
dummyImg.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
|
||||
_dummyFlowTex = new ImageTexture3D();
|
||||
_dummyFlowTex.Create(Image.Format.Rgbah, 1, 1, 1, false, new Godot.Collections.Array<Image> { dummyImg });
|
||||
RegisterGlobalParamIfMissing("rtd_flow_field", RenderingServer.GlobalShaderParameterType.Sampler3D, _dummyFlowTex);
|
||||
}
|
||||
|
||||
AddChild(_worldEnv);
|
||||
|
||||
_sun = new DirectionalLight3D
|
||||
|
|
@ -233,5 +268,81 @@ public partial class AtmosphereSystem : Node
|
|||
_env.FogDensity = preset.DepthFogDensity;
|
||||
_env.FogAerialPerspective = preset.DepthFogAerialPerspective;
|
||||
_env.FogSunScatter = preset.DepthFogSunScatter;
|
||||
|
||||
if (_volumetricEffect is not null)
|
||||
{
|
||||
Color ambCol = new(
|
||||
MathF.Max(0.10f, haze.R * 0.55f),
|
||||
MathF.Max(0.12f, haze.G * 0.55f),
|
||||
MathF.Max(0.14f, haze.B * 0.58f));
|
||||
_volumetricEffect.SetAtmosphere(
|
||||
baked.SunDirection,
|
||||
baked.SunLightEnergy,
|
||||
baked.SunLightColor,
|
||||
ambCol,
|
||||
extinctionScale: mapKind == ArenaMapKind.Sion ? 0.58f : 0.52f);
|
||||
}
|
||||
}
|
||||
|
||||
public void BindEmitterPool(VolumetricEmitterPool pool)
|
||||
{
|
||||
_emitterPool = pool ?? throw new ArgumentNullException(nameof(pool));
|
||||
_volumetricEffect?.SetEmitterPool(pool);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_worldEnv is not null && GodotObject.IsInstanceValid(_worldEnv))
|
||||
{
|
||||
_worldEnv.Compositor = null;
|
||||
}
|
||||
if (_flowTexRd is not null)
|
||||
{
|
||||
_flowTexRd.TextureRdRid = new Rid();
|
||||
}
|
||||
if (AreFlowGlobalsRegistered && RenderingServer.Singleton is not null)
|
||||
{
|
||||
_dummyFlowTex ??= CreateDummyFlowTexture();
|
||||
RenderingServer.GlobalShaderParameterSet("rtd_flow_field", _dummyFlowTex);
|
||||
}
|
||||
if (_volumetricEffect is not null)
|
||||
{
|
||||
_volumetricEffect.Enabled = false;
|
||||
if (RenderingServer.GetRenderingDevice() is not null)
|
||||
{
|
||||
RenderingServer.CallOnRenderThread(Callable.From(_volumetricEffect.DisposeRdResources));
|
||||
RenderingServer.ForceSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ImageTexture3D CreateDummyFlowTexture()
|
||||
{
|
||||
var dummyImg = Image.CreateEmpty(1, 1, false, Image.Format.Rgbah);
|
||||
dummyImg.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
|
||||
var tex = new ImageTexture3D();
|
||||
tex.Create(Image.Format.Rgbah, 1, 1, 1, false, new Godot.Collections.Array<Image> { dummyImg });
|
||||
return tex;
|
||||
}
|
||||
|
||||
private static readonly System.Collections.Generic.HashSet<string> RegisteredGlobals = new();
|
||||
public static bool AreFlowGlobalsRegistered =>
|
||||
RegisteredGlobals.Contains("rtd_flow_field") &&
|
||||
RegisteredGlobals.Contains("rtd_flow_origin") &&
|
||||
RegisteredGlobals.Contains("rtd_flow_inv_extent");
|
||||
|
||||
private static void RegisterGlobalParamIfMissing(
|
||||
StringName name,
|
||||
RenderingServer.GlobalShaderParameterType type,
|
||||
Variant defaultValue)
|
||||
{
|
||||
string key = name.ToString();
|
||||
if (RegisteredGlobals.Contains(key))
|
||||
{
|
||||
RenderingServer.GlobalShaderParameterSet(name, defaultValue);
|
||||
return;
|
||||
}
|
||||
RegisteredGlobals.Add(key);
|
||||
RenderingServer.GlobalShaderParameterAdd(name, type, defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue