volumetric light updates
This commit is contained in:
@@ -13,13 +13,15 @@ TEXTURE2D(input, UPSAMPLE_FORMAT, TEXSLOT_ONDEMAND0);
|
||||
// Run this post process as pixel shader:
|
||||
float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_TARGET
|
||||
{
|
||||
const uint2 pixel = pos.xy;
|
||||
#else
|
||||
// Run this post process as compute shader:
|
||||
RWTEXTURE2D(output, UPSAMPLE_FORMAT, 0);
|
||||
[numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)]
|
||||
void main(uint3 DTid : SV_DispatchThreadID)
|
||||
{
|
||||
const float2 uv = (DTid.xy + 0.5f) * xPPResolution_rcp;
|
||||
const uint2 pixel = DTid.xy;
|
||||
const float2 uv = (pixel + 0.5f) * xPPResolution_rcp;
|
||||
#endif // USE_PIXELSHADER
|
||||
|
||||
|
||||
@@ -28,12 +30,12 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
const float2 lowres_size = xPPParams1.xy;
|
||||
const float2 lowres_texel_size = xPPParams1.zw;
|
||||
|
||||
const float2 uv00 = uv - 0.5f * lowres_texel_size;
|
||||
const float2 uv00 = uv - lowres_texel_size * 0.5;
|
||||
const float2 uv10 = uv00 + float2(lowres_texel_size.x, 0);
|
||||
const float2 uv01 = uv00 + float2(0, lowres_texel_size.y);
|
||||
const float2 uv11 = uv00 + lowres_texel_size;
|
||||
|
||||
const float4 lineardepth_highres = texture_lineardepth.SampleLevel(sampler_point_clamp, uv, 0).xxxx;
|
||||
const float4 lineardepth_highres = texture_lineardepth[pixel].xxxx;
|
||||
const float4 lineardepth_lowres = float4(
|
||||
texture_lineardepth.SampleLevel(sampler_point_clamp, uv00, lowres_depthchain_mip),
|
||||
texture_lineardepth.SampleLevel(sampler_point_clamp, uv10, lowres_depthchain_mip),
|
||||
@@ -58,7 +60,10 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
}
|
||||
else
|
||||
{
|
||||
// large error, find nearest sample to current depth:
|
||||
// large error:
|
||||
|
||||
#ifdef UPSAMPLE_DISABLE_FILTERING
|
||||
// find nearest sample to current depth:
|
||||
float min_depth_diff = depth_diff[0];
|
||||
float2 uv_nearest = uv00;
|
||||
|
||||
@@ -79,11 +84,20 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
uv_nearest = uv11;
|
||||
min_depth_diff = depth_diff[3];
|
||||
}
|
||||
|
||||
#ifdef UPSAMPLE_DISABLE_FILTERING
|
||||
color = input[floor(uv_nearest * lowres_size)];
|
||||
#else
|
||||
color = input.SampleLevel(sampler_point_clamp, uv_nearest, 0);
|
||||
|
||||
// depth-weighted blending:
|
||||
float4 weights = saturate(1 - abs(lineardepth_highres - lineardepth_lowres));
|
||||
float sum = weights[0] + weights[1] + weights[2] + weights[3];
|
||||
weights /= max(sum, 0.0001);
|
||||
|
||||
color = 0;
|
||||
color += input.SampleLevel(sampler_point_clamp, uv00, 0) * weights[0];
|
||||
color += input.SampleLevel(sampler_point_clamp, uv10, 0) * weights[1];
|
||||
color += input.SampleLevel(sampler_point_clamp, uv01, 0) * weights[2];
|
||||
color += input.SampleLevel(sampler_point_clamp, uv11, 0) * weights[3];
|
||||
|
||||
#endif // UPSAMPLE_DISABLE_FILTERING
|
||||
}
|
||||
|
||||
|
||||
@@ -9,5 +9,14 @@ struct VertexToPixel {
|
||||
float4 pos2D : POSITION2D;
|
||||
};
|
||||
|
||||
// Mie scaterring approximated with Henyey-Greenstein phase function.
|
||||
// https://www.alexandre-pestana.com/volumetric-lights/
|
||||
#define G_SCATTERING 0.66
|
||||
float ComputeScattering(float lightDotView)
|
||||
{
|
||||
float result = 1.0f - G_SCATTERING * G_SCATTERING;
|
||||
result /= (4.0f * PI * pow(1.0f + G_SCATTERING * G_SCATTERING - (2.0f * G_SCATTERING) * lightDotView, 1.5f));
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // WI_VOLUMETRICLIGHT_HF
|
||||
|
||||
@@ -23,6 +23,7 @@ float4 main(VertexToPixel input) : SV_TARGET
|
||||
float3 accumulation = 0;
|
||||
|
||||
const float3 L = light.GetDirection();
|
||||
const float scattering = ComputeScattering(saturate(dot(L, -V)));
|
||||
|
||||
float3 rayEnd = g_xCamera_CamPos;
|
||||
|
||||
@@ -47,7 +48,7 @@ float4 main(VertexToPixel input) : SV_TARGET
|
||||
{
|
||||
float3 attenuation = shadowCascade(light, ShPos, ShTex.xy, cascade);
|
||||
|
||||
attenuation *= GetFogAmount(cameraDistance - marchedDistance);
|
||||
attenuation *= GetFogAmount(cameraDistance - marchedDistance) * scattering;
|
||||
|
||||
accumulation += attenuation;
|
||||
|
||||
@@ -64,8 +65,13 @@ float4 main(VertexToPixel input) : SV_TARGET
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
accumulation /= sampleCount;
|
||||
|
||||
return max(0, float4(accumulation * light.GetColor().rgb * light.GetEnergy(), 1));
|
||||
float3 atmosphereTransmittance = 1;
|
||||
if (g_xFrame_Options & OPTION_BIT_REALISTIC_SKY)
|
||||
{
|
||||
atmosphereTransmittance = GetAtmosphericLightTransmittance(g_xFrame_Atmosphere, P, L, texture_transmittancelut);
|
||||
}
|
||||
|
||||
return max(0, float4(accumulation * light.GetColor().rgb * light.GetEnergy() * atmosphereTransmittance, 1));
|
||||
}
|
||||
|
||||
@@ -4508,6 +4508,10 @@ void DrawVolumeLights(
|
||||
BindShadowmaps(PS, cmd);
|
||||
|
||||
device->BindResource(PS, &depthbuffer, TEXSLOT_DEPTH, cmd);
|
||||
device->BindResource(PS, &textures[TEXTYPE_2D_SKYATMOSPHERE_SKYVIEWLUT], TEXSLOT_SKYVIEWLUT, cmd);
|
||||
device->BindResource(PS, &textures[TEXTYPE_2D_SKYATMOSPHERE_TRANSMITTANCELUT], TEXSLOT_TRANSMITTANCELUT, cmd);
|
||||
device->BindResource(PS, &textures[TEXTYPE_2D_SKYATMOSPHERE_MULTISCATTEREDLUMINANCELUT], TEXSLOT_MULTISCATTERINGLUT, cmd);
|
||||
device->BindResource(PS, &textures[TEXTYPE_2D_SKYATMOSPHERE_SKYLUMINANCELUT], TEXSLOT_SKYLUMINANCELUT, cmd);
|
||||
|
||||
XMMATRIX VP = vis.camera->GetViewProjection();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace wiTextureHelper
|
||||
data[i] = wiRandom::getRandom(0, 255);
|
||||
data[i + 1] = wiRandom::getRandom(0, 255);
|
||||
data[i + 2] = wiRandom::getRandom(0, 255);
|
||||
data[i + 3] = 255;
|
||||
data[i + 3] = wiRandom::getRandom(0, 255);
|
||||
}
|
||||
|
||||
CreateTexture(helperTextures[HELPERTEXTURE_RANDOM64X64], data, 64, 64);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 56;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 18;
|
||||
const int revision = 19;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user