Add D3D12 medium temporal identity
This commit is contained in:
parent
9a3f526b6b
commit
408eddc024
6 changed files with 57 additions and 10 deletions
|
|
@ -51,6 +51,7 @@ static const float SUN_RADIUS = 1.12;
|
|||
static const int PLANET_COUNT = 5;
|
||||
static const float FIELD_ID_GRID = 1.0;
|
||||
static const float FIELD_ID_SELF = 2.0;
|
||||
static const float FIELD_ID_MEDIUM = 3.0;
|
||||
static const float FIELD_ID_PLANET_BASE = 10.0;
|
||||
static const float MAX_HISTORY_AGE = 32.0;
|
||||
|
||||
|
|
@ -95,6 +96,11 @@ float3 debugFieldIdColor(float fieldId)
|
|||
return float3(1.0, 0.92, 0.25);
|
||||
}
|
||||
|
||||
if (abs(fieldId - FIELD_ID_MEDIUM) < 0.25)
|
||||
{
|
||||
return float3(0.28, 0.72, 1.0);
|
||||
}
|
||||
|
||||
if (fieldId >= 10.0)
|
||||
{
|
||||
float phase = frac((fieldId - 10.0) * 0.37);
|
||||
|
|
@ -309,6 +315,7 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float currentReactive = saturate(currentControl.x);
|
||||
float currentCoverage = saturate(currentControl.y);
|
||||
float currentMediumOpacity = saturate(currentControl.z);
|
||||
bool currentIsMedium = abs(currentFieldId - FIELD_ID_MEDIUM) < 0.25;
|
||||
|
||||
float historyWeight = 0.0;
|
||||
float historyAge = 0.0;
|
||||
|
|
@ -337,7 +344,11 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float travelWeight = 1.0 - smoothstep(travelTolerance, travelTolerance * 4.0, travelDelta);
|
||||
float fieldWeight = abs(previousFieldId - currentFieldId) < 0.001 ? 1.0 : 0.0;
|
||||
float normalWeight = 0.0;
|
||||
if (dot(previousNormal, previousNormal) > 0.01 && dot(currentNormal, currentNormal) > 0.01)
|
||||
if (currentIsMedium)
|
||||
{
|
||||
normalWeight = 1.0;
|
||||
}
|
||||
else if (dot(previousNormal, previousNormal) > 0.01 && dot(currentNormal, currentNormal) > 0.01)
|
||||
{
|
||||
normalWeight = smoothstep(0.68, 0.96, dot(normalize(previousNormal), normalize(currentNormal)));
|
||||
}
|
||||
|
|
@ -345,9 +356,9 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float3 neighborhoodMin;
|
||||
float3 neighborhoodMax;
|
||||
currentNeighborhood(input.uv, neighborhoodMin, neighborhoodMax);
|
||||
float3 clampedHistory = clamp(previous.rgb, neighborhoodMin, neighborhoodMax);
|
||||
float3 clampedHistory = currentIsMedium ? previous.rgb : clamp(previous.rgb, neighborhoodMin, neighborhoodMax);
|
||||
float colorDelta = length(clampedHistory - currentColor);
|
||||
float colorWeight = 1.0 - smoothstep(0.18, 1.2, colorDelta);
|
||||
float colorWeight = currentIsMedium ? 1.0 - smoothstep(0.35, 1.6, colorDelta) : 1.0 - smoothstep(0.18, 1.2, colorDelta);
|
||||
float reactiveWeight = 1.0 - currentReactive;
|
||||
float coverageWeight = smoothstep(0.02, 0.55, currentCoverage);
|
||||
float coverageContinuityWeight = 1.0 - smoothstep(0.10, 0.50, abs(previousCoverage - currentCoverage));
|
||||
|
|
@ -356,7 +367,9 @@ ResolveOut D3D12ResolvePS(VertexOut input)
|
|||
float validationWeight = travelWeight * colorWeight * fieldWeight * normalWeight * reactiveWeight * coverageWeight * coverageContinuityWeight * mediumContinuityWeight;
|
||||
|
||||
historyColor = clampedHistory;
|
||||
historyWeight = 0.82 * lerp(0.35, 1.0, historyConfidence) * validationWeight;
|
||||
float maxHistoryWeight = currentIsMedium ? 0.88 : 0.82;
|
||||
float freshHistoryScale = currentIsMedium ? 0.48 : 0.35;
|
||||
historyWeight = maxHistoryWeight * lerp(freshHistoryScale, 1.0, historyConfidence) * validationWeight;
|
||||
historyAge = validationWeight > 0.01 ? min(previousHistoryAge + 1.0, MAX_HISTORY_AGE) : 0.0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ static const int PLANET_COUNT = 5;
|
|||
static const float SUN_RADIUS = 1.12;
|
||||
static const float FIELD_ID_GRID = 1.0;
|
||||
static const float FIELD_ID_SELF = 2.0;
|
||||
static const float FIELD_ID_MEDIUM = 3.0;
|
||||
static const float FIELD_ID_PLANET_BASE = 10.0;
|
||||
static const int MEDIUM_FROXEL_ATLAS_COLUMNS = 8;
|
||||
static const int MEDIUM_FROXEL_ATLAS_ROWS = 4;
|
||||
|
|
@ -176,16 +177,20 @@ float mediumSliceTravel(int sliceIndex)
|
|||
return t * farDistance;
|
||||
}
|
||||
|
||||
void integrateMedium(float2 uv, float maxTravel, out float densityMean, out float transmittance, out float3 inScattering)
|
||||
void integrateMedium(float2 uv, float maxTravel, out float densityMean, out float transmittance, out float3 inScattering, out float representativeTravel)
|
||||
{
|
||||
densityMean = 0.0;
|
||||
transmittance = 1.0;
|
||||
inScattering = 0.0;
|
||||
representativeTravel = maxTravel;
|
||||
float densityTravelSum = 0.0;
|
||||
float densitySum = 0.0;
|
||||
|
||||
[loop]
|
||||
for (int sliceIndex = 0; sliceIndex < MEDIUM_FROXEL_SLICE_COUNT; sliceIndex++)
|
||||
{
|
||||
if (mediumSliceTravel(sliceIndex) > maxTravel)
|
||||
float sliceTravel = mediumSliceTravel(sliceIndex);
|
||||
if (sliceTravel > maxTravel)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -194,11 +199,17 @@ void integrateMedium(float2 uv, float maxTravel, out float densityMean, out floa
|
|||
float4 diagnostic = mediumVolumeTexture.SampleLevel(gridSampler, atlasUv, 0.0);
|
||||
float4 transport = mediumTransportTexture.SampleLevel(gridSampler, atlasUv, 0.0);
|
||||
densityMean += diagnostic.x;
|
||||
densityTravelSum += diagnostic.x * sliceTravel;
|
||||
densitySum += diagnostic.x;
|
||||
inScattering += transmittance * transport.rgb;
|
||||
transmittance *= saturate(transport.a);
|
||||
}
|
||||
|
||||
densityMean = saturate(densityMean / (float)MEDIUM_FROXEL_SLICE_COUNT);
|
||||
if (densitySum > 0.0001)
|
||||
{
|
||||
representativeTravel = densityTravelSum / densitySum;
|
||||
}
|
||||
}
|
||||
|
||||
float3 shadeBody(float3 p, float3 normal, int primitiveId)
|
||||
|
|
@ -257,9 +268,18 @@ SceneOut D3D12ScenePS(VertexOut input)
|
|||
float densityMean;
|
||||
float transmittance;
|
||||
float3 inScattering;
|
||||
float mediumRepresentativeTravel;
|
||||
float mediumTravel = travel <= farDistance ? travel : farDistance;
|
||||
integrateMedium(input.uv, mediumTravel, densityMean, transmittance, inScattering);
|
||||
integrateMedium(input.uv, mediumTravel, densityMean, transmittance, inScattering, mediumRepresentativeTravel);
|
||||
color = color * transmittance + inScattering;
|
||||
float mediumOpacity = saturate(1.0 - transmittance);
|
||||
if (outputFieldId < 0.5 && mediumOpacity > 0.015)
|
||||
{
|
||||
outputFieldId = FIELD_ID_MEDIUM;
|
||||
outputNormal = -rayDirection;
|
||||
outputCoverage = saturate(max(mediumOpacity, densityMean * 4.0));
|
||||
travel = min(mediumRepresentativeTravel, farDistance);
|
||||
}
|
||||
|
||||
if (renderDebugMode >= 10.5 && renderDebugMode < 11.5)
|
||||
{
|
||||
|
|
@ -269,6 +289,6 @@ SceneOut D3D12ScenePS(VertexOut input)
|
|||
SceneOut output;
|
||||
output.colorTravel = float4(color, min(travel, farDistance + 1.0));
|
||||
output.metadata = float4(outputFieldId, outputNormal);
|
||||
output.control = float4(0.0, outputCoverage, saturate(1.0 - transmittance), densityMean);
|
||||
output.control = float4(0.0, outputCoverage, mediumOpacity, densityMean);
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue