Gate volumetric medium composition
This commit is contained in:
parent
18ef6c0a5e
commit
8593f3be56
12 changed files with 89 additions and 27 deletions
|
|
@ -4,7 +4,8 @@ public readonly record struct GraphicsSettings(
|
|||
int RenderDebugMode,
|
||||
float SceneExposure,
|
||||
float BloomIntensity,
|
||||
float BloomVeilIntensity)
|
||||
float BloomVeilIntensity,
|
||||
float MediumCompositeIntensity)
|
||||
{
|
||||
public const int MinRenderDebugMode = 0;
|
||||
public const int MaxRenderDebugMode = 11;
|
||||
|
|
@ -14,12 +15,15 @@ public readonly record struct GraphicsSettings(
|
|||
public const float MaxBloomIntensity = 0.24f;
|
||||
public const float MinBloomVeilIntensity = 0.0f;
|
||||
public const float MaxBloomVeilIntensity = 0.08f;
|
||||
public const float MinMediumCompositeIntensity = 0.0f;
|
||||
public const float MaxMediumCompositeIntensity = 1.0f;
|
||||
|
||||
public static GraphicsSettings Default { get; } = new(
|
||||
RenderDebugMode: 0,
|
||||
SceneExposure: 0.16f,
|
||||
BloomIntensity: 0.072f,
|
||||
BloomVeilIntensity: 0.014f);
|
||||
BloomVeilIntensity: 0.014f,
|
||||
MediumCompositeIntensity: 0.0f);
|
||||
|
||||
public GraphicsSettings Normalized()
|
||||
{
|
||||
|
|
@ -27,6 +31,7 @@ public readonly record struct GraphicsSettings(
|
|||
Math.Clamp(RenderDebugMode, MinRenderDebugMode, MaxRenderDebugMode),
|
||||
Math.Clamp(SceneExposure, MinSceneExposure, MaxSceneExposure),
|
||||
Math.Clamp(BloomIntensity, MinBloomIntensity, MaxBloomIntensity),
|
||||
Math.Clamp(BloomVeilIntensity, MinBloomVeilIntensity, MaxBloomVeilIntensity));
|
||||
Math.Clamp(BloomVeilIntensity, MinBloomVeilIntensity, MaxBloomVeilIntensity),
|
||||
Math.Clamp(MediumCompositeIntensity, MinMediumCompositeIntensity, MaxMediumCompositeIntensity));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ public sealed class AquariumCultStateStore : IDisposable
|
|||
state.SceneExposure = normalized.SceneExposure;
|
||||
state.BloomIntensity = normalized.BloomIntensity;
|
||||
state.BloomVeilIntensity = normalized.BloomVeilIntensity;
|
||||
state.MediumCompositeIntensity = normalized.MediumCompositeIntensity;
|
||||
state.SaveGeneration++;
|
||||
cache.AddAsync(state, new CultRecordHandle<AquariumGraphicsSettingsState>(GraphicsSettingsKey)).GetAwaiter().GetResult();
|
||||
backingStore.PushAll();
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ public sealed class AquariumGraphicsSettingsState
|
|||
public float BloomVeilIntensity { get; set; } = GraphicsSettings.Default.BloomVeilIntensity;
|
||||
|
||||
[Key(5)]
|
||||
public float MediumCompositeIntensity { get; set; } = GraphicsSettings.Default.MediumCompositeIntensity;
|
||||
|
||||
[Key(6)]
|
||||
public long SaveGeneration { get; set; }
|
||||
|
||||
public static AquariumGraphicsSettingsState FromSettings(GraphicsSettings settings)
|
||||
|
|
@ -36,12 +39,13 @@ public sealed class AquariumGraphicsSettingsState
|
|||
RenderDebugMode = normalized.RenderDebugMode,
|
||||
SceneExposure = normalized.SceneExposure,
|
||||
BloomIntensity = normalized.BloomIntensity,
|
||||
BloomVeilIntensity = normalized.BloomVeilIntensity
|
||||
BloomVeilIntensity = normalized.BloomVeilIntensity,
|
||||
MediumCompositeIntensity = normalized.MediumCompositeIntensity
|
||||
};
|
||||
}
|
||||
|
||||
public GraphicsSettings ToSettings()
|
||||
{
|
||||
return new GraphicsSettings(RenderDebugMode, SceneExposure, BloomIntensity, BloomVeilIntensity).Normalized();
|
||||
return new GraphicsSettings(RenderDebugMode, SceneExposure, BloomIntensity, BloomVeilIntensity, MediumCompositeIntensity).Normalized();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@ public sealed class D3D11Renderer : IDisposable
|
|||
private readonly ID3D11Texture2D mediumVolumeTexture;
|
||||
private readonly ID3D11RenderTargetView mediumVolumeRenderTargetView;
|
||||
private readonly ID3D11ShaderResourceView mediumVolumeShaderResourceView;
|
||||
private readonly ID3D11Texture2D mediumTransportTexture;
|
||||
private readonly ID3D11RenderTargetView mediumTransportRenderTargetView;
|
||||
private readonly ID3D11ShaderResourceView mediumTransportShaderResourceView;
|
||||
private readonly ID3D11Texture2D[] bloomTextures = new ID3D11Texture2D[BloomLevelCount];
|
||||
private readonly ID3D11RenderTargetView[] bloomRenderTargetViews = new ID3D11RenderTargetView[BloomLevelCount];
|
||||
private readonly ID3D11ShaderResourceView[] bloomShaderResourceViews = new ID3D11ShaderResourceView[BloomLevelCount];
|
||||
|
|
@ -205,6 +208,9 @@ public sealed class D3D11Renderer : IDisposable
|
|||
mediumVolumeTexture = CreateHdrTexture(mediumVolumeWidth, mediumVolumeHeight);
|
||||
mediumVolumeRenderTargetView = device.CreateRenderTargetView(mediumVolumeTexture);
|
||||
mediumVolumeShaderResourceView = device.CreateShaderResourceView(mediumVolumeTexture);
|
||||
mediumTransportTexture = CreateHdrTexture(mediumVolumeWidth, mediumVolumeHeight);
|
||||
mediumTransportRenderTargetView = device.CreateRenderTargetView(mediumTransportTexture);
|
||||
mediumTransportShaderResourceView = device.CreateShaderResourceView(mediumTransportTexture);
|
||||
for (var level = 0; level < BloomLevelCount; level++)
|
||||
{
|
||||
var divisor = 1 << (level + 1);
|
||||
|
|
@ -326,7 +332,8 @@ public sealed class D3D11Renderer : IDisposable
|
|||
SceneExposure,
|
||||
BloomIntensity,
|
||||
BloomVeilIntensity,
|
||||
(float2)Vector2.Zero);
|
||||
MediumCompositeIntensity,
|
||||
0.0f);
|
||||
|
||||
BuildFroxelPrimitiveTable(frame);
|
||||
BuildFieldInstanceTable(frame);
|
||||
|
|
@ -357,6 +364,8 @@ public sealed class D3D11Renderer : IDisposable
|
|||
|
||||
public float BloomVeilIntensity { get; set; } = GraphicsSettings.Default.BloomVeilIntensity;
|
||||
|
||||
public float MediumCompositeIntensity { get; set; } = GraphicsSettings.Default.MediumCompositeIntensity;
|
||||
|
||||
public bool DebugUiVisible
|
||||
{
|
||||
get => debugUi.IsVisible;
|
||||
|
|
@ -375,7 +384,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
|
||||
public GraphicsSettings CaptureGraphicsSettings()
|
||||
{
|
||||
return new GraphicsSettings(RenderDebugMode, SceneExposure, BloomIntensity, BloomVeilIntensity).Normalized();
|
||||
return new GraphicsSettings(RenderDebugMode, SceneExposure, BloomIntensity, BloomVeilIntensity, MediumCompositeIntensity).Normalized();
|
||||
}
|
||||
|
||||
public void ApplyGraphicsSettings(GraphicsSettings settings)
|
||||
|
|
@ -385,6 +394,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
SceneExposure = normalized.SceneExposure;
|
||||
BloomIntensity = normalized.BloomIntensity;
|
||||
BloomVeilIntensity = normalized.BloomVeilIntensity;
|
||||
MediumCompositeIntensity = normalized.MediumCompositeIntensity;
|
||||
}
|
||||
|
||||
private DebugUi CreateDebugUi()
|
||||
|
|
@ -397,7 +407,9 @@ public sealed class D3D11Renderer : IDisposable
|
|||
.Section("HDR")
|
||||
.Slider("Exposure", () => SceneExposure, value => SceneExposure = Math.Clamp(value, GraphicsSettings.MinSceneExposure, GraphicsSettings.MaxSceneExposure), GraphicsSettings.MinSceneExposure, GraphicsSettings.MaxSceneExposure, "0.###", "Manual scene exposure before display transform.")
|
||||
.Slider("Bloom Intensity", () => BloomIntensity, value => BloomIntensity = Math.Clamp(value, GraphicsSettings.MinBloomIntensity, GraphicsSettings.MaxBloomIntensity), GraphicsSettings.MinBloomIntensity, GraphicsSettings.MaxBloomIntensity, "0.###", "Strength of pre-tonemap bloom energy.")
|
||||
.Slider("Bloom Veil", () => BloomVeilIntensity, value => BloomVeilIntensity = Math.Clamp(value, GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity), GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity, "0.###", "Low-frequency veil from bright HDR energy."));
|
||||
.Slider("Bloom Veil", () => BloomVeilIntensity, value => BloomVeilIntensity = Math.Clamp(value, GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity), GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity, "0.###", "Low-frequency veil from bright HDR energy.")
|
||||
.Section("Medium")
|
||||
.Slider("Composite", () => MediumCompositeIntensity, value => MediumCompositeIntensity = Math.Clamp(value, GraphicsSettings.MinMediumCompositeIntensity, GraphicsSettings.MaxMediumCompositeIntensity), GraphicsSettings.MinMediumCompositeIntensity, GraphicsSettings.MaxMediumCompositeIntensity, "0.###", "Blends registered medium transport into the final scene."));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -448,6 +460,9 @@ public sealed class D3D11Renderer : IDisposable
|
|||
mediumVolumeShaderResourceView.Dispose();
|
||||
mediumVolumeRenderTargetView.Dispose();
|
||||
mediumVolumeTexture.Dispose();
|
||||
mediumTransportShaderResourceView.Dispose();
|
||||
mediumTransportRenderTargetView.Dispose();
|
||||
mediumTransportTexture.Dispose();
|
||||
sceneMetadataShaderResourceView.Dispose();
|
||||
sceneMetadataRenderTargetView.Dispose();
|
||||
sceneMetadataTexture.Dispose();
|
||||
|
|
@ -544,7 +559,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSUnsetShaderResource(11);
|
||||
context.PSUnsetShaderResource(12);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.PSUnsetShaderResource(14);
|
||||
context.OMSetRenderTargets(gridHeightRenderTargetView);
|
||||
context.RSSetViewport(0.0f, 0.0f, GridHeightTextureSize, GridHeightTextureSize, 0.0f, 1.0f);
|
||||
context.ClearRenderTargetView(gridHeightRenderTargetView, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
|
|
@ -560,9 +575,11 @@ public sealed class D3D11Renderer : IDisposable
|
|||
{
|
||||
context.PSUnsetShaderResource(12);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.OMSetRenderTargets(mediumVolumeRenderTargetView);
|
||||
context.PSUnsetShaderResource(14);
|
||||
context.OMSetRenderTargets(new[] { mediumVolumeRenderTargetView, mediumTransportRenderTargetView });
|
||||
context.RSSetViewport(0.0f, 0.0f, mediumVolumeWidth, mediumVolumeHeight, 0.0f, 1.0f);
|
||||
context.ClearRenderTargetView(mediumVolumeRenderTargetView, new Color4(0.0f, 1.0f, 0.0f, 0.0f));
|
||||
context.ClearRenderTargetView(mediumTransportRenderTargetView, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
context.IASetInputLayout(null);
|
||||
context.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
|
||||
context.VSSetShader(vertexShader);
|
||||
|
|
@ -585,6 +602,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSUnsetShaderResource(10);
|
||||
context.PSUnsetShaderResource(11);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.PSUnsetShaderResource(14);
|
||||
context.OMSetRenderTargets(new[] { sceneRenderTargetView, sceneMetadataRenderTargetView, sceneControlRenderTargetView });
|
||||
context.RSSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f);
|
||||
context.ClearRenderTargetView(sceneRenderTargetView, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
|
|
@ -600,6 +618,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSSetShaderResource(2, ditherShaderResourceView);
|
||||
context.PSSetShaderResource(12, fieldInstanceShaderResourceView);
|
||||
context.PSSetShaderResource(13, mediumVolumeShaderResourceView);
|
||||
context.PSSetShaderResource(14, mediumTransportShaderResourceView);
|
||||
context.PSSetSampler(0, gridSampler);
|
||||
context.PSSetSampler(1, ditherSampler);
|
||||
context.Draw(3, 0);
|
||||
|
|
@ -611,6 +630,8 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSUnsetShaderResource(10);
|
||||
context.PSUnsetShaderResource(11);
|
||||
context.PSUnsetShaderResource(12);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.PSUnsetShaderResource(14);
|
||||
|
||||
for (var level = 0; level < BloomLevelCount; level++)
|
||||
{
|
||||
|
|
@ -674,6 +695,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSUnsetShaderResource(10);
|
||||
context.PSUnsetShaderResource(11);
|
||||
context.PSUnsetShaderResource(13);
|
||||
context.PSUnsetShaderResource(14);
|
||||
context.OMSetRenderTargets(new[] { renderTargetView, historyWriteView, historyMetadataWriteView, historyControlWriteView });
|
||||
context.RSSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f);
|
||||
context.ClearRenderTargetView(renderTargetView, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
|
@ -692,6 +714,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
context.PSSetShaderResource(10, bloomShaderResourceViews[1]);
|
||||
context.PSSetShaderResource(11, bloomShaderResourceViews[2]);
|
||||
context.PSSetShaderResource(13, mediumVolumeShaderResourceView);
|
||||
context.PSSetShaderResource(14, mediumTransportShaderResourceView);
|
||||
context.PSSetSampler(0, gridSampler);
|
||||
context.Draw(3, 0);
|
||||
}
|
||||
|
|
@ -1043,7 +1066,8 @@ public sealed class D3D11Renderer : IDisposable
|
|||
float Exposure,
|
||||
float BloomIntensity,
|
||||
float BloomVeilIntensity,
|
||||
float2 Padding);
|
||||
float MediumCompositeIntensity,
|
||||
float Padding);
|
||||
|
||||
private readonly record struct FroxelCell(int X, int Y, int Z);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ cbuffer AquariumFrame : register(b0)
|
|||
float exposure;
|
||||
float bloomIntensity;
|
||||
float bloomVeilIntensity;
|
||||
float2 presentationPadding;
|
||||
float mediumCompositeIntensity;
|
||||
float presentationPadding;
|
||||
};
|
||||
|
||||
Texture2D<float4> gridHeightTexture : register(t0);
|
||||
|
|
@ -33,6 +34,7 @@ Texture2D<float4> bloomTexture0 : register(t9);
|
|||
Texture2D<float4> bloomTexture1 : register(t10);
|
||||
Texture2D<float4> bloomTexture2 : register(t11);
|
||||
Texture2D<float4> mediumVolumeTexture : register(t13);
|
||||
Texture2D<float4> mediumTransportTexture : register(t14);
|
||||
|
||||
struct FieldInstance
|
||||
{
|
||||
|
|
@ -462,6 +464,11 @@ float4 sampleMediumVolume(float2 uv)
|
|||
return mediumVolumeTexture.SampleLevel(gridSampler, uv, 0.0);
|
||||
}
|
||||
|
||||
float4 sampleMediumTransport(float2 uv)
|
||||
{
|
||||
return mediumTransportTexture.SampleLevel(gridSampler, uv, 0.0);
|
||||
}
|
||||
|
||||
void cloudFieldInfo(int index, out float3 center, out float3 radius, out float3 tint, out float densityScale)
|
||||
{
|
||||
float slowTime = timeSeconds * 0.035;
|
||||
|
|
@ -1444,7 +1451,13 @@ struct SceneOut
|
|||
float4 control : SV_Target2;
|
||||
};
|
||||
|
||||
float4 MediumVolumePS(VertexOut input) : SV_Target
|
||||
struct MediumVolumeOut
|
||||
{
|
||||
float4 diagnostic : SV_Target0;
|
||||
float4 transport : SV_Target1;
|
||||
};
|
||||
|
||||
MediumVolumeOut MediumVolumePS(VertexOut input)
|
||||
{
|
||||
float2 screenUv = float2(input.uv.x, 1.0 - input.uv.y);
|
||||
float2 pixel = screenUv * resolution;
|
||||
|
|
@ -1457,7 +1470,10 @@ float4 MediumVolumePS(VertexOut input) : SV_Target
|
|||
|
||||
float densityDebug = saturate(densityIntegral * 0.18);
|
||||
float sourceDebug = saturate(dot(inScattering, float3(0.2126, 0.7152, 0.0722)) * 0.65);
|
||||
return float4(densityDebug, saturate(transmittance), sourceDebug, 1.0);
|
||||
MediumVolumeOut output;
|
||||
output.diagnostic = float4(densityDebug, saturate(transmittance), sourceDebug, 1.0);
|
||||
output.transport = float4(inScattering, saturate(transmittance));
|
||||
return output;
|
||||
}
|
||||
|
||||
SceneOut AquariumScenePS(VertexOut input)
|
||||
|
|
@ -1709,7 +1725,10 @@ ResolveOut AquariumResolvePS(VertexOut input)
|
|||
}
|
||||
}
|
||||
|
||||
float3 resolved = currentColor;
|
||||
float4 mediumTransport = sampleMediumTransport(input.uv);
|
||||
float mediumBlend = saturate(mediumCompositeIntensity);
|
||||
float mediumTransmittance = lerp(1.0, saturate(mediumTransport.a), mediumBlend);
|
||||
float3 resolved = currentColor * mediumTransmittance + mediumTransport.rgb * mediumBlend;
|
||||
|
||||
float3 exposedColor = exposeSceneColor(resolved);
|
||||
float3 bloomColor =
|
||||
|
|
|
|||
Loading…
Reference in a new issue