浏览代码

Implement orthographic projector lights (single pass loop only)

/fptl_cleanup
Evgenii Golubev 8 年前
当前提交
f5b4c7e9
共有 12 个文件被更改,包括 803 次插入128 次删除
  1. 8
      Assets/ScriptableRenderPipeline/AdditionalLightData.cs
  2. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  3. 32
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/FeatureFlags.hlsl
  4. 108
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  6. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
  7. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  8. 90
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/Shadow.cs
  10. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowUtilities.cs
  11. 644
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  12. 2
      ProjectSettings/ProjectVersion.txt

8
Assets/ScriptableRenderPipeline/AdditionalLightData.cs


namespace UnityEngine.Experimental.Rendering
{
public enum LightArchetype { Punctual, Rectangle, Line };
public enum LightArchetype { Punctual, Area, Projector };
//@TODO: We should continuously move these values
// into the engine when we can see them being generally useful

public bool affectSpecular = true;
public LightArchetype archetype = LightArchetype.Punctual;
public bool isDoubleSided = false;
public bool isDoubleSided = false; // Rectangular area lights only
public float areaLightLength = 0.0f;
public float lightLength = 0.0f; // Area & projector lights
public float areaLightWidth = 0.0f;
public float lightWidth = 0.0f; // Area & projector lights
}
}

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public int cookieIndex;
public GPULightType lightType;
// Area Light specific
public Vector2 size; // x = cot(outerHalfAngle) for spot lights
public bool twoSided;
public Vector2 size; // Used by area, projector and spot lights; x = cot(outerHalfAngle) for spot lights
public bool twoSided; // Used by rectangular area lights only
};
[GenerateHLSL]

32
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/FeatureFlags.hlsl


static const uint FeatureVariantFlags[NUM_FEATURE_VARIANTS] =
{
/* 0 */ 0 | FEATURE_FLAG_ALL_MATERIALS,
/* 1 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 2 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 5 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 6 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 7 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_ALL_MATERIALS,
/* 8 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/* 9 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_ALL_MATERIALS,
/*10 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/*11 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_ALL_MATERIALS,
/*12 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/*13 */ 0xFFFFFFFF,
/*14 */ 0xFFFFFFFF,
/*15 */ 0xFFFFFFFF,
/* 0 */ 0 | FEATURE_FLAG_ALL_MATERIALS,
/* 1 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 2 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 5 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 6 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 7 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_LIGHT_PROJECTOR | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 8 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_ALL_MATERIALS,
/* 9 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/* 10 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_ALL_MATERIALS,
/* 11 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/* 12 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_ALL_MATERIALS,
/* 13 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/* 14 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_LIGHT_PROJECTOR | FEATURE_FLAG_ALL_MATERIALS,
/* 15 */ 0xFFFFFFFF
};
uint FeatureFlagsToTileVariant(uint featureFlags)

108
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


{
Punctual,
Area,
Projector,
Env,
Count
}

{
public static uint FEATURE_FLAG_LIGHT_PUNCTUAL = 1 << 0;
public static uint FEATURE_FLAG_LIGHT_AREA = 1 << 1;
public static uint FEATURE_FLAG_LIGHT_PUNCTUAL = 1 << 0;
public static uint FEATURE_FLAG_LIGHT_AREA = 1 << 1;
public static uint FEATURE_FLAG_LIGHT_ENV = 1 << 3;
public static uint FEATURE_FLAG_LIGHT_SKY = 1 << 4;
public static uint FEATURE_FLAG_LIGHT_PROJECTOR = 1 << 3;
public static uint FEATURE_FLAG_LIGHT_ENV = 1 << 4;
public static uint FEATURE_FLAG_LIGHT_SKY = 1 << 5;
}
[GenerateHLSL]

public class LightLoop : BaseLightLoop
{
public const int k_MaxDirectionalLightsOnScreen = 10;
public const int k_MaxPunctualLightsOnScreen = 512;
public const int k_MaxAreaLightsOnSCreen = 128;
public const int k_MaxLightsOnScreen = k_MaxDirectionalLightsOnScreen + k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen;
public const int k_MaxDirectionalLightsOnScreen = 4;
public const int k_MaxPunctualLightsOnScreen = 512;
public const int k_MaxAreaLightsOnScreen = 8;
public const int k_MaxProjectorLightsOnScreen = 16;
public const int k_MaxLightsOnScreen = k_MaxDirectionalLightsOnScreen + k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen + k_MaxProjectorLightsOnScreen;
public const int k_MaxEnvLightsOnScreen = 64;
public const int k_MaxShadowOnScreen = 16;
public const int k_MaxCascadeCount = 4; //Should be not less than m_Settings.directionalLightCascadeCount;

LightList m_lightList;
int m_punctualLightCount = 0;
int m_areaLightCount = 0;
int m_projectorLightCount = 0;
int m_lightCount = 0;
private ComputeShader buildScreenAABBShader { get { return m_PassResources.buildScreenAABBShader; } }

m_lightList.Allocate();
s_DirectionalLightDatas = new ComputeBuffer(k_MaxDirectionalLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));
s_LightDatas = new ComputeBuffer(k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_LightDatas = new ComputeBuffer(k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen + k_MaxProjectorLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_EnvLightDatas = new ComputeBuffer(k_MaxEnvLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_shadowDatas = new ComputeBuffer(k_MaxCascadeCount + k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ShadowData)));

case LightType.Point:
lightData.cookieIndex = m_CubeCookieTexArray.FetchSlice(light.light.cookie);
break;
}
if (additionalData.archetype == LightArchetype.Projector)
{
lightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
}
}

if (additionalData.archetype != LightArchetype.Punctual)
{
lightData.twoSided = additionalData.isDoubleSided;
lightData.size = new Vector2(additionalData.areaLightLength, additionalData.areaLightWidth);
lightData.size = new Vector2(additionalData.lightLength, additionalData.lightWidth);
}
m_lightList.lights.Add(lightData);

lightVolumeData.boxInvRange.Set(1.0f / radius, 1.0f / radius, 1.0f / radius);
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_AREA;
}
else if (gpuLightType == GPULightType.ProjectorOrtho)
{
Vector3 posVS = worldToView.MultiplyPoint(lightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(lightData.right);
Vector3 yAxisVS = worldToView.MultiplyVector(lightData.up);
Vector3 zAxisVS = worldToView.MultiplyVector(lightData.forward);
float radius = 1.0f / Mathf.Sqrt(lightData.invSqrAttenuationRadius);
// Projector lights point forwards (along Z). The projection window is aligned with the XY plane.
Vector3 boxDims = new Vector3(lightData.size.x, lightData.size.y, radius);
Vector3 boxCenterVS = posVS + zAxisVS * (0.5f * radius);
bound.center = boxCenterVS;
bound.boxAxisX = 0.5f * boxDims.x * xAxisVS; // Should this be halved or not?
bound.boxAxisY = 0.5f * boxDims.y * yAxisVS;
bound.boxAxisZ = 0.5f * boxDims.z * zAxisVS;
bound.radius = 0.5f * boxDims.magnitude; // Radius of a circumscribed sphere?
bound.scaleXY.Set(1.0f, 1.0f);
lightVolumeData.lightPos = boxCenterVS; // Is it the center of the volume?
lightVolumeData.lightAxisX = xAxisVS;
lightVolumeData.lightAxisY = yAxisVS;
lightVolumeData.lightAxisZ = zAxisVS;
lightVolumeData.boxInnerDist = boxDims * 0.5f; // No idea what this is. Document your code
lightVolumeData.boxInvRange.Set(1.0f / radius, 1.0f / radius, 1.0f / radius); // No idea what this is. Document your code
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_PROJECTOR;
}
// TODO implement unsupported type
Debug.Assert(false);
Debug.Assert(false, "TODO: encountered an unknown GPULightType.");
}
m_lightList.bounds.Add(bound);

int directionalLightcount = 0;
int punctualLightcount = 0;
int areaLightCount = 0;
int projectorLightCount = 0;
int lightCount = Math.Min(cullResults.visibleLights.Length, k_MaxLightsOnScreen);
var sortKeys = new uint[lightCount];

{
switch (additionalData.archetype)
{
case LightArchetype.Rectangle:
if (areaLightCount >= k_MaxAreaLightsOnSCreen)
case LightArchetype.Area:
if (areaLightCount >= k_MaxAreaLightsOnScreen)
gpuLightType = GPULightType.Rectangle;
gpuLightType = (additionalData.lightWidth > 0) ? GPULightType.Rectangle : GPULightType.Line;
case LightArchetype.Line:
if (areaLightCount >= k_MaxAreaLightsOnSCreen)
case LightArchetype.Projector:
if (projectorLightCount >= k_MaxProjectorLightsOnScreen)
lightCategory = LightCategory.Area;
gpuLightType = GPULightType.Line;
lightCategory = LightCategory.Projector;
gpuLightType = GPULightType.ProjectorOrtho; // TODO: pyramid
lightVolumeType = LightVolumeType.Box;
break;

continue;
}
// Spot, point, rect, line light - Rendering side
// Punctual, area, projector lights - the rendering side.
if (lightCategory == LightCategory.Punctual)
punctualLightcount++;
else if (lightCategory == LightCategory.Area)
areaLightCount++;
else
Debug.Assert(false); // Should not be anything else here.
switch (lightCategory)
{
case LightCategory.Punctual:
punctualLightcount++;
break;
case LightCategory.Area:
areaLightCount++;
break;
case LightCategory.Projector:
projectorLightCount++;
break;
default:
Debug.Assert(false, "TODO: encountered an unknown LightCategory.");
break;
}
// Then culling side. Must be call in this order as we pass the created Light data to the function
GetLightVolumeDataAndBound(lightCategory, gpuLightType, lightVolumeType, light, m_lightList.lights[m_lightList.lights.Count - 1], worldToView);
}

// Sanity check
Debug.Assert(m_lightList.directionalLights.Count == directionalLightcount);
Debug.Assert(m_lightList.lights.Count == areaLightCount + punctualLightcount);
m_areaLightCount = areaLightCount;
m_punctualLightCount = punctualLightcount;
Debug.Assert(m_lightList.lights.Count == areaLightCount + punctualLightcount + projectorLightCount);
m_punctualLightCount = punctualLightcount;
m_areaLightCount = areaLightCount;
m_projectorLightCount = projectorLightCount;
// Redo everything but this time with envLights
int envLightCount = 0;

SetGlobalBuffer("_LightDatas", s_LightDatas);
SetGlobalInt("_PunctualLightCount", m_punctualLightCount);
SetGlobalInt("_AreaLightCount", m_areaLightCount);
SetGlobalInt("_ProjectorLightCount", m_projectorLightCount);
SetGlobalBuffer("_EnvLightDatas", s_EnvLightDatas);
SetGlobalInt("_EnvLightCount", m_lightList.envLights.Count);
SetGlobalBuffer("_ShadowDatas", s_shadowDatas);

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


//
#define LIGHTCATEGORY_PUNCTUAL (0)
#define LIGHTCATEGORY_AREA (1)
#define LIGHTCATEGORY_ENV (2)
#define LIGHTCATEGORY_COUNT (3)
#define LIGHTCATEGORY_PROJECTOR (2)
#define LIGHTCATEGORY_ENV (3)
#define LIGHTCATEGORY_COUNT (4)
//
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightFeatureFlags: static fields

#define FEATURE_FLAG_LIGHT_DIRECTIONAL (4)
#define FEATURE_FLAG_LIGHT_ENV (8)
#define FEATURE_FLAG_LIGHT_SKY (16)
#define FEATURE_FLAG_LIGHT_PROJECTOR (8)
#define FEATURE_FLAG_LIGHT_ENV (16)
#define FEATURE_FLAG_LIGHT_SKY (32)
//
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightDefinitions: static fields

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl


uint _DirectionalLightCount;
uint _PunctualLightCount;
uint _AreaLightCount;
uint _ProjectorLightCount;
uint _EnvLightCount;
float4 _DirShadowSplitSpheres[4]; // TODO: share this max between C# and hlsl

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


specularLighting += localSpecularLighting;
}
// Area are store with punctual, just offset the index
for (i = _PunctualLightCount; i < _AreaLightCount + _PunctualLightCount; ++i)
for (; i < _PunctualLightCount + _AreaLightCount; ++i)
{
float3 localDiffuseLighting, localSpecularLighting;

EvaluateBSDF_Area( context, V, posInput, prelightData, _LightDatas[i], bsdfData,
localDiffuseLighting, localSpecularLighting);
}
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
for (; i < _PunctualLightCount + _AreaLightCount + _ProjectorLightCount; ++i)
{
float3 localDiffuseLighting, localSpecularLighting;
EvaluateBSDF_Projector( context, V, posInput, prelightData, _LightDatas[i], bsdfData,
localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;

90
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Projector
//-----------------------------------------------------------------------------
void EvaluateBSDF_Projector(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput, PreLightData preLightData, LightData lightData, BSDFData bsdfData,
out float3 diffuseLighting,
out float3 specularLighting)
{
float3 positionWS = posInput.positionWS;
float3 unL = lightData.positionWS - positionWS;
float3 L = -lightData.forward; // Lights are pointing backward in Unity
// Project 'unL' onto the light's axes.
float distX = dot(unL, lightData.right);
float distY = dot(unL, lightData.up);
// Compute windowing factors using the dimensions of the light's "viewport".
float windowX = (abs(distX) <= lightData.size.x) ? 1 : 0;
float windowY = (abs(distY) <= lightData.size.y) ? 1 : 0;
float illuminance = saturate(dot(bsdfData.normalWS, L) * (windowX * windowY));
diffuseLighting = float3(0.0, 0.0, 0.0);
specularLighting = float3(0.0, 0.0, 0.0);
float4 cookie = float4(1.0, 1.0, 1.0, 1.0);
[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0)
{
#ifdef SHADOWS_USE_SHADOWCTXT
float shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, lightData.shadowIndex, L, posInput.unPositionSS);
#else
float shadow = GetDirectionalShadowAttenuation(lightLoopContext, positionWS, lightData.shadowIndex, L, posInput.unPositionSS);
#endif
illuminance *= shadow;
}
[branch] if (lightData.cookieIndex >= 0 && illuminance > 0.0)
{
// Project 'unL' onto the light's axes.
float2 coord = float2(distX, distY);
// Compute the texture coordinates in [0, 1]^2.
coord = coord / lightData.size + float2(0.5, 0.5);
cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex);
illuminance *= cookie.a;
}
[branch] if (illuminance > 0.0)
{
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting);
diffuseLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.diffuseScale);
specularLighting *= (cookie.rgb * lightData.color) * (illuminance * lightData.specularScale);
}
[branch] if (bsdfData.enableTransmission)
{
// Reverse the normal.
illuminance = saturate(dot(-bsdfData.normalWS, L));
[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0)
{
// TODO: factor out the biased position?
float3 biasedPositionWS = positionWS + bsdfData.normalWS * bsdfData.thickness;
#ifdef SHADOWS_USE_SHADOWCTXT
float shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, biasedPositionWS, lightData.shadowIndex, L, posInput.unPositionSS);
#else
float shadow = GetDirectionalShadowAttenuation(lightLoopContext, biasedPositionWS, lightData.shadowIndex, L, posInput.unPositionSS);
#endif
illuminance *= shadow;
}
illuminance *= cookie.a;
// The difference between the Disney Diffuse and the Lambertian BRDF for transmittance is negligible.
float3 backLight = (cookie.rgb * lightData.color) * (illuminance * lightData.diffuseScale * Lambert());
// TODO: multiplication by 'diffuseColor' and 'transmittance' is the same for each light.
float3 transmittedLight = backLight * bsdfData.diffuseColor * bsdfData.transmittance;
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
diffuseLighting += transmittedLight;
}
}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Line - Reference
//-----------------------------------------------------------------------------

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/Shadow.cs


// set light specific values that are not related to the shadowmap
GPUShadowType shadowtype;
ShadowUtils.MapLightType(ald.archetype, vl.lightType, out sd.lightType, out shadowtype);
ShadowUtils.MapLightType(vl.lightType, ald, out sd.lightType, out shadowtype);
sd.bias = l.shadowBias;
sd.quality = 0;

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowUtilities.cs


return proj * view;
}
public static bool MapLightType(LightArchetype la, LightType lt, out GPULightType gputype, out GPUShadowType shadowtype)
public static bool MapLightType(LightType lt, AdditionalLightData ald, out GPULightType gputype, out GPUShadowType shadowtype)
switch (la)
shadowtype = GPUShadowType.Unknown; // Default for all non-punctual lights
switch (ald.archetype)
case LightArchetype.Punctual: return MapLightType(lt, out gputype, out shadowtype);
case LightArchetype.Rectangle: gputype = GPULightType.Rectangle; shadowtype = GPUShadowType.Unknown; return true;
case LightArchetype.Line: gputype = GPULightType.Line; shadowtype = GPUShadowType.Unknown; return true;
default: gputype = GPULightType.Spot; shadowtype = GPUShadowType.Unknown; return false; // <- probably not what you want
case LightArchetype.Punctual: return MapLightType(lt, out gputype, out shadowtype);
case LightArchetype.Area: gputype = (ald.lightWidth > 0) ? GPULightType.Rectangle : GPULightType.Line; return true;
case LightArchetype.Projector: gputype = GPULightType.ProjectorOrtho; return true; // TODO: pyramid
default: gputype = GPULightType.Spot; return false; // <- probably not what you want
}
}

644
Assets/TestScenes/HDTest/HDRenderLoopTest.unity
文件差异内容过多而无法显示
查看文件

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.1.0a6
m_EditorVersion: 2017.1.0b2
正在加载...
取消
保存