Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ float4 BurleyNormalizedSS(uint2 DTid, float2 texCoord, uint eyeIndex, float sssA
}

float4 surfaceAlbedo = AlbedoTexture[DTid];
float3 originalColor = Color::GammaToLinear(centerColor.xyz / max(surfaceAlbedo.xyz, EPSILON_SSS_ALBEDO));
float3 originalColor = Color::GammaToLinear(centerColor.xyz / lerp(1.0, max(surfaceAlbedo.xyz, EPSILON_SSS_ALBEDO), sssAmount));

float4 diffuseMeanFreePath = humanProfile ? MeanFreePathHuman : MeanFreePathBase;
diffuseMeanFreePath.xyz = float3(max(diffuseMeanFreePath.x, 1e-5f), max(diffuseMeanFreePath.y, 1e-5f), max(diffuseMeanFreePath.z, 1e-5f));
Expand Down Expand Up @@ -108,28 +108,30 @@ float4 BurleyNormalizedSS(uint2 DTid, float2 texCoord, uint eyeIndex, float sssA
float2 sampleUV = texCoord + uvOffset;
float2 clampedUV = clamp(sampleUV, float2(0.0f, 0.0f), float2(1.0f, 1.0f));
uint2 samplePixcoord = uint2(clampedUV * SharedData::BufferDim.xy);
float3 sampleColor = Color::GammaToLinear(ColorTexture[samplePixcoord].xyz / max(AlbedoTexture[samplePixcoord].xyz, EPSILON_SSS_ALBEDO));
float sampleMask = MaskTexture[samplePixcoord].x;
bool mask = sampleMask > 1e-5f;
if (!mask)
continue;

float3 sampleColor = Color::GammaToLinear(ColorTexture[samplePixcoord].xyz / lerp(1.0, max(AlbedoTexture[samplePixcoord].xyz, EPSILON_SSS_ALBEDO), sampleMask));
float sampleDepth = SharedData::GetScreenDepth(DepthTexture[samplePixcoord].x);
float3 sampleNormalVS = GBuffer::DecodeNormal(NormalTexture[samplePixcoord].xy);
float3 sampleNormalWS = normalize(mul(FrameBuffer::CameraViewInverse[eyeIndex], float4(sampleNormalVS, 0)).xyz);

float deltaDepth = (sampleDepth - centerDepth) * 10.f / GAME_UNIT_TO_CM; // convert to mm
float radiusSampledInMM = sqrt(radius * radius + deltaDepth * deltaDepth);

float maskSample = MaskTexture[samplePixcoord].x;
bool mask = maskSample > 1e-5f;

float3 diffusionProfile = GetBurleyProfile(diffuseMeanFreePath.xyz, s3d, radiusSampledInMM);
float normalWeight = sqrt(saturate(dot(sampleNormalWS, normalWS) * 0.5f + 0.5f));
float3 sampleWeight = mask ? (diffusionProfile / pdf) * normalWeight : 0.0f;
float3 sampleWeight = (diffusionProfile / pdf) * normalWeight;

colorSum += sampleWeight * sampleColor;
weightSum += sampleWeight;
}

colorSum *= any(weightSum == 0.0f) ? 0.0f : (1.0f / weightSum);
colorSum = lerp(colorSum, originalColor, saturate(centerWeight));
float3 color = Color::LinearToGamma(colorSum) * AlbedoTexture[DTid.xy].xyz;
float3 color = Color::LinearToGamma(colorSum) * lerp(1.0f, AlbedoTexture[DTid.xy].xyz, sssAmount);

float4 outColor = float4(color, ColorTexture[DTid.xy].w);
return outColor;
Expand Down