浏览代码

HDRenderPipeline: Split AdditionalLightdata into HDAdditionalLight and AdditionalShadowData

HDAdditionalLight  is dedicated to the render pipeline
AdditionalShadowData is common to all render pipeline
/RenderPassXR_Sandbox
sebastienlagarde 7 年前
当前提交
a7ee1111
共有 12 个文件被更改,包括 592 次插入344 次删除
  1. 44
      Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  2. 53
      Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs
  3. 51
      Assets/ScriptableRenderPipeline/Core/Shadow/ShadowUtilities.cs
  4. 8
      Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs
  5. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  6. 79
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  7. 273
      Assets/TestScenes/FPTL/FPTL.unity
  8. 174
      Assets/ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs
  9. 13
      Assets/ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs.meta
  10. 35
      Assets/ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs
  11. 195
      Assets/ScriptableRenderPipeline/Core/AdditionalLightData.cs
  12. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs.meta

44
Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs


float[] cascadeRatios = null;
if( sr.shadowType == GPUShadowType.Directional )
{
AdditionalLightData ald = lights[sr.index].light.GetComponent<AdditionalLightData>();
if( !ald )
AdditionalShadowData asd = lights[sr.index].light.GetComponent<AdditionalShadowData>();
if( !asd )
ald.GetShadowCascades( out cascadeCnt, out cascadeRatios );
asd.GetShadowCascades( out cascadeCnt, out cascadeRatios );
}

ShadowUtils.Unpack( sr.shadowAlgorithm, out algo, out vari, out prec );
if( algo == ShadowAlgorithm.PCF )
{
AdditionalLightData ald = light.light.GetComponent<AdditionalLightData>();
if( !ald )
AdditionalShadowData asd = light.light.GetComponent<AdditionalShadowData>();
if( !asd )
int[] shadowData = ald.GetShadowData( out shadowDataFormat );
int[] shadowData = asd.GetShadowData( out shadowDataFormat );
ald.SetShadowAlgorithm( (int)algo, (int)vari, (int) prec, shadowDataFormat, shadowData );
asd.SetShadowAlgorithm( (int)algo, (int)vari, (int) prec, shadowDataFormat, shadowData );
Debug.Log( "Fixed up shadow data for algorithm " + algo + ", variant " + vari );
}

{
base.WritePerLightPayload( ref light, sr, ref sd, ref payload, ref payloadOffset );
AdditionalLightData ald = light.light.GetComponent<AdditionalLightData>();
if( !ald )
AdditionalShadowData asd = light.light.GetComponent<AdditionalShadowData>();
if( !asd )
int[] shadowData = ald.GetShadowData( out shadowDataFormat );
int[] shadowData = asd.GetShadowData( out shadowDataFormat );
if( shadowData == null )
return;

while( i < cnt && m_EntryCache[i].current.slice == rendertargetSlice )
{
AdditionalLightData ald = lights[m_EntryCache[i].key.visibleIdx].light.GetComponent<AdditionalLightData>();
AdditionalShadowData asd = lights[m_EntryCache[i].key.visibleIdx].light.GetComponent<AdditionalShadowData>();
int[] shadowData = ald.GetShadowData( out shadowDataFormat );
int[] shadowData = asd.GetShadowData( out shadowDataFormat );
ShadowAlgorithm algo;
ShadowVariant vari;

#if UNITY_EDITOR
// and register itself
AdditionalLightDataEditor.SetRegistry( this );
AdditionalShadowDataEditor.SetRegistry( this );
#endif
}

int facecount = 0;
GPUShadowType shadowType = GPUShadowType.Point;
AdditionalLightData ald = vl.light.GetComponent<AdditionalLightData>();
AdditionalShadowData asd = vl.light.GetComponent<AdditionalShadowData>();
bool add = (distToCam < ald.shadowFadeDistance || vl.lightType == LightType.Directional) && m_ShadowSettings.enabled;
bool add = (distToCam < asd.shadowFadeDistance || vl.lightType == LightType.Directional) && m_ShadowSettings.enabled;
if( add )
{

add = --m_MaxShadows[(int)GPUShadowType.Directional, 0] >= 0;
shadowType = GPUShadowType.Directional;
facecount = ald.cascadeCount;
facecount = asd.cascadeCount;
break;
case LightType.Point:
add = --m_MaxShadows[(int)GPUShadowType.Point, 0] >= 0;

sreq.shadowType = shadowType;
int sa, sv, sp;
ald.GetShadowAlgorithm( out sa, out sv, out sp );
asd.GetShadowAlgorithm( out sa, out sv, out sp );
sreq.shadowAlgorithm = ShadowUtils.Pack( (ShadowAlgorithm) sa, (ShadowVariant) sv, (ShadowPrecision) sp );
totalRequestCount += (uint) facecount;
requestsGranted.AddUnchecked( sreq );

shadowIndices.Reserve( grantedRequests.Count() );
for( uint i = 0, cnt = grantedRequests.Count(); i < cnt; ++i )
{
VisibleLight vl = lights[grantedRequests[i].index];
Light l = vl.light;
AdditionalLightData ald = l.GetComponent<AdditionalLightData>();
Light l = lights[grantedRequests[i].index].light;
AdditionalShadowData asd = l.GetComponent<AdditionalShadowData>();
GPUShadowType shadowtype;
ShadowUtils.MapLightType( ald.archetype, vl.lightType, out shadowtype );
GPUShadowType shadowtype = GetShadowLightType(l);
// current bias value range is way too large, so scale by 0.01 for now until we've decided whether to actually keep this value or not.
sd.bias = 0.01f * (SystemInfo.usesReversedZBuffer ? l.shadowBias : -l.shadowBias);
sd.normalBias = 100.0f * l.shadowNormalBias;

int smidx = 0;
while( smidx < k_MaxShadowmapPerType )
{
if( m_ShadowmapsPerType[(int)shadowtype,smidx] != null && m_ShadowmapsPerType[(int)shadowtype,smidx].Reserve( frameId, ref sd, grantedRequests[i], (uint) ald.shadowResolution, (uint) ald.shadowResolution, ref shadowDatas, ref shadowmapPayload, lights ) )
if( m_ShadowmapsPerType[(int)shadowtype,smidx] != null && m_ShadowmapsPerType[(int)shadowtype,smidx].Reserve( frameId, ref sd, grantedRequests[i], (uint) asd.shadowResolution, (uint) asd.shadowResolution, ref shadowDatas, ref shadowmapPayload, lights ) )
break;
smidx++;
}

53
Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs


public delegate void VariantDelegate( Light l, ShadowAlgorithm dataAlgorithm, ShadowVariant dataVariant, ShadowPrecision dataPrecision, ref int[] dataContainer );
public delegate GPUShadowType ShadowLightTypeDelegate(Light l);
// default implementation based on legacy Unity
static public GPUShadowType ShadowLightType(Light l)
{
GPUShadowType shadowType = GPUShadowType.Unknown;
switch (l.type)
{
case LightType.Spot:
shadowType = GPUShadowType.Spot;
break;
case LightType.Directional:
shadowType = GPUShadowType.Directional;
break;
case LightType.Point:
shadowType = GPUShadowType.Point;
break;
// area lights by themselves can't be mapped to any GPU type
}
return shadowType;
}
struct Dels
{
public VariantDelegate low;

}
Override[] m_GlobalOverrides = new Override[(int)GPUShadowType.MAX];
ShadowLightTypeDelegate m_shadowLightType;
Dictionary<ShadowAlgorithm, Entry>[] m_Entries = new Dictionary<ShadowAlgorithm, Entry>[ShadowConstants.Counts.k_GPUShadowType]
{ new Dictionary<ShadowAlgorithm, Entry>(),

// Init default delegate
public ShadowRegistry() { m_shadowLightType = ShadowLightType; }
}
public GPUShadowType GetShadowLightType(Light l)
{
return m_shadowLightType(l);
}
public void SetShadowLightTypeDelegate(ShadowLightTypeDelegate del)
{
m_shadowLightType = del;
}
public void Register( GPUShadowType type, ShadowPrecision precision, ShadowAlgorithm algorithm, string algorithmDescriptor, ShadowVariant[] variants, string[] variantDescriptors, VariantDelegate[] variantDelegates )

public void Draw( Light l )
{
AdditionalLightData ald = l.GetComponent<AdditionalLightData>();
Debug.Assert(ald != null, "Light has no valid AdditionalLightData component attached.");
AdditionalShadowData asd = l.GetComponent<AdditionalShadowData>();
Debug.Assert(asd != null, "Light has no valid AdditionalShadowData component attached.");
GPUShadowType shadowType;
ShadowUtils.MapLightType( ald.archetype, l.type, out shadowType );
GPUShadowType shadowType = GetShadowLightType(l);
// check if this has supported shadows
if( (int) shadowType >= ShadowConstants.Counts.k_GPUShadowType )

shadowPrecision = (int) m_GlobalOverrides[(int)shadowType].precision;
}
else
ald.GetShadowAlgorithm( out shadowAlgorithm, out shadowVariant, out shadowPrecision );
asd.GetShadowAlgorithm( out shadowAlgorithm, out shadowVariant, out shadowPrecision );
DrawWidgets( l, shadowType, (ShadowAlgorithm) shadowAlgorithm, (ShadowVariant) shadowVariant, (ShadowPrecision) shadowPrecision, globalOverride );
}

}
}
AdditionalLightData ald = l.GetComponent<AdditionalLightData>();
AdditionalShadowData asd = l.GetComponent<AdditionalShadowData>();
shadowData = ald.GetShadowData( (int) packedAlgo );
shadowData = asd.GetShadowData( (int) packedAlgo );
UnityEditor.EditorGUILayout.EndHorizontal();

e.variantDels[(int) shadowVariant].high( l, shadowAlgorithm, shadowVariant, shadowPrecision, ref shadowData );
ald.SetShadowAlgorithm( (int) shadowAlgorithm, (int) shadowVariant, (int) shadowPrecision, (int) packedAlgo, shadowData );
asd.SetShadowAlgorithm( (int) shadowAlgorithm, (int) shadowVariant, (int) shadowPrecision, (int) packedAlgo, shadowData );
UnityEditor.EditorGUI.indentLevel--;
#endif

51
Assets/ScriptableRenderPipeline/Core/Shadow/ShadowUtilities.cs


// Cubemap faces with flipped z coordinate.
// These matrices do NOT match what we have in Skybox.cpp.
// The C++ runtime flips y as well and requires patching up
// the culling state. Using these matrices keeps the winding
// the culling state. Using these matrices keeps the winding
// order, but may need some special treatment if rendering
// into an actual cubemap.
public static readonly Matrix4x4[] kCubemapFaces = new Matrix4x4[]

cullResults.ComputeDirectionalShadowMatricesAndCullingPrimitives( lightIndex, (int) cascadeIdx, cascadeCount, ratios, (int) width, nearPlaneOffset, out view, out proj, out splitData );
// and the compound
return proj * view;
}
public static bool MapLightType( LightType lt, out HDPipeline.GPULightType gputype, out GPUShadowType shadowtype )
{
switch( lt )
{
case LightType.Spot : gputype = HDPipeline.GPULightType.Spot; shadowtype = GPUShadowType.Spot; return true;
case LightType.Directional : gputype = HDPipeline.GPULightType.Directional; shadowtype = GPUShadowType.Directional; return true;
case LightType.Point : gputype = HDPipeline.GPULightType.Point; shadowtype = GPUShadowType.Point; return true;
default:
case LightType.Area : gputype = HDPipeline.GPULightType.Rectangle; shadowtype = GPUShadowType.Unknown; return false; // area lights by themselves can't be mapped to any GPU type
}
}
public static bool MapLightType(LightArchetype la, LightType lt, out GPUShadowType shadowtype)
{
switch (la)
{
case LightArchetype.Punctual:
return MapLightType(lt, out shadowtype);
case LightArchetype.Area:
shadowtype = GPUShadowType.Unknown;
return true;
case LightArchetype.Projector:
shadowtype = GPUShadowType.Unknown;
return true;
default:
shadowtype = GPUShadowType.Unknown;
return false; // <- probably not what you want
}
}
public static bool MapLightType(LightType lt, out GPUShadowType shadowtype)
{
switch (lt)
{
case LightType.Spot:
shadowtype = GPUShadowType.Spot;
return true;
case LightType.Directional:
shadowtype = GPUShadowType.Directional;
return true;
case LightType.Point:
shadowtype = GPUShadowType.Point;
return true;
default:
case LightType.Area:
shadowtype = GPUShadowType.Unknown;
return false; // area lights by themselves can't be mapped to any GPU type
}
}
public static GPUShadowAlgorithm Pack( ShadowAlgorithm algo, ShadowVariant vari, ShadowPrecision prec )

8
Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs


SetupGBuffer(camera.pixelWidth, camera.pixelHeight, cmd);
loop.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
// render opaque objects using Deferred pass
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("Deferred"))
{

for (int i = 0; i < lcnt; ++i)
{
VisibleLight vl = inputs.visibleLights[i];
if (vl.light.shadows != LightShadows.None && vl.light.GetComponent<AdditionalLightData>().shadowDimmer > 0.0f)
if (vl.light.shadows != LightShadows.None && vl.light.GetComponent<AdditionalShadowData>().shadowDimmer > 0.0f)
m_ShadowRequests.Add(i);
}
// pass this list to a routine that assigns shadows based on some heuristic

continue;
m_ShadowMgr.UpdateCullingParameters( ref cullingParams );
CullResults.Cull(ref cullingParams, renderContext, ref m_CullResults);
ExecuteRenderLoop(camera, m_CullResults, renderContext);
}

cmd.SetGlobalVector("g_vShadow3x3PCFTerms3", m_Shadow3X3PCFTerms[3]);
loop.ExecuteCommandBuffer(cmd);
}
private float PerceptualRoughnessToBlinnPhongPower(float perceptualRoughness)

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


{
public class HDRenderPipelineMenuItems
{
[UnityEditor.MenuItem("HDRenderPipeline/Add \"Additional Light Data\" (if not present)")]
[UnityEditor.MenuItem("HDRenderPipeline/Add \"Additional Light-shadow Data\" (if not present)")]
static void AddAdditionalLightData()
{
Light[] lights = GameObject.FindObjectsOfType(typeof(Light)) as Light[];

// Do not add a component if there already is one.
if (light.GetComponent<AdditionalLightData>() == null)
if (light.GetComponent<HDAdditionalLightData>() == null)
{
light.gameObject.AddComponent<HDAdditionalLightData>();
}
if (light.GetComponent<AdditionalShadowData>() == null)
light.gameObject.AddComponent<AdditionalLightData>();
light.gameObject.AddComponent<AdditionalShadowData>();
}
}
}

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


static ComputeBuffer s_ShadowDataBuffer;
static ComputeBuffer s_ShadowPayloadBuffer;
public static GPUShadowType HDShadowLightType(Light l)
{
// We only process light with additional data
var ald = l.GetComponent<HDAdditionalLightData>();
if (ald == null)
{
return ShadowRegistry.ShadowLightType(l);
}
GPUShadowType shadowType = GPUShadowType.Unknown;
switch (ald.archetype)
{
case LightArchetype.Punctual:
shadowType = ShadowRegistry.ShadowLightType(l);
break;
// Area and projector not supported yet
}
return shadowType;
}
public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSettings, out IShadowManager shadowManager)
{
s_ShadowDataBuffer = new ComputeBuffer( k_MaxShadowDataSlots, System.Runtime.InteropServices.Marshal.SizeOf( typeof( ShadowData ) ) );

m_ShadowMgr.SetGlobalShadowOverride( GPUShadowType.Point , ShadowAlgorithm.PCF, ShadowVariant.V4, ShadowPrecision.High, useGlobalOverrides );
m_ShadowMgr.SetGlobalShadowOverride( GPUShadowType.Spot , ShadowAlgorithm.PCF, ShadowVariant.V4, ShadowPrecision.High, useGlobalOverrides );
m_ShadowMgr.SetGlobalShadowOverride( GPUShadowType.Directional , ShadowAlgorithm.PCF, ShadowVariant.V4, ShadowPrecision.High, useGlobalOverrides );
m_ShadowMgr.SetShadowLightTypeDelegate(HDShadowLightType);
shadowManager = m_ShadowMgr;
}

// clustered light list specific buffers and data end
private static GameObject s_DefaultAdditionalLightDataGameObject;
private static AdditionalLightData s_DefaultAdditionalLightData;
private static HDAdditionalLightData s_DefaultAdditionalLightData;
bool usingFptl
{

}
}
private static AdditionalLightData DefaultAdditionalLightData
private static HDAdditionalLightData DefaultAdditionalLightData
{
get
{

s_DefaultAdditionalLightDataGameObject.hideFlags = HideFlags.HideAndDontSave;
s_DefaultAdditionalLightData = s_DefaultAdditionalLightDataGameObject.AddComponent<AdditionalLightData>();
s_DefaultAdditionalLightData = s_DefaultAdditionalLightDataGameObject.AddComponent<HDAdditionalLightData>();
s_DefaultAdditionalLightDataGameObject.SetActive(false);
}
return s_DefaultAdditionalLightData;

return new Vector3(light.finalColor.r, light.finalColor.g, light.finalColor.b);
}
public bool GetDirectionalLightData(ShadowSettings shadowSettings, GPULightType gpuLightType, VisibleLight light, AdditionalLightData additionalData, int lightIndex)
public bool GetDirectionalLightData(ShadowSettings shadowSettings, GPULightType gpuLightType, VisibleLight light, HDAdditionalLightData additionalData, AdditionalShadowData additionalShadowData, int lightIndex)
{
var directionalLightData = new DirectionalLightData();

return 1.0f - Mathf.Clamp01((distanceToCamera - distanceFadeNear) / (fadeDistance - distanceFadeNear));
}
public bool GetLightData(ShadowSettings shadowSettings, Camera camera, GPULightType gpuLightType, VisibleLight light, AdditionalLightData additionalData, int lightIndex)
public bool GetLightData(ShadowSettings shadowSettings, Camera camera, GPULightType gpuLightType, VisibleLight light, HDAdditionalLightData additionalLightData, AdditionalShadowData additionalshadowData, int lightIndex)
{
var lightData = new LightData();

{
var spotAngle = light.spotAngle;
var innerConePercent = additionalData.GetInnerSpotPercent01();
var innerConePercent = additionalLightData.GetInnerSpotPercent01();
var cosSpotOuterHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * Mathf.Deg2Rad), 0.0f, 1.0f);
var sinSpotOuterHalfAngle = Mathf.Sqrt(1.0f - cosSpotOuterHalfAngle * cosSpotOuterHalfAngle);
var cosSpotInnerHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * innerConePercent * Mathf.Deg2Rad), 0.0f, 1.0f); // inner cone

}
float distanceToCamera = (lightData.positionWS - camera.transform.position).magnitude;
float distanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalData.fadeDistance);
float lightScale = additionalData.lightDimmer * distanceFade;
float distanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalLightData.fadeDistance);
float lightScale = additionalLightData.lightDimmer * distanceFade;
lightData.diffuseScale = additionalData.affectDiffuse ? lightScale * m_TileSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalData.affectSpecular ? lightScale * m_TileSettings.specularGlobalDimmer : 0.0f;
lightData.diffuseScale = additionalLightData.affectDiffuse ? lightScale * m_TileSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalLightData.affectSpecular ? lightScale * m_TileSettings.specularGlobalDimmer : 0.0f;
if (lightData.diffuseScale <= 0.0f && lightData.specularScale <= 0.0f)
return false;

break;
}
if (additionalData.archetype == LightArchetype.Projector)
if (additionalLightData.archetype == LightArchetype.Projector)
float shadowDistanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalData.shadowFadeDistance);
lightData.shadowDimmer = additionalData.shadowDimmer * shadowDistanceFade;
if (additionalshadowData)
{
float shadowDistanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalshadowData.shadowFadeDistance);
lightData.shadowDimmer = additionalshadowData.shadowDimmer * shadowDistanceFade;
}
else
{
lightData.shadowDimmer = 1.0f;
}
// fix up shadow information
int shadowIdx;

}
if (additionalData.archetype != LightArchetype.Punctual)
if (additionalLightData.archetype != LightArchetype.Punctual)
lightData.size = new Vector2(additionalData.lightLength, additionalData.lightWidth);
lightData.size = new Vector2(additionalLightData.lightLength, additionalLightData.lightWidth);
}
m_lightList.lights.Add(lightData);

for (int i = 0; i < lcnt; ++i)
{
VisibleLight vl = cullResults.visibleLights[i];
AdditionalLightData ald = vl.light.GetComponent<AdditionalLightData>();
if( vl.light.shadows != LightShadows.None && ald != null && ald.shadowDimmer > 0.0f )
AdditionalShadowData asd = vl.light.GetComponent<AdditionalShadowData>();
if( vl.light.shadows != LightShadows.None && asd != null && asd.shadowDimmer > 0.0f )
m_ShadowRequests.Add( i );
}
// pass this list to a routine that assigns shadows based on some heuristic

var light = cullResults.visibleLights[lightIndex];
// We only process light with additional data
var additionalData = light.light.GetComponent<AdditionalLightData>();
var additionalData = light.light.GetComponent<HDAdditionalLightData>();
if (additionalData == null)
additionalData = DefaultAdditionalLightData;

int lightIndex = (int)(sortKey & 0xFFFF);
var light = cullResults.visibleLights[lightIndex];
var additionalData = light.light.GetComponent<AdditionalLightData>() ?? DefaultAdditionalLightData;
var additionalLightData = light.light.GetComponent<HDAdditionalLightData>() ?? DefaultAdditionalLightData;
var additionalShadowData = light.light.GetComponent<AdditionalShadowData>(); // Can be null
if (GetDirectionalLightData(shadowSettings, gpuLightType, light, additionalData, lightIndex))
if (GetDirectionalLightData(shadowSettings, gpuLightType, light, additionalLightData, additionalShadowData, lightIndex))
if(GetLightData(shadowSettings, camera, gpuLightType, light, additionalData, lightIndex))
if (GetLightData(shadowSettings, camera, gpuLightType, light, additionalLightData, additionalShadowData, lightIndex))
{
switch (lightCategory)
{

cmd.SetComputeIntParam(buildDispatchIndirectShader, "g_NumTilesX", numTilesX);
cmd.DispatchCompute(buildDispatchIndirectShader, s_BuildDispatchIndirectKernel, (numTiles + 63) / 64, 1, 1);
}
loop.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

273
Assets/TestScenes/FPTL/FPTL.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
OcclusionCullingSettings:
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
serializedVersion: 2
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
serializedVersion: 7
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3

m_AmbientSkyColor: {r: 0, g: 0, b: 0, a: 1}
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_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1

--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 7
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2

m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 4
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024

m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_DirectLightInLightProbes: 1
m_MixedBakeMode: 1
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 0
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_RuntimeCPUUsage: 25
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &344719374
GameObject:

m_GameObject: {fileID: 550164696}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
shadowResolution: 976
innerSpotPercent: 77
shadowResolution: 512
shadowDimmer: 1
shadowFadeDistance: 10000
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowAlgorithm: 0
shadowVariant: 1
shadowPrecision: 0
shadowData:
format: 1
data: 0bd7a33b0000803f
shadowDatas:
- format: 0
data: 0bd7a33b0000803f
- format: 1
data: 0bd7a33b0000803f
--- !u!108 &550164698
Light:
m_ObjectHideFlags: 0

m_Enabled: 1
serializedVersion: 7
serializedVersion: 8
m_Type: 0
m_Color: {r: 0.8455882, g: 0.42901167, b: 0.42901167, a: 1}
m_Intensity: 1.5

m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &550164699

m_GameObject: {fileID: 756999128}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
shadowResolution: 955
innerSpotPercent: 66.4
shadowResolution: 512
shadowDimmer: 1
shadowFadeDistance: 10000
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowAlgorithm: 0
shadowVariant: 1
shadowPrecision: 0
shadowData:
format: 1
data: 0bd7a33b0000803f
shadowDatas:
- format: 0
data: 0bd7a33b0000803f
- format: 1
data: 0bd7a33b0000803f
--- !u!108 &756999130
Light:
m_ObjectHideFlags: 0

m_Enabled: 1
serializedVersion: 7
serializedVersion: 8
m_Type: 2
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 2.41

m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &756999131

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &942239536
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!64 &1064871614
MeshCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1090653690
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1100543301
SphereCollider:

m_GameObject: {fileID: 1403765353}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
shadowResolution: 955
innerSpotPercent: 66.4
shadowResolution: 512
shadowDimmer: 1
shadowFadeDistance: 10000
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowAlgorithm: 0
shadowVariant: 1
shadowPrecision: 0
shadowData:
format: 1
data: 0bd7a33b0000803f
shadowDatas:
- format: 0
data: 0bd7a33b0000803f
- format: 1
data: 0bd7a33b0000803f
--- !u!108 &1403765355
Light:
m_ObjectHideFlags: 0

m_Enabled: 1
serializedVersion: 7
serializedVersion: 8
m_Type: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1.94

m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1403765356

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1409545157
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1469174315
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1506796424
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1597621868
SphereCollider:

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1713034008}
m_Enabled: 1
m_ExtensionPropertyValues: []
--- !u!124 &1713034010
Behaviour:
m_ObjectHideFlags: 0

m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1758207074
SphereCollider:

m_GameObject: {fileID: 1810843056}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
shadowResolution: 955
innerSpotPercent: 66.4
shadowResolution: 512
shadowDimmer: 1
shadowFadeDistance: 10000
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowAlgorithm: 0
shadowVariant: 1
shadowPrecision: 0
shadowData:
format: 1
data: 0bd7a33b0000803f
shadowDatas:
- format: 0
data: 0bd7a33b0000803f
- format: 1
data: 0bd7a33b0000803f
--- !u!108 &1810843058
Light:
m_ObjectHideFlags: 0

m_Enabled: 1
serializedVersion: 7
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.98096883, b: 0.8382353, a: 1}
m_Intensity: 0.65

m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1810843059

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1818419757
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1946201411
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &2054101902
SphereCollider:

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_StitchSeams: 0
m_SelectedEditorRenderState: 3
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &2136471013
SphereCollider:

174
Assets/ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs


namespace UnityEngine.Experimental.Rendering
{
[RequireComponent(typeof(Light))]
public class AdditionalShadowData : MonoBehaviour
{
public const int DefaultShadowResolution = 512;
public int shadowResolution = DefaultShadowResolution;
public static int GetShadowResolution(AdditionalShadowData shadowData)
{
if (shadowData != null)
return shadowData.shadowResolution;
else
return DefaultShadowResolution;
}
[Range(0.0F, 1.0F)]
public float shadowDimmer = 1.0f;
public float shadowFadeDistance = 10000.0f;
// shadow related parameters
[System.Serializable]
public struct ShadowData
{
public int format;
public int[] data;
};
[HideInInspector, SerializeField]
private int shadowCascadeCount = 4;
[HideInInspector, SerializeField]
private float[] shadowCascadeRatios = new float[3] { 0.05f, 0.2f, 0.3f };
[HideInInspector, SerializeField]
private int shadowAlgorithm;
[HideInInspector, SerializeField]
private int shadowVariant;
[HideInInspector, SerializeField]
private int shadowPrecision;
[HideInInspector, SerializeField]
private ShadowData shadowData;
[HideInInspector, SerializeField]
private ShadowData[] shadowDatas = new ShadowData[0];
public int cascadeCount { get { return shadowCascadeCount; } }
public void GetShadowCascades(out int cascadeCount, out float[] cascadeRatios) { cascadeCount = shadowCascadeCount; cascadeRatios = shadowCascadeRatios; }
public void GetShadowAlgorithm(out int algorithm, out int variant, out int precision) { algorithm = shadowAlgorithm; variant = shadowVariant; precision = shadowPrecision; }
public void SetShadowAlgorithm(int algorithm, int variant, int precision, int format, int[] data)
{
shadowAlgorithm = algorithm;
shadowVariant = variant;
shadowPrecision = precision;
shadowData.format = format;
shadowData.data = data;
int idx = FindShadowData(format);
if (idx < 0)
{
idx = shadowDatas.Length;
ShadowData[] tmp = new ShadowData[idx + 1];
for (int i = 0; i < idx; ++i)
tmp[i] = shadowDatas[i];
shadowDatas = tmp;
}
shadowDatas[idx].format = format;
shadowDatas[idx].data = data != null ? data : new int[0];
}
// Load a specific shadow data. Returns null if requested data is not present.
public int[] GetShadowData(int shadowDataFormat)
{
if (shadowData.format == shadowDataFormat)
return shadowData.data;
int idx = FindShadowData(shadowDataFormat);
return idx >= 0 ? shadowDatas[idx].data : null;
}
// Returns the currently set shadow data and format. Can return null.
public int[] GetShadowData(out int shadowDataFormat)
{
shadowDataFormat = shadowData.format;
return shadowData.data;
}
#if UNITY_EDITOR
public void CompactShadowData()
{
shadowDatas = new ShadowData[0];
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
private int FindShadowData(int shadowDataFormat)
{
for (int i = 0; i < shadowDatas.Length; ++i)
{
if (shadowDatas[i].format == shadowDataFormat)
return i;
}
return -1;
}
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(AdditionalShadowData))]
[UnityEditor.CanEditMultipleObjects]
public class AdditionalShadowDataEditor : UnityEditor.Editor
{
static ShadowRegistry m_ShadowRegistry;
#pragma warning disable 414 // CS0414 The private field '...' is assigned but its value is never used
UnityEditor.SerializedProperty m_ShadowAlgorithm;
UnityEditor.SerializedProperty m_ShadowVariant;
UnityEditor.SerializedProperty m_ShadowData;
UnityEditor.SerializedProperty m_ShadowDatas;
#pragma warning restore 414
UnityEditor.SerializedProperty m_ShadowCascadeCount;
UnityEditor.SerializedProperty m_ShadowCascadeRatios;
public static void SetRegistry( ShadowRegistry registry ) { m_ShadowRegistry = registry; }
void OnEnable()
{
m_ShadowAlgorithm = serializedObject.FindProperty( "shadowAlgorithm" );
m_ShadowVariant = serializedObject.FindProperty( "shadowVariant" );
m_ShadowData = serializedObject.FindProperty( "shadowData" );
m_ShadowDatas = serializedObject.FindProperty( "shadowDatas" );
m_ShadowCascadeCount = serializedObject.FindProperty( "shadowCascadeCount" );
m_ShadowCascadeRatios = serializedObject.FindProperty( "shadowCascadeRatios" );
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if( m_ShadowRegistry == null )
return;
AdditionalShadowData asd = (AdditionalShadowData) target;
if( asd == null )
return;
UnityEditor.EditorGUI.BeginChangeCheck();
m_ShadowRegistry.Draw( asd.gameObject.GetComponent<Light>() );
serializedObject.Update();
// cascade code
if( asd.gameObject.GetComponent<Light>().type == LightType.Directional )
{
UnityEditor.EditorGUI.BeginChangeCheck();
UnityEditor.EditorGUILayout.PropertyField( m_ShadowCascadeCount );
if( UnityEditor.EditorGUI.EndChangeCheck() )
{
const int kMaxCascades = (int) ShadowAtlas.k_MaxCascadesInShader; // depending on where you look this is either 32 or 4, so we're limiting it to 4 for now
int newcnt = m_ShadowCascadeCount.intValue <= 0 ? 1 : (m_ShadowCascadeCount.intValue > kMaxCascades ? kMaxCascades : m_ShadowCascadeCount.intValue);
m_ShadowCascadeCount.intValue = newcnt;
m_ShadowCascadeRatios.arraySize = newcnt-1;
}
UnityEditor.EditorGUI.indentLevel++;
for( int i = 0; i < m_ShadowCascadeRatios.arraySize; i++ )
{
UnityEditor.EditorGUILayout.Slider( m_ShadowCascadeRatios.GetArrayElementAtIndex( i ), 0.0f, 1.0f, new GUIContent( "Cascade " + i ) );
}
UnityEditor.EditorGUI.indentLevel--;
}
if( UnityEditor.EditorGUI.EndChangeCheck() )
{
UnityEditor.EditorUtility.SetDirty( asd );
UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
UnityEditor.SceneView.RepaintAll();
}
serializedObject.ApplyModifiedProperties();
}
}
#endif
}

13
Assets/ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs.meta


fileFormatVersion: 2
guid: c6c2871f720b2af4e9210febdac74517
timeCreated: 1498052298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

35
Assets/ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs


namespace UnityEngine.Experimental.Rendering
{
public enum LightArchetype { Punctual, Area, Projector };
//@TODO: We should continuously move these values
// into the engine when we can see them being generally useful
[RequireComponent(typeof(Light))]
public class HDAdditionalLightData : MonoBehaviour
{
[Range(0.0F, 100.0F)]
public float m_innerSpotPercent = 0.0f; // To display this field in the UI this need to be public
public float GetInnerSpotPercent01()
{
return Mathf.Clamp(m_innerSpotPercent, 0.0f, 100.0f) / 100.0f;
}
[Range(0.0F, 1.0F)]
public float lightDimmer = 1.0f;
// Not used for directional lights.
public float fadeDistance = 10000.0f;
public bool affectDiffuse = true;
public bool affectSpecular = true;
public LightArchetype archetype = LightArchetype.Punctual;
[Range(0.0f, 20.0f)]
public float lightLength = 0.0f; // Area & projector lights
[Range(0.0f, 20.0f)]
public float lightWidth = 0.0f; // Area & projector lights
}
}

195
Assets/ScriptableRenderPipeline/Core/AdditionalLightData.cs


namespace UnityEngine.Experimental.Rendering
{
public enum LightArchetype { Punctual, Area, Projector };
//@TODO: We should continuously move these values
// into the engine when we can see them being generally useful
[RequireComponent(typeof(Light))]
public class AdditionalLightData : MonoBehaviour
{
public const int DefaultShadowResolution = 512;
public int shadowResolution = DefaultShadowResolution;
public static int GetShadowResolution(AdditionalLightData lightData)
{
if (lightData != null)
return lightData.shadowResolution;
else
return DefaultShadowResolution;
}
[Range(0.0F, 100.0F)]
public float m_innerSpotPercent = 0.0f; // To display this field in the UI this need to be public
public float GetInnerSpotPercent01()
{
return Mathf.Clamp(m_innerSpotPercent, 0.0f, 100.0f) / 100.0f;
}
[Range(0.0F, 1.0F)]
public float shadowDimmer = 1.0f;
[Range(0.0F, 1.0F)]
public float lightDimmer = 1.0f;
// Not used for directional lights.
public float fadeDistance = 10000.0f;
public float shadowFadeDistance = 10000.0f;
public bool affectDiffuse = true;
public bool affectSpecular = true;
public LightArchetype archetype = LightArchetype.Punctual;
[Range(0.0f, 20.0f)]
public float lightLength = 0.0f; // Area & projector lights
[Range(0.0f, 20.0f)]
public float lightWidth = 0.0f; // Area & projector lights
// shadow related parameters
[System.Serializable]
public struct ShadowData
{
public int format;
public int[] data;
};
[HideInInspector, SerializeField] private int shadowCascadeCount = 4;
[HideInInspector, SerializeField] private float[] shadowCascadeRatios = new float[3]{ 0.05f, 0.2f, 0.3f };
[HideInInspector, SerializeField] private int shadowAlgorithm;
[HideInInspector, SerializeField] private int shadowVariant;
[HideInInspector, SerializeField] private int shadowPrecision;
[HideInInspector, SerializeField] private ShadowData shadowData;
[HideInInspector, SerializeField] private ShadowData[] shadowDatas = new ShadowData[0];
public int cascadeCount { get { return shadowCascadeCount; } }
public void GetShadowCascades( out int cascadeCount, out float[] cascadeRatios ) { cascadeCount = shadowCascadeCount; cascadeRatios = shadowCascadeRatios; }
public void GetShadowAlgorithm( out int algorithm, out int variant, out int precision ) { algorithm = shadowAlgorithm; variant = shadowVariant; precision = shadowPrecision; }
public void SetShadowAlgorithm( int algorithm, int variant, int precision, int format, int[] data )
{
shadowAlgorithm = algorithm;
shadowVariant = variant;
shadowPrecision = precision;
shadowData.format = format;
shadowData.data = data;
int idx = FindShadowData( format );
if( idx < 0 )
{
idx = shadowDatas.Length;
ShadowData[] tmp = new ShadowData[idx+1];
for( int i = 0; i < idx; ++i )
tmp[i] = shadowDatas[i];
shadowDatas = tmp;
}
shadowDatas[idx].format = format;
shadowDatas[idx].data = data != null ? data : new int[0];
}
// Load a specific shadow data. Returns null if requested data is not present.
public int[] GetShadowData( int shadowDataFormat )
{
if( shadowData.format == shadowDataFormat )
return shadowData.data;
int idx = FindShadowData( shadowDataFormat );
return idx >= 0 ? shadowDatas[idx].data : null;
}
// Returns the currently set shadow data and format. Can return null.
public int[] GetShadowData( out int shadowDataFormat )
{
shadowDataFormat = shadowData.format;
return shadowData.data;
}
#if UNITY_EDITOR
public void CompactShadowData()
{
shadowDatas = new ShadowData[0];
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
private int FindShadowData( int shadowDataFormat )
{
for( int i = 0; i < shadowDatas.Length; ++i )
{
if( shadowDatas[i].format == shadowDataFormat )
return i;
}
return -1;
}
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(AdditionalLightData))]
[UnityEditor.CanEditMultipleObjects]
public class AdditionalLightDataEditor : UnityEditor.Editor
{
static ShadowRegistry m_ShadowRegistry;
#pragma warning disable 414 // CS0414 The private field '...' is assigned but its value is never used
UnityEditor.SerializedProperty m_ShadowAlgorithm;
UnityEditor.SerializedProperty m_ShadowVariant;
UnityEditor.SerializedProperty m_ShadowData;
UnityEditor.SerializedProperty m_ShadowDatas;
#pragma warning restore 414
UnityEditor.SerializedProperty m_ShadowCascadeCount;
UnityEditor.SerializedProperty m_ShadowCascadeRatios;
public static void SetRegistry( ShadowRegistry registry ) { m_ShadowRegistry = registry; }
void OnEnable()
{
m_ShadowAlgorithm = serializedObject.FindProperty( "shadowAlgorithm" );
m_ShadowVariant = serializedObject.FindProperty( "shadowVariant" );
m_ShadowData = serializedObject.FindProperty( "shadowData" );
m_ShadowDatas = serializedObject.FindProperty( "shadowDatas" );
m_ShadowCascadeCount = serializedObject.FindProperty( "shadowCascadeCount" );
m_ShadowCascadeRatios = serializedObject.FindProperty( "shadowCascadeRatios" );
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if( m_ShadowRegistry == null )
return;
AdditionalLightData ald = (AdditionalLightData) target;
if( ald == null )
return;
UnityEditor.EditorGUI.BeginChangeCheck();
m_ShadowRegistry.Draw( ald.gameObject.GetComponent<Light>() );
serializedObject.Update();
// cascade code
if( ald.gameObject.GetComponent<Light>().type == LightType.Directional )
{
UnityEditor.EditorGUI.BeginChangeCheck();
UnityEditor.EditorGUILayout.PropertyField( m_ShadowCascadeCount );
if( UnityEditor.EditorGUI.EndChangeCheck() )
{
const int kMaxCascades = (int) ShadowAtlas.k_MaxCascadesInShader; // depending on where you look this is either 32 or 4, so we're limiting it to 4 for now
int newcnt = m_ShadowCascadeCount.intValue <= 0 ? 1 : (m_ShadowCascadeCount.intValue > kMaxCascades ? kMaxCascades : m_ShadowCascadeCount.intValue);
m_ShadowCascadeCount.intValue = newcnt;
m_ShadowCascadeRatios.arraySize = newcnt-1;
}
UnityEditor.EditorGUI.indentLevel++;
for( int i = 0; i < m_ShadowCascadeRatios.arraySize; i++ )
{
UnityEditor.EditorGUILayout.Slider( m_ShadowCascadeRatios.GetArrayElementAtIndex( i ), 0.0f, 1.0f, new GUIContent( "Cascade " + i ) );
}
UnityEditor.EditorGUI.indentLevel--;
}
if( UnityEditor.EditorGUI.EndChangeCheck() )
{
UnityEditor.EditorUtility.SetDirty( ald );
UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
UnityEditor.SceneView.RepaintAll();
}
serializedObject.ApplyModifiedProperties();
}
}
#endif
}

/Assets/ScriptableRenderPipeline/Core/AdditionalLightData.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs.meta

正在加载...
取消
保存