|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using UnityEngine.Experimental.GlobalIllumination; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
using UnityEngine.Rendering.PostProcessing; |
|
|
|
using UnityEngine.XR; |
|
|
|
|
|
|
|
|
|
|
BuildShadowSettings(); |
|
|
|
SetRenderingFeatures(); |
|
|
|
GraphicsSettings.lightsUseLinearIntensity = true; |
|
|
|
|
|
|
|
PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor"); |
|
|
|
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor"); |
|
|
|
|
|
|
{ |
|
|
|
base.Render(context, cameras); |
|
|
|
|
|
|
|
GraphicsSettings.lightsUseLinearIntensity = true; |
|
|
|
SetupPerFrameShaderConstants(); |
|
|
|
|
|
|
|
// Sort cameras array by camera depth
|
|
|
|
|
|
|
// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
|
|
|
|
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
|
|
|
|
// If we precompute the terms in a MAD instruction
|
|
|
|
float spotAngle = Mathf.Deg2Rad * lightData.spotAngle; |
|
|
|
float cosOuterAngle = Mathf.Cos(spotAngle * 0.5f); |
|
|
|
float cosInneAngle = Mathf.Cos(spotAngle * 0.25f); |
|
|
|
float smoothAngleRange = cosInneAngle - cosOuterAngle; |
|
|
|
if (Mathf.Approximately(smoothAngleRange, 0.0f)) |
|
|
|
smoothAngleRange = 1.0f; |
|
|
|
|
|
|
|
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f); |
|
|
|
float cosInneAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f); |
|
|
|
float smoothAngleRange = Mathf.Max(0.001f, cosInneAngle - cosOuterAngle); |
|
|
|
float invAngleRange = 1.0f / smoothAngleRange; |
|
|
|
float add = -cosOuterAngle * invAngleRange; |
|
|
|
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f); |
|
|
|