浏览代码

[PlanarReflection] parameter renaming

/main
Frédéric Vauchelles 7 年前
当前提交
5442aee1
共有 10 个文件被更改,包括 151 次插入81 次删除
  1. 14
      SampleScenes/HDTest/PlanarReflectionTests.unity
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/SerializedPlanarReflectionProbe.cs
  3. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  5. 70
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl
  7. 45
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
  8. 50
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ProbeWrapper.cs
  9. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/VolumeProjection.hlsl
  10. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

14
SampleScenes/HDTest/PlanarReflectionTests.unity


m_AmbientSkyColor: {r: 0.2, g: 0.2, b: 0.2, a: 0}
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: 1
m_AmbientIntensity: 0
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}

m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_ReflectionIntensity: 0
m_IndirectSpecularColor: {r: 0.07321051, g: 0.076927215, b: 0.08504366, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 0}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 547467865}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 3.1386204, z: 0}
m_LocalPosition: {x: 0, y: 5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1596124444}

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 547467865}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1

m_Resolution: 128
m_UpdateFrequency: 0
m_BoxSize: {x: 20, y: 10, z: 20}
m_BoxOffset: {x: 0, y: 1.8613796, z: 0}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_NearClip: 0.3
m_FarClip: 1000
m_ShadowDistance: 100

m_Layer: 0
m_Name: Planar Reflection Probe
m_TagString: Untagged
m_Icon: {fileID: -5487077368411116049, guid: 0000000000000000d000000000000000, type: 0}
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/SerializedPlanarReflectionProbe.cs


proxyVolumeReference = serializedObject.Find((PlanarReflectionProbe p) => p.proxyVolumeReference);
influenceVolume = new SerializedInfluenceVolume(serializedObject.Find((PlanarReflectionProbe p) => p.influenceVolume));
captureOffset = serializedObject.Find((PlanarReflectionProbe p) => p.captureOffset);
captureOffset = serializedObject.Find((PlanarReflectionProbe p) => p.centerOffset);
dimmer = serializedObject.Find((PlanarReflectionProbe p) => p.dimmer);
mode = serializedObject.Find((PlanarReflectionProbe p) => p.mode);
}

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs


[GenerateHLSL]
public struct EnvLightData
{
public Vector3 capturePositionWS;
public EnvShapeType envShapeType;
public EnvShapeType envShapeType;
public int unused8;
public Vector3 forward;
public int envIndex;

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl


// PackingRules = Exact
struct EnvLightData
{
float3 positionWS;
float3 capturePositionWS;
float3 positionWS;
int unused8;
float3 forward;
int envIndex;
float3 up;

//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float3 GetPositionWS(EnvLightData value)
float3 GetCapturePositionWS(EnvLightData value)
return value.positionWS;
return value.capturePositionWS;
}
float3 GetPositionWS(EnvLightData value)
{
return value.positionWS;
}
int GetUnused8(EnvLightData value)
{
return value.unused8;
}
float3 GetForward(EnvLightData value)
{

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


TextureFormat probeCacheFormat = gLightLoopSettings.reflectionCacheCompressed ? TextureFormat.BC6H : TextureFormat.RGBAHalf;
m_ReflectionProbeCache = new ReflectionProbeCache(iblFilterGGX, gLightLoopSettings.reflectionProbeCacheSize, gLightLoopSettings.reflectionCubemapSize, probeCacheFormat, true);
m_ReflectionPlanarProbeCache = new ReflectionProbeCache(iblFilterGGX, gLightLoopSettings.reflectionProbeCacheSize, gLightLoopSettings.reflectionCubemapSize, probeCacheFormat, true);
s_GenAABBKernel = buildScreenAABBShader.FindKernel("ScreenBoundsAABB");

m_ReflectionProbeCache.Release();
m_ReflectionProbeCache = null;
}
if (m_ReflectionPlanarProbeCache != null)
{
m_ReflectionPlanarProbeCache.Release();
m_ReflectionPlanarProbeCache = null;
}
if (m_CookieTexArray != null)
{
m_CookieTexArray.Release();

m_CookieTexArray.NewFrame();
m_CubeCookieTexArray.NewFrame();
m_ReflectionProbeCache.NewFrame();
m_ReflectionPlanarProbeCache.NewFrame();
}
public bool NeedResize()

envLightData.boxSideFadePositive = probe.boxSideFadePositive;
envLightData.boxSideFadeNegative = probe.boxSideFadeNegative;
var influenceToWorld = probe.influenceToWorld;
envLightData.right = influenceToWorld.GetColumn(0).normalized;
envLightData.up = influenceToWorld.GetColumn(1).normalized;
envLightData.forward = influenceToWorld.GetColumn(2).normalized;
envLightData.positionWS = influenceToWorld.GetColumn(3);
envLightData.right = probe.influenceRight;
envLightData.up = probe.influenceUp;
envLightData.forward = probe.influenceForward;
envLightData.capturePositionWS = probe.capturePosition;
envLightData.offsetLS = probe.centerOffsetCaptureSpace;
envLightData.positionWS = probe.influencePosition;
envLightData.offsetLS = probe.captureOffsetLS;
m_lightList.envLights.Add(envLightData);

envProxyData.extents = probe.proxyExtents;
envProxyData.minProjectionDistance = probe.infiniteProjection ? 65504f : 0;
var proxyToWorld = probe.proxyToWorld;
envProxyData.right = proxyToWorld.GetColumn(0).normalized;
envProxyData.up = proxyToWorld.GetColumn(1).normalized;
envProxyData.forward = proxyToWorld.GetColumn(2).normalized;
envProxyData.positionWS = proxyToWorld.GetColumn(3);
envProxyData.right = probe.proxyRight;
envProxyData.up = probe.proxyUp;
envProxyData.forward = probe.proxyForward;
envProxyData.positionWS = probe.proxyPosition;
m_lightList.envProxies.Add(envProxyData);

{
var bound = new SFiniteLightBound();
var lightVolumeData = new LightVolumeData();
var mat = probe.influenceToWorld;
var vx = mat.GetColumn(0).normalized; // Scale shouldn't affect the probe or its bounds
var vy = mat.GetColumn(1).normalized;
var vz = mat.GetColumn(2).normalized;
var vw = mat.GetColumn(3);
vx = worldToView.MultiplyVector(vx);
vy = worldToView.MultiplyVector(vy);
vz = worldToView.MultiplyVector(vz);
var influencePositionVS = worldToView.MultiplyPoint(vw);
var influenceRightVS = worldToView.MultiplyVector(probe.influenceRight);
var influenceUpVS = worldToView.MultiplyVector(probe.influenceUp);
var influenceForwardVS = worldToView.MultiplyVector(probe.influenceForward);
var influencePositionVS = worldToView.MultiplyPoint(probe.influencePosition);
lightVolumeData.lightCategory = (uint)LightCategory.Env;
lightVolumeData.lightVolume = (uint)lightVolumeType;

{
lightVolumeData.lightPos = influencePositionVS;
lightVolumeData.radiusSq = influenceExtents.x * influenceExtents.x;
lightVolumeData.lightAxisX = vx;
lightVolumeData.lightAxisY = vy;
lightVolumeData.lightAxisZ = vz;
lightVolumeData.lightAxisX = influenceRightVS;
lightVolumeData.lightAxisY = influenceUpVS;
lightVolumeData.lightAxisZ = influenceForwardVS;
bound.boxAxisX = vx * influenceExtents.x;
bound.boxAxisY = vy * influenceExtents.x;
bound.boxAxisZ = vz * influenceExtents.x;
bound.boxAxisX = influenceRightVS * influenceExtents.x;
bound.boxAxisY = influenceUpVS * influenceExtents.x;
bound.boxAxisZ = influenceForwardVS * influenceExtents.x;
bound.scaleXY.Set(1.0f, 1.0f);
bound.radius = influenceExtents.x;
break;

bound.center = influencePositionVS;
bound.boxAxisX = influenceExtents.x * vx;
bound.boxAxisY = influenceExtents.y * vy;
bound.boxAxisZ = influenceExtents.z * vz;
bound.boxAxisX = influenceExtents.x * influenceRightVS;
bound.boxAxisY = influenceExtents.y * influenceUpVS;
bound.boxAxisZ = influenceExtents.z * influenceForwardVS;
bound.scaleXY.Set(1.0f, 1.0f);
bound.radius = influenceExtents.magnitude;

lightVolumeData.lightPos = influencePositionVS;
lightVolumeData.lightAxisX = vx;
lightVolumeData.lightAxisY = vy;
lightVolumeData.lightAxisZ = vz;
lightVolumeData.lightAxisX = influenceRightVS;
lightVolumeData.lightAxisY = influenceUpVS;
lightVolumeData.lightAxisZ = influenceForwardVS;
lightVolumeData.boxInnerDist = influenceExtents - k_BoxCullingExtentThreshold;
lightVolumeData.boxInvRange.Set(1.0f / k_BoxCullingExtentThreshold.x, 1.0f / k_BoxCullingExtentThreshold.y, 1.0f / k_BoxCullingExtentThreshold.z);
break;

// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.positionWS -= camPosWS;
envLightData.capturePositionWS -= camPosWS;
m_lightList.envLights[n - 1] = envLightData;
var envProjData = m_lightList.envProxies[n - 1];

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl


output.forward = float3(0.0, 0.0, 1.0);
output.up = float3(0.0, 1.0, 0.0);
output.right = float3(1.0, 0.0, 0.0);
output.positionWS = float3(0.0, 0.0, 0.0);
output.capturePositionWS = float3(0.0, 0.0, 0.0);
output.offsetLS = float3(0.0, 0.0, 0.0);
output.influenceExtents = float3(0.0, 0.0, 0.0);
output.blendDistancePositive = float3(0.0, 0.0, 0.0);

45
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs


[SerializeField]
InfluenceVolume m_InfluenceVolume;
[SerializeField]
Vector3 m_CaptureOffset;
Vector3 m_CenterOffset;
[SerializeField]
[Range(0, 1)]
float m_Dimmer = 1;

public BoundingSphere boundingSphere { get { return m_InfluenceVolume.GetBoundingSphereAt(transform); } }
public Texture texture { get; private set; }
public Bounds bounds { get { return m_InfluenceVolume.GetBoundsAt(transform); } }
public Matrix4x4 influenceToWorld { get { return transform.localToWorldMatrix; } }
public Vector3 captureOffset { get { return m_CaptureOffset; } }
public Vector3 centerOffset { get { return m_CenterOffset; } }
public Vector3 influenceRight { get { return transform.right; } }
public Vector3 influenceUp { get { return transform.up; } }
public Vector3 influenceForward { get { return transform.forward; } }
public Vector3 capturePosition { get { return transform.position; } }
public Vector3 influencePosition { get { return transform.TransformPoint(m_CenterOffset); } }
public Matrix4x4 proxyToWorld
public Vector3 proxyRight
{
get
{
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.transform.right
: influenceRight;
}
}
public Vector3 proxyUp
{
get
{
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.transform.up
: influenceUp;
}
}
public Vector3 proxyForward
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.transform.localToWorldMatrix
: transform.localToWorldMatrix;
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.transform.forward
: influenceForward;
}
}
public Vector3 proxyPosition
{
get
{
return m_ProxyVolumeReference != null
? m_ProxyVolumeReference.transform.position
: influencePosition;
}
}
public ShapeType proxyShape

50
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ProbeWrapper.cs


public abstract ReflectionProbeMode mode { get; }
public abstract Texture texture { get; }
public abstract Vector3 captureOffsetLS { get; }
// Position of the center of the probe in capture space
public abstract Vector3 centerOffsetCaptureSpace { get; }
public abstract Matrix4x4 influenceToWorld { get; }
public abstract Vector3 influenceRight { get; }
public abstract Vector3 influenceUp { get; }
public abstract Vector3 influenceForward { get; }
public abstract Vector3 capturePosition { get; }
public Vector3 influencePosition
{
get
{
return centerOffsetCaptureSpace.x * influenceRight
+ centerOffsetCaptureSpace.y * influenceUp
+ centerOffsetCaptureSpace.z * influenceForward
+ capturePosition;
}
}
public abstract EnvShapeType influenceShapeType { get; }
public abstract Vector3 influenceExtents { get; }
public abstract Vector3 blendNormalDistancePositive { get; }

public abstract Vector3 boxSideFadePositive { get; }
public abstract Vector3 boxSideFadeNegative { get; }
public abstract Matrix4x4 proxyToWorld { get; }
public abstract Vector3 proxyRight { get; }
public abstract Vector3 proxyUp { get; }
public abstract Vector3 proxyForward { get; }
public abstract Vector3 proxyPosition { get; }
}
class VisibleReflectionProbeWrapper : ProbeWrapper

return add;
}
public override Matrix4x4 influenceToWorld { get { return probe.localToWorld; } }
public override Vector3 influenceRight { get { return probe.localToWorld.GetColumn(0).normalized; } }
public override Vector3 influenceUp { get { return probe.localToWorld.GetColumn(1).normalized; } }
public override Vector3 influenceForward { get { return probe.localToWorld.GetColumn(2).normalized; } }
public override Vector3 capturePosition { get { return probe.localToWorld.GetColumn(3); } }
public override Vector3 captureOffsetLS { get { return probe.center; } } // center is misnamed, it is the offset (in local space) from center of the bounding box to the cubemap capture point
public override Vector3 centerOffsetCaptureSpace { get { return probe.center; } } // center is misnamed, it is the offset (in local space) from center of the bounding box to the cubemap capture point
public override EnvShapeType influenceShapeType { get { return ConvertShape(additional.influenceShape); } }
public override float dimmer { get { return additional.dimmer; } }
public override Vector3 influenceExtents

public override Vector3 boxSideFadePositive { get { return additional.boxSideFadePositive; } }
public override Vector3 boxSideFadeNegative { get { return additional.boxSideFadeNegative; } }
public override Matrix4x4 proxyToWorld { get { return influenceToWorld; } }
public override Vector3 proxyRight { get { return influenceRight; } }
public override Vector3 proxyUp{ get { return influenceUp; } }
public override Vector3 proxyForward{ get { return influenceForward; } }
public override Vector3 proxyPosition { get { return influencePosition; } }
}
class PlanarReflectionProbeWrapper : ProbeWrapper

this.probe = probe;
}
public override Matrix4x4 influenceToWorld { get { return probe.influenceToWorld; } }
public override Vector3 influenceRight { get { return probe.influenceRight; } }
public override Vector3 influenceUp { get { return probe.influenceUp; } }
public override Vector3 influenceForward { get { return probe.influenceForward; } }
public override Vector3 capturePosition { get { return probe.capturePosition; } }
public override Vector3 captureOffsetLS { get { return probe.captureOffset; } }
public override Vector3 centerOffsetCaptureSpace { get { return probe.centerOffset; } }
public override EnvShapeType influenceShapeType { get { return ConvertShape(probe.influenceVolume.shapeType); } }
public override float dimmer { get { return probe.dimmer; } }
public override Vector3 influenceExtents

public override Vector3 blendDistanceNegative { get { return probe.influenceVolume.boxInfluenceNegativeFade; } }
public override Vector3 boxSideFadePositive { get { return probe.influenceVolume.boxPositiveFaceFade; } }
public override Vector3 boxSideFadeNegative { get { return probe.influenceVolume.boxNegativeFaceFade; } }
public override Matrix4x4 proxyToWorld { get { return probe.proxyToWorld; } }
public override Vector3 proxyRight { get { return probe.proxyRight; } }
public override Vector3 proxyUp { get { return probe.proxyUp; } }
public override Vector3 proxyForward { get { return probe.proxyForward; } }
public override Vector3 proxyPosition { get { return probe.proxyPosition; } }
}
}

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/VolumeProjection.hlsl


#define ENVMAP_FEATURE_PERFACEFADE
#define ENVMAP_FEATURE_INFLUENCENORMAL
#include "LightDefinition.cs.hlsl"
float3x3 WorldToProxySpace(EnvProxyData proxyData)
{
return transpose(float3x3(proxyData.right, proxyData.up, proxyData.forward)); // worldToLocal assume no scaling

#if defined(ENVMAP_FEATURE_INFLUENCENORMAL)
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtents.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideInfluenceNormalVolume = all(belowPositiveInfluenceNormalVolume >= 1.0) && all(aboveNegativeInfluenceNormalVolume >= 1.0) ? 1.0 : 0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3x3 WorldToLightSpace(EnvLightData lightData)
{
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset)
// the center of the bounding box is thus in locals space: positionLS - offsetLS
// We use this formulation as it is the one of legacy unity that was using only AABB box.
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset)
// the center of the bounding box is thus in locals space: positionLS - offsetLS
// We use this formulation as it is the one of legacy unity that was using only AABB box.
positionLS = mul(positionLS, worldToLS).xyz - lightData.offsetLS;
positionLS = mul(positionLS, worldToLS).xyz;
return positionLS;
}

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl
#include "Lit.cs.hlsl"
#include "../../Lighting/VolumeProjection.hlsl"
#include "../../Lighting/VolumeProjection.hlsl"
//-----------------------------------------------------------------------------
// Texture and constant buffer declaration

if (projectionShapeType == ENVSHAPETYPE_SPHERE)
{
float projectionDistance = IntersectSphereProxy(proxyData, dirPS, positionPS);
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS
R = (positionWS + projectionDistance * R) - lightData.positionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionWS;
// Test again for clear coat
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION && HasMaterialFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))

coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
}
}
else if (projectionShapeType == ENVSHAPETYPE_BOX)

// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS
R = (positionWS + projectionDistance * R) - lightData.positionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionWS;
// TODO: add distance based roughness

dirPS = mul(coatR, worldToPS);
projectionDistance = IntersectBoxProxy(proxyData, dirPS, positionPS);
coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
}
}

正在加载...
取消
保存