浏览代码

[PlanarProbes] Packed env light data and env proxy data

/main
Frédéric Vauchelles 7 年前
当前提交
504ba0e9
共有 15 个文件被更改,包括 214 次插入216 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  2. 91
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  3. 160
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  4. 49
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  5. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.hlsl
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  7. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/materialflags.compute
  8. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl
  9. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Lighting.hlsl
  10. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/VolumeProjection.hlsl
  11. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  12. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute
  13. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyStencilBuffer.shader
  14. 23
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl
  15. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl.meta

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _AreaLightCount = Shader.PropertyToID("_AreaLightCount");
public static readonly int g_vLightListGlobal = Shader.PropertyToID("g_vLightListGlobal");
public static readonly int _EnvLightDatas = Shader.PropertyToID("_EnvLightDatas");
public static readonly int _EnvProxyDatas = Shader.PropertyToID("_EnvProxyDatas");
public static readonly int _EnvLightCount = Shader.PropertyToID("_EnvLightCount");
public static readonly int _EnvProxyCount = Shader.PropertyToID("_EnvProxyCount");
public static readonly int _ShadowDatas = Shader.PropertyToID("_ShadowDatas");

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


public struct EnvLightData
{
public Vector3 capturePositionWS;
public EnvShapeType envShapeType;
public Vector3 positionWS;
public int unused8;
public EnvShapeType influenceShapeType;
public Vector3 forward;
public Vector3 influencePositionWS;
public Vector3 up;
public float dimmer;
public Vector3 influenceForward;
public float proxyForwardX;
public Vector3 influenceUp;
public float proxyForwardY;
public Vector3 right;
// User can chose if they use This is use in case we want to force infinite projection distance (i.e no projection);
public float minProjectionDistance;
public Vector3 influenceRight;
public float proxyForwardZ;
public float unused0;
public float dimmer;
public float unused2;
public float proxyUpX;
public float unused3;
public float proxyUpY;
public float unused4;
public float proxyUpZ;
public float unused5;
public float proxyRightX;
public float unused6;
public float proxyRightY;
public float unused7;
public float proxyRightZ;
public float unused9;
};
// User can chose if they use This is use in case we want to force infinite projection distance (i.e no projection);
public float minProjectionDistance;
[GenerateHLSL]
public struct EnvProxyData
{
public Vector3 positionWS;
public EnvShapeType envShapeType;
public Vector3 proxyPositionWS;
public EnvShapeType proxyShapeType;
public Vector3 forward;
public float minProjectionDistance;
// Box: extents = box extents
// Sphere: extents.x = sphere radius
public Vector3 proxyExtents;
public int unused14;
public Vector3 up;
public int unused00;
public Vector3 proxyForward
{
get { return new Vector3(proxyForwardX, proxyForwardY, proxyForwardZ); }
set
{
proxyForwardX = value.x;
proxyForwardY = value.y;
proxyForwardZ = value.z;
}
}
public Vector3 right;
// User can chose if they use This is use in case we want to force infinite projection distance (i.e no projection);
public int unused01;
public Vector3 proxyUp
{
get { return new Vector3(proxyUpX, proxyUpY, proxyUpZ); }
set
{
proxyUpX = value.x;
proxyUpY = value.y;
proxyUpZ = value.z;
}
}
// Box: extents = box extents
// Sphere: extents.x = sphere radius
public Vector3 extents;
public int unused02;
}
public Vector3 proxyRight
{
get { return new Vector3(proxyRightX, proxyRightY, proxyRightZ); }
set
{
proxyRightX = value.x;
proxyRightY = value.y;
proxyRightZ = value.z;
}
}
};
[GenerateHLSL]
public enum EnvCacheType

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


struct EnvLightData
{
float3 capturePositionWS;
int envShapeType;
float3 positionWS;
int unused8;
float3 forward;
int influenceShapeType;
float3 influencePositionWS;
float3 up;
float3 influenceForward;
float proxyForwardX;
float3 influenceUp;
float proxyForwardY;
float3 influenceRight;
float proxyForwardZ;
float3 influenceExtents;
float3 right;
float minProjectionDistance;
float3 influenceExtents;
float unused0;
float unused2;
float proxyUpX;
float unused3;
float proxyUpY;
float unused4;
float proxyUpZ;
float unused5;
float proxyRightX;
float unused6;
float proxyRightY;
float unused7;
float proxyRightZ;
float unused9;
};
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.EnvProxyData
// PackingRules = Exact
struct EnvProxyData
{
float3 positionWS;
int envShapeType;
float3 forward;
float3 up;
int unused00;
float3 right;
int unused01;
float3 extents;
int unused02;
float3 proxyPositionWS;
int proxyShapeType;
float3 proxyExtents;
int unused14;
};
//

{
return value.capturePositionWS;
}
int GetEnvShapeType(EnvLightData value)
int GetInfluenceShapeType(EnvLightData value)
return value.envShapeType;
return value.influenceShapeType;
float3 GetPositionWS(EnvLightData value)
float3 GetInfluencePositionWS(EnvLightData value)
return value.positionWS;
return value.influencePositionWS;
int GetUnused8(EnvLightData value)
int GetEnvIndex(EnvLightData value)
return value.unused8;
return value.envIndex;
float3 GetForward(EnvLightData value)
float3 GetInfluenceForward(EnvLightData value)
return value.forward;
return value.influenceForward;
int GetEnvIndex(EnvLightData value)
float GetProxyForwardX(EnvLightData value)
return value.envIndex;
return value.proxyForwardX;
float3 GetUp(EnvLightData value)
float3 GetInfluenceUp(EnvLightData value)
return value.up;
return value.influenceUp;
float GetDimmer(EnvLightData value)
float GetProxyForwardY(EnvLightData value)
return value.dimmer;
return value.proxyForwardY;
float3 GetRight(EnvLightData value)
float3 GetInfluenceRight(EnvLightData value)
return value.right;
return value.influenceRight;
float GetMinProjectionDistance(EnvLightData value)
float GetProxyForwardZ(EnvLightData value)
return value.minProjectionDistance;
return value.proxyForwardZ;
float GetUnused0(EnvLightData value)
float GetDimmer(EnvLightData value)
return value.unused0;
return value.dimmer;
float GetUnused2(EnvLightData value)
float GetProxyUpX(EnvLightData value)
return value.unused2;
return value.proxyUpX;
float GetUnused3(EnvLightData value)
float GetProxyUpY(EnvLightData value)
return value.unused3;
return value.proxyUpY;
float GetUnused4(EnvLightData value)
float GetProxyUpZ(EnvLightData value)
return value.unused4;
return value.proxyUpZ;
float GetUnused5(EnvLightData value)
float GetProxyRightX(EnvLightData value)
return value.unused5;
return value.proxyRightX;
float GetUnused6(EnvLightData value)
float GetProxyRightY(EnvLightData value)
return value.unused6;
return value.proxyRightY;
float GetUnused7(EnvLightData value)
float GetProxyRightZ(EnvLightData value)
return value.unused7;
return value.proxyRightZ;
float GetUnused9(EnvLightData value)
{
return value.unused9;
}
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvProxyData
//
float3 GetPositionWS(EnvProxyData value)
{
return value.positionWS;
}
int GetEnvShapeType(EnvProxyData value)
{
return value.envShapeType;
}
float3 GetForward(EnvProxyData value)
{
return value.forward;
}
float GetMinProjectionDistance(EnvProxyData value)
float GetMinProjectionDistance(EnvLightData value)
float3 GetUp(EnvProxyData value)
{
return value.up;
}
int GetUnused00(EnvProxyData value)
{
return value.unused00;
}
float3 GetRight(EnvProxyData value)
float3 GetProxyPositionWS(EnvLightData value)
return value.right;
return value.proxyPositionWS;
int GetUnused01(EnvProxyData value)
int GetProxyShapeType(EnvLightData value)
return value.unused01;
return value.proxyShapeType;
float3 GetExtents(EnvProxyData value)
float3 GetProxyExtents(EnvLightData value)
return value.extents;
return value.proxyExtents;
int GetUnused02(EnvProxyData value)
int GetUnused14(EnvLightData value)
return value.unused02;
return value.unused14;
}

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


static ComputeBuffer s_DirectionalLightDatas = null;
static ComputeBuffer s_LightDatas = null;
static ComputeBuffer s_EnvLightDatas = null;
static ComputeBuffer s_EnvProxyDatas = null;
static ComputeBuffer s_shadowDatas = null;
static Texture2DArray s_DefaultTexture2DArray;

public List<DirectionalLightData> directionalLights;
public List<LightData> lights;
public List<EnvLightData> envLights;
public List<EnvProxyData> envProxies;
public List<ShadowData> shadows;
public List<SFiniteLightBound> bounds;

directionalLights.Clear();
lights.Clear();
envLights.Clear();
envProxies.Clear();
shadows.Clear();
bounds.Clear();

directionalLights = new List<DirectionalLightData>();
lights = new List<LightData>();
envLights = new List<EnvLightData>();
envProxies = new List<EnvProxyData>();
shadows = new List<ShadowData>();
bounds = new List<SFiniteLightBound>();

s_DirectionalLightDatas = new ComputeBuffer(k_MaxDirectionalLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));
s_LightDatas = new ComputeBuffer(k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_EnvLightDatas = new ComputeBuffer(k_MaxEnvLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_EnvProxyDatas = new ComputeBuffer(k_MaxEnvLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvProxyData)));
s_shadowDatas = new ComputeBuffer(k_MaxCascadeCount + k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ShadowData)));
GlobalLightLoopSettings gLightLoopSettings = hdAsset.GetRenderPipelineSettings().lightLoopSettings;

CoreUtils.SafeRelease(s_DirectionalLightDatas);
CoreUtils.SafeRelease(s_LightDatas);
CoreUtils.SafeRelease(s_EnvLightDatas);
CoreUtils.SafeRelease(s_EnvProxyDatas);
CoreUtils.SafeRelease(s_shadowDatas);
if (m_ReflectionProbeCache != null)

var envLightData = new EnvLightData();
envLightData.envShapeType = probe.influenceShapeType;
envLightData.influenceShapeType = probe.influenceShapeType;
envLightData.dimmer = probe.dimmer;
envLightData.influenceExtents = probe.influenceExtents;
envLightData.blendNormalDistancePositive = probe.blendNormalDistancePositive;

envLightData.boxSideFadeNegative = probe.boxSideFadeNegative;
envLightData.sampleDirectionDiscardWS = sampleDirectionDiscardWS;
envLightData.right = influenceToWorld.GetColumn(0).normalized;
envLightData.up = influenceToWorld.GetColumn(1).normalized;
envLightData.forward = influenceToWorld.GetColumn(2).normalized;
envLightData.influenceRight = influenceToWorld.GetColumn(0).normalized;
envLightData.influenceUp = influenceToWorld.GetColumn(1).normalized;
envLightData.influenceForward = influenceToWorld.GetColumn(2).normalized;
envLightData.positionWS = influenceToWorld.GetColumn(3);
envLightData.influencePositionWS = influenceToWorld.GetColumn(3);
m_lightList.envLights.Add(envLightData);
// Build projection data
// Proxy data
var envProxyData = new EnvProxyData();
envProxyData.envShapeType = probe.proxyShapeType;
envProxyData.extents = probe.proxyExtents;
envProxyData.minProjectionDistance = probe.infiniteProjection ? 65504f : 0;
envLightData.proxyExtents = probe.proxyExtents;
envLightData.minProjectionDistance = probe.infiniteProjection ? 65504f : 0;
envLightData.proxyRight = proxyToWorld.GetColumn(0).normalized;
envLightData.proxyUp = proxyToWorld.GetColumn(1).normalized;
envLightData.proxyForward = proxyToWorld.GetColumn(2).normalized;
envLightData.proxyPositionWS = proxyToWorld.GetColumn(3);
envLightData.proxyShapeType = probe.proxyShapeType;
envProxyData.right = proxyToWorld.GetColumn(0).normalized;
envProxyData.up = proxyToWorld.GetColumn(1).normalized;
envProxyData.forward = proxyToWorld.GetColumn(2).normalized;
envProxyData.positionWS = proxyToWorld.GetColumn(3);
m_lightList.envProxies.Add(envProxyData);
m_lightList.envLights.Add(envLightData);
return true;
}

int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.capturePositionWS -= camPosWS;
envLightData.positionWS -= camPosWS;
envLightData.influencePositionWS -= camPosWS;
envLightData.proxyPositionWS -= camPosWS;
var envProjData = m_lightList.envProxies[n - 1];
envProjData.positionWS -= camPosWS;
m_lightList.envProxies[n - 1] = envProjData;
}
}
}

Debug.Assert(m_lightList.bounds.Count == m_lightCount);
Debug.Assert(m_lightList.lightVolumes.Count == m_lightCount);
Debug.Assert(m_lightList.envProxies.Count == m_lightList.envLights.Count);
UpdateDataBuffers();

s_DirectionalLightDatas.SetData(m_lightList.directionalLights);
s_LightDatas.SetData(m_lightList.lights);
s_EnvLightDatas.SetData(m_lightList.envLights);
s_EnvProxyDatas.SetData(m_lightList.envProxies);
s_shadowDatas.SetData(m_lightList.shadows);
// These two buffers have been set in Rebuild()

cmd.SetGlobalInt(HDShaderIDs._PunctualLightCount, m_punctualLightCount);
cmd.SetGlobalInt(HDShaderIDs._AreaLightCount, m_areaLightCount);
cmd.SetGlobalBuffer(HDShaderIDs._EnvLightDatas, s_EnvLightDatas);
cmd.SetGlobalBuffer(HDShaderIDs._EnvProxyDatas, s_EnvProxyDatas);
cmd.SetGlobalInt(HDShaderIDs._EnvProxyCount, m_lightList.envProxies.Count);
cmd.SetGlobalBuffer(HDShaderIDs._ShadowDatas, s_shadowDatas);
cmd.SetGlobalInt(HDShaderIDs._NumTileFtplX, GetNumTileFtplX(camera));

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


#else
uint envLightIndex = i;
#endif
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, _EnvLightDatas[envLightIndex], _EnvProxyDatas[envLightIndex], bsdfData,
_EnvLightDatas[envLightIndex].envShapeType, _EnvProxyDatas[envLightIndex].envShapeType,
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, _EnvLightDatas[envLightIndex], bsdfData,
_EnvLightDatas[envLightIndex].influenceShapeType, _EnvLightDatas[envLightIndex].proxyShapeType,
GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION, reflectionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}

#else
uint envLightIndex = i;
#endif
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, _EnvLightDatas[envLightIndex], _EnvProxyDatas[envLightIndex], bsdfData,
_EnvLightDatas[envLightIndex].envShapeType, _EnvProxyDatas[envLightIndex].envShapeType,
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, _EnvLightDatas[envLightIndex], bsdfData,
_EnvLightDatas[envLightIndex].influenceShapeType, _EnvLightDatas[envLightIndex].proxyShapeType,
GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION, refractionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}

// The sky data are generated on the fly so the compiler can optimize the code
EnvLightData envLightSky = InitSkyEnvLightData(0);
EnvProxyData envProxySky = InitSkyEnvProxyData(0);
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, envProxySky, bsdfData,
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, bsdfData,
ENVSHAPETYPE_SKY, ENVSHAPETYPE_SKY,
GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION, reflectionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);

// The sky data are generated on the fly so the compiler can optimize the code
EnvLightData envLightSky = InitSkyEnvLightData(0);
EnvProxyData envProxySky = InitSkyEnvProxyData(0);
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, envProxySky, bsdfData,
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, bsdfData,
ENVSHAPETYPE_SKY, ENVSHAPETYPE_SKY,
GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION, refractionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


StructuredBuffer<DirectionalLightData> _DirectionalLightDatas;
StructuredBuffer<LightData> _LightDatas;
StructuredBuffer<EnvLightData> _EnvLightDatas;
StructuredBuffer<EnvProxyData> _EnvProxyDatas;
StructuredBuffer<ShadowData> _ShadowDatas;
// Used by directional and spot lights

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/materialflags.compute


#pragma kernel MaterialFlagsGen_Write MATERIALFLAGSGEN=MaterialFlagsGen_Write
#pragma kernel MaterialFlagsGen_Write MATERIALFLAGSGEN=MaterialFlagsGen_Write
#pragma kernel MaterialFlagsGen_Or MATERIALFLAGSGEN=MaterialFlagsGen_Or USE_OR
// #pragma enable_d3d11_debug_symbols

#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../Material/Material.hlsl" // This includes Material.hlsl
#include "../../Lighting/LightDefinition.cs.hlsl"
#include "../../Lighting/LightDefinition.custom.hlsl"
#define USE_MATERIAL_FEATURE_FLAGS
#define NR_THREADS 64

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


#define UNITY_LIGHT_UTILITIES_INCLUDED
#include "LightDefinition.cs.hlsl"
#include "LightDefinition.custom.hlsl"
// The EnvLightData of the sky light contains a bunch of compile-time constants.
// This function sets them directly to allow the compiler to propagate them and optimize the code.

output.envShapeType = ENVSHAPETYPE_SKY;
output.influenceShapeType = ENVSHAPETYPE_SKY;
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.influenceForward = float3(0.0, 0.0, 1.0);
output.influenceUp = float3(0.0, 1.0, 0.0);
output.influenceRight = float3(1.0, 0.0, 0.0);
output.influencePositionWS = float3(0.0, 0.0, 0.0);
output.blendDistancePositive = float3(0.0, 0.0, 0.0);
output.blendDistanceNegative = float3(0.0, 0.0, 0.0);
output.blendNormalDistancePositive = float3(0.0, 0.0, 0.0);

output.dimmer = 1.0;
output.sampleDirectionDiscardWS = float3(0.0, 0.0, 0.0);
return output;
}
EnvProxyData InitSkyEnvProxyData(int envIndex)
{
EnvProxyData output;
output.positionWS = float3(0.0, 0.0, 0.0);
output.envShapeType = ENVSHAPETYPE_SKY;
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);
// proxy
output.proxyForwardX = 0; output.proxyForwardY = 0; output.proxyForwardZ = 1;
output.proxyUpX = 0; output.proxyUpY = 1; output.proxyUpZ = 0;
output.proxyRightX = 1; output.proxyRightY = 0; output.proxyRightZ = 0;
output.proxyPositionWS = float3(0.0, 0.0, 0.0);
output.extents = float3(0.0, 0.0, 0.0);
output.proxyExtents = float3(0.0, 0.0, 0.0);
return output;
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Lighting.hlsl


#define HAS_LIGHTLOOP // Allow to not define LightLoop related function in Material.hlsl
#include "../Lighting/LightDefinition.cs.hlsl"
#include "../Lighting/LightDefinition.custom.hlsl"
#include "../Lighting/LightUtilities.hlsl"
#include "LightLoop/Shadow.hlsl"

31
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/VolumeProjection.hlsl


#define ENVMAP_FEATURE_INFLUENCENORMAL
#include "../LightDefinition.cs.hlsl"
#include "../LightDefinition.custom.hlsl"
float3x3 WorldToProxySpace(EnvProxyData proxyData)
float3x3 WorldToProxySpace(EnvLightData lightData)
return transpose(float3x3(proxyData.right, proxyData.up, proxyData.forward)); // worldToLocal assume no scaling
return transpose(
float3x3(
EnvLightData_GetProxyRight(lightData),
EnvLightData_GetProxyUp(lightData),
EnvLightData_GetProxyForward(lightData)
)
); // worldToLocal assume no scaling
float3 WorldToProxyPosition(EnvProxyData proxyData, float3x3 worldToPS, float3 positionWS)
float3 WorldToProxyPosition(EnvLightData lightData, float3x3 worldToPS, float3 positionWS)
float3 positionPS = positionWS - proxyData.positionWS;
float3 positionPS = positionWS - lightData.proxyPositionWS;
float IntersectSphereProxy(EnvProxyData proxyData, float3 dirPS, float3 positionPS)
float IntersectSphereProxy(EnvLightData lightData, float3 dirPS, float3 positionPS)
float sphereOuterDistance = proxyData.extents.x;
float sphereOuterDistance = lightData.proxyExtents.x;
projectionDistance = max(projectionDistance, proxyData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
float IntersectBoxProxy(EnvProxyData proxyData, float3 dirPS, float3 positionPS)
float IntersectBoxProxy(EnvLightData lightData, float3 dirPS, float3 positionPS)
float3 boxOuterDistance = proxyData.extents;
float3 boxOuterDistance = lightData.proxyExtents;
projectionDistance = max(projectionDistance, proxyData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
return projectionDistance;
}

float3x3 WorldToInfluenceSpace(EnvLightData lightData)
{
return transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
return transpose(float3x3(lightData.influenceRight, lightData.influenceUp, lightData.influenceForward)); // worldToLocal assume no scaling
float3 positionIS = positionWS - lightData.positionWS;
float3 positionIS = positionWS - lightData.influencePositionWS;
positionIS = mul(positionIS, worldToIS).xyz;
return positionIS;
}

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


// _preIntegratedFGD and _CubemapLD are unique for each BRDF
IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, EnvLightData lightData, EnvProxyData proxyData, BSDFData bsdfData,
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
int influenceShapeType, int projectionShapeType, int GPUImageBasedLightingType,
inout float hierarchyWeight)
{

float3 positionIS = WorldToInfluencePosition(lightData, worldToIS, positionWS);
float3 dirIS = mul(R, worldToIS);
float3x3 worldToPS = WorldToProxySpace(proxyData);
float3 positionPS = WorldToProxyPosition(proxyData, worldToPS, positionWS);
float3x3 worldToPS = WorldToProxySpace(lightData);
float3 positionPS = WorldToProxyPosition(lightData, worldToPS, positionWS);
float3 dirPS = mul(R, worldToPS);
float projectionDistance = 0;

{
projectionDistance = IntersectSphereProxy(proxyData, dirPS, positionPS);
projectionDistance = IntersectSphereProxy(lightData, 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.capturePositionWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionWS;

dirPS = mul(coatR, worldToPS);
projectionDistance = IntersectSphereProxy(proxyData, dirPS, positionPS);
projectionDistance = IntersectSphereProxy(lightData, dirPS, positionPS);
projectionDistance = IntersectBoxProxy(proxyData, dirPS, positionPS);
projectionDistance = IntersectBoxProxy(lightData, dirPS, positionPS);
// No need to normalize for fetching cubemap
// 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;

if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION && HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
dirPS = mul(coatR, worldToPS);
projectionDistance = IntersectBoxProxy(proxyData, dirPS, positionPS);
projectionDistance = IntersectBoxProxy(lightData, dirPS, positionPS);
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute


#include "CoreRP/ShaderLibrary/SpaceFillingCurves.hlsl"
#include "../../ShaderVariables.hlsl"
#include "../../Lighting/LightDefinition.cs.hlsl"
#include "../../Lighting/LightDefinition.custom.hlsl"
#include "SubsurfaceScattering.hlsl"
//--------------------------------------------------------------------------------------------------

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyStencilBuffer.shader


#include "CoreRP/ShaderLibrary/Packing.hlsl"
#include "../ShaderVariables.hlsl"
#include "../Lighting/LightDefinition.cs.hlsl"
#include "../Lighting/LightDefinition.custom.hlsl"
int _StencilRef;
RW_TEXTURE2D(float, _HTile); // DXGI_FORMAT_R8_UINT is not supported by Unity

23
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl


#ifndef LIGHTDEFINITION_CUSTOM_HLSL
#define LIGHTDEFINITION_CUSTOM_HLSL
//-----------------------------------------------------------------------------
// Packing accessors
//-----------------------------------------------------------------------------
float3 EnvLightData_GetProxyForward(EnvLightData lightData)
{
return float3(lightData.proxyForwardX, lightData.proxyForwardY, lightData.proxyForwardZ);
}
float3 EnvLightData_GetProxyUp(EnvLightData lightData)
{
return float3(lightData.proxyUpX, lightData.proxyUpY, lightData.proxyUpZ);
}
float3 EnvLightData_GetProxyRight(EnvLightData lightData)
{
return float3(lightData.proxyRightX, lightData.proxyRightY, lightData.proxyRightZ);
}
#endif

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl.meta


fileFormatVersion: 2
guid: 3ad8aff9e108a5e40b19c2c89fe7a448
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存