浏览代码

Clean up

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
d4501639
共有 4 个文件被更改,包括 33 次插入41 次删除
  1. 41
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  2. 29
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl

41
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


// Transmittance(x, z) = Transmittance(x, y) * Transmittance(y, z)
// Integral{a, b}{Transmittance(0, t) * Li(t) dt} = Transmittance(0, a) * Integral{a, b}{Transmittance(0, t - a) * Li(t) dt}.
float OpticalDepthHomogeneousMedia(float extinction, float intervalLength)
float OpticalDepthHomogeneousMedium(float extinction, float intervalLength)
float3 OpticalDepthHomogeneousMedia(float3 extinction, float intervalLength)
float3 OpticalDepthHomogeneousMedium(float3 extinction, float intervalLength)
{
return extinction * intervalLength;
}

return exp(-opticalDepth);
}
float TransmittanceHomogeneousMedia(float extinction, float intervalLength)
float TransmittanceHomogeneousMedium(float extinction, float intervalLength)
return Transmittance(OpticalDepthHomogeneousMedia(extinction, intervalLength));
return Transmittance(OpticalDepthHomogeneousMedium(extinction, intervalLength));
float3 TransmittanceHomogeneousMedia(float3 extinction, float intervalLength)
float3 TransmittanceHomogeneousMedium(float3 extinction, float intervalLength)
return Transmittance(OpticalDepthHomogeneousMedia(extinction, intervalLength));
return Transmittance(OpticalDepthHomogeneousMedium(extinction, intervalLength));
float TransmittanceIntegralHomogeneousMedia(float extinction, float intervalLength)
float TransmittanceIntegralHomogeneousMedium(float extinction, float intervalLength)
float3 TransmittanceIntegralHomogeneousMedia(float3 extinction, float intervalLength)
float3 TransmittanceIntegralHomogeneousMedium(float3 extinction, float intervalLength)
{
return rcp(extinction) - rcp(extinction) * exp(-extinction * intervalLength);
}

HenyeyGreensteinPhasePartVarying(asymmetry, LdotD);
}
// Samples the interval of homogeneous participating media using the closed-form tracking approach
// (proportionally to the transmittance times the extinction coefficient).
// Returns the offset from the start of the interval and the weight = (extinction * transmittance / pdf).
// Samples the interval of homogeneous participating medium using the closed-form tracking approach
// (proportionally to the transmittance).
// Returns the offset from the start of the interval and the weight = (transmittance / pdf).
void ImportanceSampleHomogeneousMedia(float extinction, float intervalLength, float rndVal,
void ImportanceSampleHomogeneousMedium(float rndVal, float extinction, float intervalLength,
// weight = extinction * exp(-extinction * t) / pdf
// weight = 1 - exp(-intervalLength * extinction)
// weight = exp(-extinction * t) / pdf
// weight = (1 - exp(-extinction * intervalLength)) / extinction;
weight = 1 - exp(-extinction * intervalLength);
offset = log(1 - rndVal * weight) / extinction;
float x = 1 - exp(-extinction * intervalLength);
weight = x * rcp(extinction);
offset = -log(1 - rndVal * x) * rcp(extinction);
// Ref: Importance Sampling of Area Lights in Participating Media.
void ImportanceSamplePunctualLight(float3 lightPosition, float3 rayOrigin, float3 rayDirection,
float tMin, float tMax, float rndVal,
// Ref: Importance Sampling of Area Lights in Participating Medium.
void ImportanceSamplePunctualLight(float rndVal, float3 lightPosition,
float3 rayOrigin, float3 rayDirection,
float tMin, float tMax,
out float dist, out float rcpPdf)
{
float3 originToLight = lightPosition - rayOrigin;

29
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute


// Definitions
//--------------------------------------------------------------------------------------------------
#ifdef PRESET_ULTRA
// E.g. for 1080p: (1920/4)x(1080/4)x(256) = 33,177,600 voxels
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 256
#else
// E.g. for 1080p: (1920/8)x(1080/8)x(128) = 4,147,200 voxels
#define VBUFFER_TILE_SIZE 8
#define VBUFFER_SLICE_COUNT 128
#endif // PRESET_ULTRA
#pragma kernel VolumetricLightingAllLights VolumetricLighting=VolumetricLightingAllLights LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClustered VolumetricLighting=VolumetricLightingClustered LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST

float tc = t0 + 0.5 * dt;
float3 centerWS = GetPointAtDistance(ray, tc);
// Sample the participating media at 'tc' (or 'centerWS').
// Sample the participating medium at 'tc' (or 'centerWS').
// We consider it to be constant along the interval [t0, t1] (within the voxel).
float3 scattering = _GlobalFog_Scattering;
float extinction = _GlobalFog_Extinction;

if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
{
float tOffset, weight;
ImportanceSampleHomogeneousMedia(extinction, dt, rndVal, tOffset, weight);
ImportanceSampleHomogeneousMedium(rndVal, extinction, dt, tOffset, weight);
float t = t0 + tOffset;
float3 positionWS = GetPointAtDistance(ray, t);

if (lightType != GPULIGHTTYPE_POINT) continue;
float t, rcpPdf;
ImportanceSamplePunctualLight(lightData.positionWS, ray.originWS, ray.directionWS,
tMin, tMax, rndVal, t, rcpPdf);
ImportanceSamplePunctualLight(rndVal, lightData.positionWS,
ray.originWS, ray.directionWS,
tMin, tMax, t, rcpPdf);
float3 positionWS = GetPointAtDistance(ray, t);

float intensity = GetPunctualShapeAttenuation(lightData, L, distSq);
float3 color = lightData.color;
// TODO: heterogeneous media.
intensity *= TransmittanceHomogeneousMedia(extinction, dist);
// TODO: heterogeneous medium.
intensity *= TransmittanceHomogeneousMedium(extinction, dist);
[branch] if (lightData.shadowIndex >= 0)
{

}
// Compute transmittance from 't0' to 't'.
float transmittance = TransmittanceHomogeneousMedia(extinction, t - t0);
float transmittance = TransmittanceHomogeneousMedium(extinction, t - t0);
color *= scattering;
// Compute the amount of in-scattered radiance.
sampleRadiance += color * intensity;

float transmittance = Transmittance(opticalDepth);
// Integral{a, b}{Transmittance(0, t) * Li(t) dt} = Transmittance(0, a) * Integral{a, b}{Transmittance(0, t - a) * Li(t) dt}.
// We multiply by the scattering coefficient per light.
totalRadiance += (transmittance * IsotropicPhaseFunction()) * sampleRadiance;
totalRadiance += (transmittance * IsotropicPhaseFunction()) * scattering * sampleRadiance;
// Compute the optical depth up to the center of the interval.
opticalDepth += 0.5 * extinction * dt;

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


}
#ifdef VOLUMETRIC_LIGHTING_ENABLED
shadow *= Transmittance(OpticalDepthHomogeneousMedia(preLightData.globalFogExtinction, dist));
shadow *= TransmittanceHomogeneousMedium(preLightData.globalFogExtinction, dist);
#endif
illuminance *= shadow;

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl


if (_AtmosphericScatteringType == FOGTYPE_EXPONENTIAL)
{
float3 fogColor = GetFogColor(posInput);
float fogFactor = _ExpFogDensity * (1.0f - Transmittance(OpticalDepthHomogeneousMedia(1.0f / _ExpFogDistance, posInput.depthVS)));
float fogFactor = _ExpFogDensity * (1.0f - TransmittanceHomogeneousMedium(1.0f / _ExpFogDistance, posInput.depthVS));
return float4(fogColor, fogFactor);
}
else if (_AtmosphericScatteringType == FOGTYPE_LINEAR)

正在加载...
取消
保存