浏览代码

Share the light loop code

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
33d14b62
共有 6 个文件被更改,包括 43 次插入64 次删除
  1. 18
      SampleScenes/HDTest/HDRenderLoopTest.unity
  2. 14
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  3. 5
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightEvaluation.hlsl
  4. 67
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  6. 2
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/SkySettings/HDRP_Default_Sky.asset

18
SampleScenes/HDTest/HDRenderLoopTest.unity


--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3

m_AmbientSkyColor: {r: 0.2, g: 0.2, b: 0.2, a: 0}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 0
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}

m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 0
m_ReflectionIntensity: 1
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_UseShadowmask: 1
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

m_Name:
m_EditorClassIdentifier:
m_CommonSettings: {fileID: 0}
m_SkySettings: {fileID: 11400000, guid: 3b08dd58a5baaa245896b3088620f1ec, type: 2}
m_SkySettings: {fileID: 11400000, guid: 55214718938e62442b0f5673994ee7b7, type: 2}
--- !u!4 &1613005974
Transform:
m_ObjectHideFlags: 0

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1828470159}
m_LocalRotation: {x: -0.34097207, y: -0.14720488, z: 0.054151595, w: -0.92689615}
m_LocalPosition: {x: -102.840866, y: 5.4326243, z: 25.258797}
m_LocalRotation: {x: -0.388371, y: -0.58506876, z: 0.3757572, w: -0.60470587}
m_LocalPosition: {x: -126.72653, y: 124.686264, z: -44.780445}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

14
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


float a = tMin - originToLightProj;
float b = tMax - originToLightProj;
float dSq = rayToLightDistSq;
float d = sqrt(dSq);
float dInv = rsqrt(dSq);
float dRcp = rsqrt(dSq);
float d = dSq * dRcp;
float theta0 = FastATan(a * dInv);
float theta1 = FastATan(b * dInv);
float theta0 = FastATan(a * dRcp);
float theta1 = FastATan(b * dRcp);
float gamma = theta1 - theta0;
float theta = lerp(theta0, theta1, rndVal);
float t = d * tan(theta);

rcpPdf = gamma * rSq * dInv;
rcpPdf = gamma * rSq * dRcp;
}
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf

}
#ifndef USE_LEGACY_UNITY_SHADER_VARIABLES
#define VOLUMETRIC_LIGHTING_ENABLED
#endif
#define VOLUMETRIC_LIGHTING_ENABLED
#ifdef PRESET_ULTRA
// E.g. for 1080p: (1920/4)x(1080/4)x(256) = 33,177,600 voxels

5
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightEvaluation.hlsl


#endif
}
// Note: no fog attenuation along shadow rays for directional lights.
attenuation *= shadow;
[branch] if (lightData.cookieIndex >= 0)

shadow = lerp(1.0, shadow, lightData.shadowDimmer);
#endif
}
#ifdef VOLUMETRIC_LIGHTING_ENABLED
shadow *= TransmittanceHomogeneousMedium(_GlobalFog_Extinction, dist);
#endif
attenuation *= shadow;

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


// Computes the in-scattered radiance along the ray.
void FillVolumetricLightingBuffer(LightLoopContext context, uint featureFlags,
PositionInputs posInput, Ray ray, uint2 voxelCoord, float4 depthParams)
PositionInputs posInput, Ray ray)
{
BakeLightingData unusedData; // Unused, so define once

float3 totalRadiance = 0;
float opticalDepth = 0;
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)depthParams.x); // Prevent unrolling...
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.x); // Prevent unrolling...
#ifdef LIGHTLOOP_TILE_PASS
// Our voxel is not necessarily completely inside a single light cluster.

for (uint slice = 0; slice < sliceCountHack; slice++)
{
float e1 = slice * de + de; // (slice + 1) / sliceCount
float z1 = DecodeLogarithmicDepth(e1, depthParams);
float z1 = DecodeLogarithmicDepth(e1, _VBufferDepthEncodingParams);
float t1 = ray.ratioLenToZ * z1;
float dt = t1 - t0;

if (featureFlags & LIGHTFEATUREFLAGS_PUNCTUAL)
{
uint punctualLightStart;
uint punctualLightCount;
uint lightCount, lightStart;
punctualLightStart, punctualLightCount);
lightStart, lightCount);
punctualLightStart = 0;
punctualLightCount = _PunctualLightCount;
lightCount = _PunctualLightCount;
lightStart = 0;
for (uint i = 0; i < punctualLightCount; ++i)
for (uint i = 0; i < lightCount; ++i)
LightData lightData = FetchLight(punctualLightStart, i);
LightData lightData = FetchLight(lightStart, i);
float tEntr, tExit;
float tEntr = tMin;
float tExit = tMax;
if (lightType == GPULIGHTTYPE_SPOT)
{

continue;
}
}
else
{
tEntr = tMin;
tExit = tMax;
}
float t, distSq, rcpPdf;
ImportanceSamplePunctualLight(rndVal, lightData.positionWS,

posInput.positionWS = GetPointAtDistance(ray, t);
// TODO: we could compute this data in ImportanceSamplePunctualLight().
float3 L = lightToSample * -rsqrt(distSq);
float intensity = GetPunctualShapeAttenuation(lightData, L, distSq);
float3 color = lightData.color;
float3 L = -lightToSample * rsqrt(distSq);
// TODO: heterogeneous medium.
intensity *= TransmittanceHomogeneousMedium(extinction, dist);
[branch] if (lightData.shadowIndex >= 0)
{
// TODO: make projector lights cast shadows.
float shadow = GetPunctualShadowAttenuation(context.shadowContext, posInput.positionWS,
float3(0, 0, 0), lightData.shadowIndex, float4(L, dist));
float3 color; float attenuation;
EvaluateLight_Punctual(context, posInput, lightData, unusedData, 0, L, dist, distSq,
color, attenuation);
intensity *= lerp(1, shadow, lightData.shadowDimmer);
}
// Projector lights always have cookies, so we can perform clipping inside the if().
[branch] if (lightData.cookieIndex >= 0)
{
float4 cookie = EvaluateCookie_Punctual(context, lightData, lightToSample);
color *= cookie.rgb;
intensity *= cookie.a;
}
float intensity = attenuation * rcpPdf;
float transmittance = TransmittanceHomogeneousMedium(extinction, t - t0);
intensity *= transmittance * rcpPdf;
intensity *= TransmittanceHomogeneousMedium(extinction, t - t0);
// Compute the amount of in-scattered radiance.
sampleRadiance += color * intensity;

opticalDepth += 0.5 * extinction * dt;
// Store the voxel data. TODO: reprojection of 'tc' (or 'centerWS').
_VBufferLighting[uint3(voxelCoord, slice)] = float4(totalRadiance, opticalDepth);
_VBufferLighting[uint3(posInput.positionSS, slice)] = float4(totalRadiance, opticalDepth);
// Compute the optical depth up to the end of the interval.
opticalDepth += 0.5 * extinction * dt;

context.shadowContext = InitShadowContext();
uint featureFlags = 0xFFFFFFFF;
PositionInputs posInput;
ZERO_INITIALIZE(PositionInputs, posInput);
posInput.tileCoord = tileCoord;
PositionInputs posInput = GetPositionInput(voxelCoord, rcp(_VBufferResolutionAndScale.xy), tileCoord);
FillVolumetricLightingBuffer(context, featureFlags, posInput, ray, voxelCoord, _VBufferDepthEncodingParams);
FillVolumetricLightingBuffer(context, featureFlags, posInput, ray);
}

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl
#include "Lit.cs.hlsl"
#include "../SubsurfaceScattering/SubsurfaceScattering.hlsl"
#include "../../../Core/ShaderLibrary/VolumeRendering.hlsl"
// Define refraction keyword helpers
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE))

2
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/SkySettings/HDRP_Default_Sky.asset


m_EditorClassIdentifier:
rotation: 160
exposure: 0
multiplier: 1
multiplier: 0
resolution: 256
updateMode: 0
updatePeriod: 0

正在加载...
取消
保存