GitHub
7 年前
当前提交
8617a030
共有 6 个文件被更改,包括 195 次插入 和 16 次删除
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
-
20ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ProbeWrapper.cs
-
165ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.GlobalIllumination; |
|||
using Unity.Collections; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class GlobalIlluminationUtils |
|||
{ |
|||
// Return true if the light must be added to the baking
|
|||
public static bool LightDataGIExtract(Light l, ref LightDataGI ld) |
|||
{ |
|||
var add = l.GetComponent<HDAdditionalLightData>(); |
|||
if (add == null) |
|||
{ |
|||
add = HDUtils.s_DefaultHDAdditionalLightData; |
|||
} |
|||
|
|||
// TODO: Only take into account the light dimmer when we have real time GI.
|
|||
|
|||
ld.instanceID = l.GetInstanceID(); |
|||
ld.color = add.affectDiffuse ? LinearColor.Convert(l.color, l.intensity) : LinearColor.Black(); |
|||
ld.indirectColor = add.affectDiffuse ? LightmapperUtils.ExtractIndirect(l) : LinearColor.Black(); |
|||
#if UNITY_EDITOR
|
|||
ld.mode = LightmapperUtils.Extract(l.lightmapBakeType); |
|||
#else
|
|||
ld.mode = LightMode.Realtime; |
|||
#endif
|
|||
ld.shadow = (byte)(l.shadows != LightShadows.None ? 1 : 0); |
|||
|
|||
if (add.lightTypeExtent == LightTypeExtent.Punctual) |
|||
{ |
|||
switch (l.type) |
|||
{ |
|||
case LightType.Directional: |
|||
ld.orientation.SetLookRotation(l.transform.forward, Vector3.up); |
|||
ld.position = Vector3.zero; |
|||
ld.range = 0.0f; |
|||
ld.coneAngle = 0.0f; |
|||
ld.innerConeAngle = 0.0f; |
|||
#if UNITY_EDITOR
|
|||
ld.shape0 = l.shadows == LightShadows.Soft ? (Mathf.Deg2Rad * l.shadowAngle) : 0.0f; |
|||
#else
|
|||
ld.shape0 = 0.0f; |
|||
#endif
|
|||
ld.shape1 = 0.0f; |
|||
ld.type = UnityEngine.Experimental.GlobalIllumination.LightType.Directional; |
|||
ld.falloff = FalloffType.Undefined; |
|||
break; |
|||
|
|||
case LightType.Spot: |
|||
|
|||
ld.orientation = l.transform.rotation; |
|||
ld.position = l.transform.position; |
|||
ld.range = l.range; |
|||
ld.coneAngle = l.spotAngle * Mathf.Deg2Rad; // coneAngle is the full angle
|
|||
ld.innerConeAngle = l.spotAngle * Mathf.Deg2Rad * add.GetInnerSpotPercent01(); |
|||
#if UNITY_EDITOR
|
|||
ld.shape0 = l.shadows == LightShadows.Soft ? l.shadowRadius : 0.0f; |
|||
#else
|
|||
ld.shape0 = 0.0f; |
|||
#endif
|
|||
ld.shape1 = 0.0f; |
|||
ld.type = UnityEngine.Experimental.GlobalIllumination.LightType.Spot; |
|||
ld.falloff = add.applyRangeAttenuation ? FalloffType.InverseSquared : FalloffType.InverseSquaredNoRangeAttenuation; |
|||
|
|||
/* |
|||
switch (add.spotLightShape) |
|||
{ |
|||
case SpotLightShape.Cone: |
|||
break; |
|||
case SpotLightShape.Pyramid: |
|||
break; |
|||
case SpotLightShape.Box: |
|||
break; |
|||
default: |
|||
Debug.Assert(false, "Encountered an unknown SpotLightShape."); |
|||
break; |
|||
} |
|||
*/ |
|||
break; |
|||
|
|||
case LightType.Point: |
|||
ld.orientation = Quaternion.identity; |
|||
ld.position = l.transform.position; |
|||
ld.range = l.range; |
|||
ld.coneAngle = 0.0f; |
|||
ld.innerConeAngle = 0.0f; |
|||
|
|||
#if UNITY_EDITOR
|
|||
ld.shape0 = l.shadows == LightShadows.Soft ? l.shadowRadius : 0.0f; |
|||
#else
|
|||
ld.shape0 = 0.0f; |
|||
#endif
|
|||
ld.shape1 = 0.0f; |
|||
ld.type = UnityEngine.Experimental.GlobalIllumination.LightType.Point; |
|||
ld.falloff = add.applyRangeAttenuation ? FalloffType.InverseSquared : FalloffType.InverseSquaredNoRangeAttenuation; |
|||
break; |
|||
|
|||
// Note: We don't support this type in HDRP, but ini just in case
|
|||
case LightType.Area: |
|||
ld.orientation = l.transform.rotation; |
|||
ld.position = l.transform.position; |
|||
ld.range = l.range; |
|||
ld.coneAngle = 0.0f; |
|||
ld.innerConeAngle = 0.0f; |
|||
#if UNITY_EDITOR
|
|||
ld.shape0 = l.areaSize.x; |
|||
ld.shape1 = l.areaSize.y; |
|||
#else
|
|||
ld.shape0 = 0.0f; |
|||
ld.shape1 = 0.0f; |
|||
#endif
|
|||
ld.type = UnityEngine.Experimental.GlobalIllumination.LightType.Rectangle; |
|||
ld.falloff = FalloffType.Undefined; |
|||
break; |
|||
|
|||
default: |
|||
Debug.Assert(false, "Encountered an unknown LightType."); |
|||
break; |
|||
} |
|||
} |
|||
else if (add.lightTypeExtent == LightTypeExtent.Rectangle) |
|||
{ |
|||
ld.orientation = l.transform.rotation; |
|||
ld.position = l.transform.position; |
|||
ld.range = l.range; |
|||
ld.coneAngle = 0.0f; |
|||
ld.innerConeAngle = 0.0f; |
|||
#if UNITY_EDITOR
|
|||
ld.shape0 = l.areaSize.x; |
|||
ld.shape1 = l.areaSize.y; |
|||
#else
|
|||
ld.shape0 = 0.0f; |
|||
ld.shape1 = 0.0f; |
|||
#endif
|
|||
ld.type = UnityEngine.Experimental.GlobalIllumination.LightType.Rectangle; |
|||
ld.falloff = add.applyRangeAttenuation ? FalloffType.InverseSquared : FalloffType.InverseSquaredNoRangeAttenuation; |
|||
} |
|||
else if (add.lightTypeExtent == LightTypeExtent.Line) |
|||
{ |
|||
|
|||
} |
|||
else |
|||
{ |
|||
Debug.Assert(false, "Encountered an unknown LightType."); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
static public Lightmapping.RequestLightsDelegate hdLightsDelegate = (Light[] requests, NativeArray<LightDataGI> lightsOutput) => |
|||
{ |
|||
// Get all lights in the scene
|
|||
LightDataGI ld = new LightDataGI(); |
|||
for (int i = 0; i < requests.Length; i++) |
|||
{ |
|||
Light l = requests[i]; |
|||
LightDataGIExtract(l, ref ld); |
|||
lightsOutput[i] = ld; |
|||
} |
|||
}; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fdcaf3aecf6718c4bb05a3616bcf6009 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue