浏览代码

Merge pull request #931 from Unity-Technologies/Add-GI-delegate

Add gi delegate
/main
GitHub 7 年前
当前提交
8617a030
共有 6 个文件被更改,包括 195 次插入16 次删除
  1. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
  3. 20
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ProbeWrapper.cs
  5. 165
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs
  6. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs.meta

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


using System.Diagnostics;
using System.Linq;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.Experimental.GlobalIllumination;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

rendererSupportsReflectionProbes = true
};
//Lightmapping.SetDelegate(GlobalIlluminationUtils.hdLightsDelegate);
#if UNITY_EDITOR
SceneViewDrawMode.SetupDrawMode();
#endif

SupportedRenderingFeatures.active = new SupportedRenderingFeatures();
Lightmapping.ResetDelegate();
#if UNITY_EDITOR
SceneViewDrawMode.ResetDrawMode();
#endif

ConfigureForShadowMask(enableBakeShadowMask, cmd);
StartStereoRendering(renderContext, hdCamera.camera);
ClearBuffers(hdCamera, cmd);
// TODO: Add stereo occlusion mask

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs


public const RendererConfiguration k_RendererConfigurationBakedLighting = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume;
public const RendererConfiguration k_RendererConfigurationBakedLightingWithShadowMask = k_RendererConfigurationBakedLighting | RendererConfiguration.PerObjectOcclusionProbe | RendererConfiguration.PerObjectOcclusionProbeProxyVolume | RendererConfiguration.PerObjectShadowMask;
static public HDAdditionalReflectionData s_DefaultHDAdditionalReflectionData { get { return ComponentSingleton<HDAdditionalReflectionData>.instance; } }
static public HDAdditionalLightData s_DefaultHDAdditionalLightData { get { return ComponentSingleton<HDAdditionalLightData>.instance; } }
static public HDAdditionalCameraData s_DefaultHDAdditionalCameraData { get { return ComponentSingleton<HDAdditionalCameraData>.instance; } }
public static Material GetBlitMaterial()
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;

20
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


public static int s_TileSizeClustered = 32;
// feature variants
public static int s_NumFeatureVariants = 27;
public static int s_NumFeatureVariants = 27;
// Following define the maximum number of bits use in each feature category.
public static uint s_LightFeatureMaskFlags = 0xFFF000;

static Texture2DArray s_DefaultTexture2DArray;
static Cubemap s_DefaultTextureCube;
static HDAdditionalReflectionData defaultHDAdditionalReflectionData { get { return ComponentSingleton<HDAdditionalReflectionData>.instance; } }
static HDAdditionalLightData defaultHDAdditionalLightData { get { return ComponentSingleton<HDAdditionalLightData>.instance; } }
static HDAdditionalCameraData defaultHDAdditionalCameraData { get { return ComponentSingleton<HDAdditionalCameraData>.instance; } }
PlanarReflectionProbeCache m_ReflectionPlanarProbeCache;
ReflectionProbeCache m_ReflectionProbeCache;

directionalLightData.positionWS = light.light.transform.position;
directionalLightData.color = GetLightColor(light);
// Caution: This is bad but if additionalData == defaultHDAdditionalLightData it mean we are trying to promote legacy lights, which is the case for the preview for example, so we need to multiply by PI as legacy Unity do implicit divide by PI for direct intensity.
// So we expect that all light with additionalData == defaultHDAdditionalLightData are currently the one from the preview, light in scene MUST have additionalData
directionalLightData.color *= (defaultHDAdditionalLightData == additionalData) ? Mathf.PI : 1.0f;
// Caution: This is bad but if additionalData == HDUtils.s_DefaultHDAdditionalLightData it mean we are trying to promote legacy lights, which is the case for the preview for example, so we need to multiply by PI as legacy Unity do implicit divide by PI for direct intensity.
// So we expect that all light with additionalData == HDUtils.s_DefaultHDAdditionalLightData are currently the one from the preview, light in scene MUST have additionalData
directionalLightData.color *= (HDUtils.s_DefaultHDAdditionalLightData == additionalData) ? Mathf.PI : 1.0f;
directionalLightData.diffuseScale = additionalData.affectDiffuse ? diffuseDimmer : 0.0f;
directionalLightData.specularScale = additionalData.affectSpecular ? specularDimmer : 0.0f;

{
var light = cullResults.visibleLights[lightIndex];
// Light should always have additional data, however preview light right don't have, so we must handle the case by assigning defaultHDAdditionalLightData
// Light should always have additional data, however preview light right don't have, so we must handle the case by assigning HDUtils.s_DefaultHDAdditionalLightData
var additionalData = GetHDAdditionalLightData(light);
LightCategory lightCategory = LightCategory.Count;

m_enableBakeShadowMask = m_enableBakeShadowMask || IsBakedShadowMaskLight(light.light);
// Light should always have additional data, however preview light right don't have, so we must handle the case by assigning defaultHDAdditionalLightData
// Light should always have additional data, however preview light right don't have, so we must handle the case by assigning HDUtils.s_DefaultHDAdditionalLightData
var additionalLightData = GetHDAdditionalLightData(light);
var additionalShadowData = light.light.GetComponent<AdditionalShadowData>(); // Can be null

var add = probe.probe.GetComponent<HDAdditionalReflectionData>();
if (add == null)
{
add = defaultHDAdditionalReflectionData;
add = HDUtils.s_DefaultHDAdditionalReflectionData;
add.blendDistancePositive = Vector3.one * probe.blendDistance;
add.blendDistanceNegative = add.blendDistancePositive;
add.influenceShape = ShapeType.Box;

var add = light.light.GetComponent<HDAdditionalLightData>();
if (add == null)
{
add = defaultHDAdditionalLightData;
add = HDUtils.s_DefaultHDAdditionalLightData;
}
return add;
}

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ProbeWrapper.cs


class VisibleReflectionProbeWrapper : ProbeWrapper
{
static HDAdditionalReflectionData defaultHDAdditionalReflectionData { get { return ComponentSingleton<HDAdditionalReflectionData>.instance; } }
VisibleReflectionProbe probe;
HDAdditionalReflectionData additional;

var add = probe.probe.GetComponent<HDAdditionalReflectionData>();
if (add == null)
{
add = defaultHDAdditionalReflectionData;
add = HDUtils.s_DefaultHDAdditionalReflectionData;
add.blendDistancePositive = Vector3.one * probe.blendDistance;
add.blendDistanceNegative = add.blendDistancePositive;
add.influenceShape = ShapeType.Box;

165
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs


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;
}
};
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/GlobalIlluminationUtils.cs.meta


fileFormatVersion: 2
guid: fdcaf3aecf6718c4bb05a3616bcf6009
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存