浏览代码

Merge pull request #685 from EvgeniiG/master

Store light.range in lightData.size.x for box lights
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
ab1a6cff
共有 22 个文件被更改,包括 234 次插入182 次删除
  1. 106
      SampleScenes/HDTest/HDRenderLoopTest.unity
  2. 4
      ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl
  3. 4
      ScriptableRenderPipeline/Core/ShaderLibrary/API/Metal.hlsl
  4. 5
      ScriptableRenderPipeline/Core/ShaderLibrary/API/PSSL.hlsl
  5. 5
      ScriptableRenderPipeline/Core/ShaderLibrary/API/Vulkan.hlsl
  6. 5
      ScriptableRenderPipeline/Core/ShaderLibrary/API/XBoxOne.hlsl
  7. 57
      ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl
  8. 25
      ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl
  9. 23
      ScriptableRenderPipeline/Core/ShaderLibrary/Random.hlsl
  10. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/Sampling/Hammersley.hlsl
  11. 10
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDLightEditor.Styles.cs
  12. 20
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDLightEditor.cs
  13. 8
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalLightData.cs
  14. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDLightEditorUtilities.cs
  15. 10
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  16. 52
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  17. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  18. 2
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  19. 4
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1210_Lit_BentNormal.unity
  20. 2
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2001_Dynamic_Directional.unity
  21. 8
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2002_Dynamic_Mix.unity
  22. 54
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2003_Light_Parameters.unity

106
SampleScenes/HDTest/HDRenderLoopTest.unity


--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3

m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 0}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_UseShadowmask: 1
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 2
spotLightShape: 0
shapeLength: 16
shapeWidth: 0
shapeWidth: 16
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

m_IsActive: 1
--- !u!114 &827169274
MonoBehaviour:
m_ObjectHideFlags: 0
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 827169273}

affectSpecular: 1
lightTypeExtent: 1
spotLightShape: 0
shapeLength: 16
shapeWidth: 2
shapeWidth: 16
shapeHeight: 2
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

m_GameObject: {fileID: 827169273}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Type: 2
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 12

serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_AreaSize: {x: 16, y: 2}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0

m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!114 &827169277
MonoBehaviour:
m_ObjectHideFlags: 0
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 827169273}

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 1
shapeLength: 4
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 1
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

m_IsActive: 1
--- !u!114 &1640077384
MonoBehaviour:
m_ObjectHideFlags: 0
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1640077383}

affectSpecular: 1
lightTypeExtent: 1
spotLightShape: 0
shapeLength: 4
shapeWidth: 2
shapeWidth: 4
shapeHeight: 2
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_AreaSize: {x: 4, y: 2}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0

m_LocalEulerAnglesHint: {x: 0, y: 180, z: 90.00001}
--- !u!114 &1640077387
MonoBehaviour:
m_ObjectHideFlags: 0
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1640077383}

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 4
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

4
ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl


#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_REVERSED_Z 1
#define UNITY_NEAR_CLIP_VALUE (1.0)
// This value will not go through any matrix projection convertion
// This value will not go through any matrix projection conversion
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_SEMANTIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

4
ScriptableRenderPipeline/Core/ShaderLibrary/API/Metal.hlsl


#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_REVERSED_Z 1
#define UNITY_NEAR_CLIP_VALUE (1.0)
// This value will not go through any matrix projection convertion
// This value will not go through any matrix projection conversion
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_SEMANTIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

5
ScriptableRenderPipeline/Core/ShaderLibrary/API/PSSL.hlsl


// This file assume SHADER_API_D3D11 is defined
#define INTRINSIC_BITFIELD_EXTRACT
#define BitFieldExtract __v_bfe_u32
#define INTRINSIC_BITFIELD_EXTRACT_SIGN_EXTEND
#define BitFieldExtractSignExtend __v_bfe_i32
#define INTRINSIC_WAVEREADFIRSTLANE
#define WaveReadFirstLane ReadFirstLane
#define INTRINSIC_MAD24

#define UNITY_NEAR_CLIP_VALUE (1.0)
// This value will not go through any matrix projection convertion
#define UNITY_RAW_FAR_CLIP_VALUE (0.0)
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_SEMANTIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

5
ScriptableRenderPipeline/Core/ShaderLibrary/API/Vulkan.hlsl


// This file assume SHADER_API_VULKAN is defined
// TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed.
// This value will not go through any matrix projection convertion
// This value will not go through any matrix projection conversion
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_SEMANTIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

5
ScriptableRenderPipeline/Core/ShaderLibrary/API/XBoxOne.hlsl


// This file assume SHADER_API_D3D11 is defined
// TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed.
// This value will not go through any matrix projection convertion
// This value will not go through any matrix projection conversion
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_SEMANTIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

57
ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl


// Unsigned integer bit field extraction.
// Note that the intrinsic itself generates a vector instruction.
// Wrap this function with WaveReadFirstLane() to get scalar output.
uint BitFieldExtract(uint data, uint numBits, uint offset)
uint BitFieldExtract(uint data, uint offset, uint numBits)
uint mask = UINT_MAX >> (32u - numBits);
uint mask = (1u << numBits) - 1u;
#ifndef INTRINSIC_BITFIELD_EXTRACT_SIGN_EXTEND
// Integer bit field extraction with sign extension.
// Note that the intrinsic itself generates a vector instruction.
// Wrap this function with WaveReadFirstLane() to get scalar output.
int BitFieldExtractSignExtend(int data, uint offset, uint numBits)
{
int shifted = data >> offset; // Sign-extending (arithmetic) shift
int signBit = shifted & (1u << (numBits - 1u));
uint mask = (1u << numBits) - 1u;
return -signBit | (shifted & mask); // Use 2-complement for negation to replicate the sign bit
}
#endif // INTRINSIC_BITFIELD_EXTRACT_SIGN_EXTEND
return BitFieldExtract(data, 1u, offset) != 0;
return BitFieldExtract(data, offset, 1u) != 0;
}
void SetBit(inout uint data, uint offset)

return (x < 1.0) ? poly : HALF_PI - poly;
}
#if (SHADER_TARGET >= 45)
uint FastLog2(uint x)
{
return firstbithigh(x) - 1u;
}
#endif
// 4 VGPR, 16 FR (12 FR, 1 QR), 2 scalar
// input [-infinity, infinity] and output [-PI/2, PI/2]
float FastATan(float x)

}
// Same as smoothstep except it assume 0, 1 interval for x
float Smoothstep01(float x)
{
return x * x * (3.0 - (2.0 * x));
}
static const float3x3 k_identity3x3 = {1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0};
static const float4x4 k_identity4x4 = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0};
// Using pow often result to a warning like this
// "pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them"
// PositivePow remove this warning when you know the value is positive and avoid inf/NAN.

float3 Orthonormalize(float3 tangent, float3 normal)
{
return normalize(tangent - dot(tangent, normal) * normal);
}
// Same as smoothstep except it assume 0, 1 interval for x
float Smoothstep01(float x)
{
return x * x * (3.0 - (2.0 * x));
}
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Space transformations
// ----------------------------------------------------------------------------
static const float3x3 k_identity3x3 = {1, 0, 0,
0, 1, 0,
0, 0, 1};
static const float4x4 k_identity4x4 = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
// Use case examples:
// (position = positionCS) => (clipSpaceTransform = use default)

25
ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl


// Packs an integer stored using at most 'numBits' into a [0..1] float.
float PackInt(uint i, uint numBits)
{
uint maxInt = UINT_MAX >> (32u - numBits);
uint maxInt = (1u << numBits) - 1u;
return saturate(i * rcp(maxInt));
}

uint maxInt = UINT_MAX >> (32u - numBits);
uint maxInt = (1u << numBits) - 1u;
return (uint)(f * maxInt + 0.5); // Round instead of truncating
}

// Packs 8 lowermost bits of a [0..65535] integer into a [0..1] float.
float PackShortLo(uint i)
{
uint lo = BitFieldExtract(i, 8u, 0u);
uint lo = BitFieldExtract(i, 0u, 8u);
return PackInt(lo, 8);
}

//-----------------------------------------------------------------------------
// src must be between 0.0 and 1.0
uint PackFloatToUInt(float src, uint numBits, uint offset)
uint PackFloatToUInt(float src, uint offset, uint numBits)
float UnpackUIntToFloat(uint src, uint numBits, uint offset)
float UnpackUIntToFloat(uint src, uint offset, uint numBits)
uint maxInt = UINT_MAX >> (32u - numBits);
return float(BitFieldExtract(src, numBits, offset)) * rcp(maxInt);
uint maxInt = (1u << numBits) - 1u;
return float(BitFieldExtract(src, offset, numBits)) * rcp(maxInt);
return (PackFloatToUInt(rgba.x, 10, 0) | PackFloatToUInt(rgba.y, 10, 10) | PackFloatToUInt(rgba.z, 10, 20) | PackFloatToUInt(rgba.w, 2, 30));
return (PackFloatToUInt(rgba.x, 0, 10) |
PackFloatToUInt(rgba.y, 10, 10) |
PackFloatToUInt(rgba.z, 20, 10) |
PackFloatToUInt(rgba.w, 30, 2));
ouput.x = UnpackUIntToFloat(rgba, 10, 0);
ouput.x = UnpackUIntToFloat(rgba, 0, 10);
ouput.z = UnpackUIntToFloat(rgba, 10, 20);
ouput.w = UnpackUIntToFloat(rgba, 2, 30);
ouput.z = UnpackUIntToFloat(rgba, 20, 10);
ouput.w = UnpackUIntToFloat(rgba, 30, 2);
return ouput;
}

23
ScriptableRenderPipeline/Core/ShaderLibrary/Random.hlsl


return JenkinsHash(v.x ^ JenkinsHash(v.y) ^ JenkinsHash(v.z) ^ JenkinsHash(v.w));
}
// Construct a float with half-open range [0:1] using low 23 bits.
// Construct a float with half-open range [0, 1) using low 23 bits.
float ConstructFloat(uint m) {
const uint ieeeMantissa = 0x007FFFFFu; // Binary FP32 mantissa bitmask
const uint ieeeOne = 0x3F800000u; // 1.0 in FP32 IEEE
float ConstructFloat(int m) {
const int ieeeMantissa = 0x007FFFFF; // Binary FP32 mantissa bitmask
const int ieeeOne = 0x3F800000; // 1.0 in FP32 IEEE
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
float f = asfloat(m); // Range [1, 2)
return f - 1; // Range [0, 1)
}
float f = asfloat(m); // Range [1:2]
return f - 1; // Range [0:1]
float ConstructFloat(uint m)
{
return ConstructFloat(asint(m));
// Pseudo-random value in half-open range [0:1]. The distribution is reasonably uniform.
// Pseudo-random value in half-open range [0, 1). The distribution is reasonably uniform.
// Ref: https://stackoverflow.com/a/17479300
float GenerateHashedRandomFloat(uint x)
{

2
ScriptableRenderPipeline/Core/ShaderLibrary/Sampling/Hammersley.hlsl


// Ref: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
uint ReverseBits32(uint bits)
{
#if 1 // Shader model 5
#if (SHADER_TARGET >= 45)
return reversebits(bits);
#else
bits = (bits << 16) | (bits >> 16);

10
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent fadeDistance = new GUIContent("Fade Distance", "The distance at which the light will smoothly fade before being culled to minimize popping.");
public readonly GUIContent spotInnerPercent = new GUIContent("Inner Percent", "Controls size of the angular attenuation in percent of the base angle of the Spot light's cone.");
public readonly GUIContent spotLightShape = new GUIContent("Shape", "The shape use for the spotlight. Has an impact on the cookie transformation and light angular attenuation.");
public readonly GUIContent shapeLengthLine = new GUIContent("Length", "Length of the line light");
public readonly GUIContent shapeLengthRect = new GUIContent("Size X", "SizeX of the rectangle light");
public readonly GUIContent shapeWidthRect = new GUIContent("Size Y", "SizeY of the rectangle light");
public readonly GUIContent shapeWidthLine = new GUIContent("Length", "Length of the line light");
public readonly GUIContent shapeWidthRect = new GUIContent("Size X", "SizeX of the rectangle light");
public readonly GUIContent shapeHeightRect = new GUIContent("Size Y", "SizeY of the rectangle light");
public readonly GUIContent shapeLengthBox = new GUIContent("Size X", "");
public readonly GUIContent shapeWidthBox = new GUIContent("Size Y", "");
public readonly GUIContent shapeWidthBox = new GUIContent("Size X", "");
public readonly GUIContent shapeHeightBox = new GUIContent("Size Y", "");
public readonly GUIContent applyRangeAttenuation = new GUIContent("Apply Range Attenuation", "Allows disabling range attenuation. This is useful indoor (like a room) to avoid having to setup a large range for a light to get correct inverse square attenuation that may leak out of the indoor");
public readonly GUIContent shape = new GUIContent("Type", "Specifies the current type of light. Possible types are Directional, Spot, Point, Rectangle and Line lights.");

20
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDLightEditor.cs


public SerializedProperty affectSpecular;
public SerializedProperty lightTypeExtent;
public SerializedProperty spotLightShape;
public SerializedProperty shapeLength;
public SerializedProperty shapeHeight;
public SerializedProperty aspectRatio;
public SerializedProperty shapeRadius;
public SerializedProperty maxSmoothness;

affectSpecular = o.Find(x => x.affectSpecular),
lightTypeExtent = o.Find(x => x.lightTypeExtent),
spotLightShape = o.Find(x => x.spotLightShape),
shapeLength = o.Find(x => x.shapeLength),
shapeHeight = o.Find(x => x.shapeHeight),
aspectRatio = o.Find(x => x.aspectRatio),
shapeRadius = o.Find(x => x.shapeRadius),
maxSmoothness = o.Find(x => x.maxSmoothness),

}
else if (spotLightShape == SpotLightShape.Box)
{
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeLength, s_Styles.shapeLengthBox);
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeHeight, s_Styles.shapeHeightBox);
}
EditorGUILayout.PropertyField(m_AdditionalLightData.maxSmoothness, s_Styles.maxSmoothness);
break;

//m_BaseData.type.enumValueIndex = (int)LightType.Area;
settings.lightType.enumValueIndex = (int)LightType.Point;
m_AdditionalLightData.lightTypeExtent.enumValueIndex = (int)LightTypeExtent.Rectangle;
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeLength, s_Styles.shapeLengthRect);
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
settings.areaSizeY.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeHeight, s_Styles.shapeHeightRect);
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
settings.areaSizeY.floatValue = m_AdditionalLightData.shapeHeight.floatValue;
settings.shadowsType.enumValueIndex = (int)LightShadows.None;
break;

settings.lightType.enumValueIndex = (int)LightType.Point;
m_AdditionalLightData.lightTypeExtent.enumValueIndex = (int)LightTypeExtent.Line;
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeLength, s_Styles.shapeLengthLine);
EditorGUILayout.PropertyField(m_AdditionalLightData.shapeWidth, s_Styles.shapeWidthLine);
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
settings.areaSizeY.floatValue = 0.01f;
settings.shadowsType.enumValueIndex = (int)LightShadows.None;
break;

if (settings.cookie != null && m_LightShape == LightShape.Directional)
{
EditorGUI.indentLevel++;
EditorGUILayout.Slider(m_AdditionalLightData.shapeLength, 0.01f, 10f, s_Styles.cookieSizeX);
EditorGUILayout.Slider(m_AdditionalLightData.shapeWidth, 0.01f, 10f, s_Styles.cookieSizeY);
EditorGUILayout.Slider(m_AdditionalLightData.shapeWidth, 0.01f, 10f, s_Styles.cookieSizeX);
EditorGUILayout.Slider(m_AdditionalLightData.shapeHeight, 0.01f, 10f, s_Styles.cookieSizeY);
EditorGUI.indentLevel--;
}
}

8
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalLightData.cs


// Only for Rectangle/Line/box projector lights
[Range(0.0f, 20.0f)]
[FormerlySerializedAs("lightLength")]
public float shapeLength = 0.5f;
[FormerlySerializedAs("lightWidth")]
public float shapeWidth = 0.5f;
[FormerlySerializedAs("lightWidth")]
public float shapeWidth = 0.5f;
[FormerlySerializedAs("lightHeight")]
public float shapeHeight = 0.5f;
// Only for pyramid projector
public float aspectRatio = 1.0f;

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDLightEditorUtilities.cs


{
var additionalLightData = spherelight.GetComponent<HDAdditionalLightData>();
if (additionalLightData == null) return;
Gizmos.DrawSphere(spherelight.transform.position, additionalLightData.shapeLength);
Gizmos.DrawSphere(spherelight.transform.position, additionalLightData.shapeWidth);
if (spherelight.shadows != LightShadows.None) Gizmos.DrawWireSphere(spherelight.transform.position, spherelight.shadowNearPlane);
Gizmos.DrawWireSphere(spherelight.transform.position, spherelight.range);
}

}
else // Ortho frustum
{
//DrawLightOrthoFrustum(Vector3.zero, additionalLightData.shapeLength, additionalLightData.shapeWidth, frustumlight.range, 0.0f);
//DrawLightOrthoFrustum(Vector3.zero, additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range, 0.0f);
Vector3 frustumsize = new Vector3(additionalLightData.shapeLength, additionalLightData.shapeWidth, frustumlight.range);
Vector3 frustumsize = new Vector3(additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range);
Gizmos.DrawWireCube(frustumCenter, frustumsize);
}
Gizmos.matrix = Matrix4x4.identity;

10
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public Vector3 forward;
public int cookieIndex; // -1 if unused
public Vector3 right; // Rescaled by (2 / shapeLength)
public Vector3 right; // Rescaled by (2 / shapeWidth)
public Vector3 up; // Rescaled by (2 / shapeWidth)
public Vector3 up; // Rescaled by (2 / shapeHeight)
public float diffuseScale;
public Vector2 fadeDistanceScaleAndBias; // Use with ShadowMask feature

public Vector3 forward;
public int cookieIndex; // -1 if unused
public Vector3 right; // If spot: rescaled by cot(outerHalfAngle); if projector: rescaled by (2 / shapeLength)
public Vector3 right; // If spot: rescaled by cot(outerHalfAngle); if projector: rescaled by (2 / shapeWidth)
public Vector3 up; // If spot: rescaled by cot(outerHalfAngle); if projector: rescaled by (2 / shapeWidth)
public Vector3 up; // If spot: rescaled by cot(outerHalfAngle); if projector: rescaled by (2 / shapeHeight)
public float diffuseScale;
public float angleScale; // Spot light

public Vector4 shadowMaskSelector; // Use with ShadowMask feature
public Vector2 size; // Used by area and pyramid projector lights
public Vector2 size; // Used by area (X = length or width, Y = height) and box projector lights (X = range (depth))
public GPULightType lightType;
public float minRoughness; // This is use to give a small "area" to punctual light, as if we have a light with a radius.
};

52
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


// Light direction for directional is opposite to the forward direction
directionalLightData.forward = light.light.transform.forward;
// Rescale for cookies and windowing.
directionalLightData.up = light.light.transform.up * 2 / additionalData.shapeWidth;
directionalLightData.right = light.light.transform.right * 2 / additionalData.shapeLength;
directionalLightData.up = light.light.transform.up * 2 / additionalData.shapeHeight;
directionalLightData.right = light.light.transform.right * 2 / additionalData.shapeWidth;
directionalLightData.positionWS = light.light.transform.position;
directionalLightData.color = GetLightColor(light);
directionalLightData.diffuseScale = additionalData.affectDiffuse ? diffuseDimmer : 0.0f;

return 1.0f - Mathf.Clamp01(distanceToCamera * scale + bias);
}
public bool GetLightData(CommandBuffer cmd, ShadowSettings shadowSettings, Camera camera, GPULightType gpuLightType, VisibleLight light, HDAdditionalLightData additionalLightData, AdditionalShadowData additionalshadowData, int lightIndex)
public bool GetLightData(CommandBuffer cmd, ShadowSettings shadowSettings, Camera camera, GPULightType gpuLightType,
VisibleLight light, HDAdditionalLightData additionalLightData, AdditionalShadowData additionalshadowData,
int lightIndex, ref Vector3 lightDimensions)
{
var lightData = new LightData();

lightData.up = light.light.transform.up;
lightData.right = light.light.transform.right;
lightData.size = new Vector2(additionalLightData.shapeLength, additionalLightData.shapeWidth);
lightDimensions.x = additionalLightData.shapeWidth;
lightDimensions.y = additionalLightData.shapeHeight;
lightDimensions.z = light.range;
lightData.size.x = light.range;
lightData.right *= 2.0f / additionalLightData.shapeLength;
lightData.up *= 2.0f / additionalLightData.shapeWidth;
lightData.right *= 2.0f / additionalLightData.shapeWidth;
lightData.up *= 2.0f / additionalLightData.shapeHeight;
}
else if (lightData.lightType == GPULightType.ProjectorPyramid)
{

float frustumHeight;
float frustumWidth;
float frustumWidth, frustumHeight;
if (additionalLightData.aspectRatio >= 1.0f)
{
frustumHeight = 2.0f * Mathf.Tan(spotAngle * 0.5f * Mathf.Deg2Rad);

frustumHeight = frustumWidth / additionalLightData.aspectRatio;
}
lightData.size = new Vector2(frustumWidth, frustumHeight);
// Adjust based on the new parametrization.
lightDimensions.x = frustumWidth;
lightDimensions.y = frustumHeight;
// Rescale for cookies and windowing.
lightData.right *= 2.0f / frustumWidth;

// These are the neutral values allowing GetAngleAnttenuation in shader code to return 1.0
lightData.angleScale = 0.0f;
lightData.angleOffset = 1.0f;
}
if (lightData.lightType == GPULightType.Rectangle || lightData.lightType == GPULightType.Line)
{
lightData.size = new Vector2(additionalLightData.shapeWidth, additionalLightData.shapeHeight);
}
float distanceToCamera = (lightData.positionWS - camera.transform.position).magnitude;

}
// TODO: we should be able to do this calculation only with LightData without VisibleLight light, but for now pass both
public void GetLightVolumeDataAndBound(LightCategory lightCategory, GPULightType gpuLightType, LightVolumeType lightVolumeType, VisibleLight light, LightData lightData, Matrix4x4 worldToView)
public void GetLightVolumeDataAndBound(LightCategory lightCategory, GPULightType gpuLightType, LightVolumeType lightVolumeType,
VisibleLight light, LightData lightData, Vector3 lightDimensions, Matrix4x4 worldToView)
var range = light.range;
var range = lightDimensions.z;
var lightToWorld = light.localToWorld;
Vector3 positionWS = lightData.positionWS;
Vector3 positionVS = worldToView.MultiplyPoint(positionWS);

if (gpuLightType == GPULightType.ProjectorPyramid)
{
Vector3 lightPosToProjWindowCorner = (0.5f * lightData.size.x) * vx + (0.5f * lightData.size.y) * vy + 1.0f * vz;
Vector3 lightPosToProjWindowCorner = (0.5f * lightDimensions.x) * vx + (0.5f * lightDimensions.y) * vy + 1.0f * vz;
cs = Vector3.Dot(vz, Vector3.Normalize(lightPosToProjWindowCorner));
si = Mathf.Sqrt(1.0f - cs * cs);
}

}
else if (gpuLightType == GPULightType.Line)
{
Vector3 dimensions = new Vector3(lightData.size.x + 2 * range, 2 * range, 2 * range); // Omni-directional
Vector3 dimensions = new Vector3(lightDimensions.x + 2 * range, 2 * range, 2 * range); // Omni-directional
Vector3 extents = 0.5f * dimensions;
bound.center = positionVS;

lightVolumeData.lightAxisX = xAxisVS;
lightVolumeData.lightAxisY = yAxisVS;
lightVolumeData.lightAxisZ = zAxisVS;
lightVolumeData.boxInnerDist = new Vector3(lightData.size.x, 0, 0);
lightVolumeData.boxInnerDist = new Vector3(lightDimensions.x, 0, 0);
Vector3 dimensions = new Vector3(lightData.size.x + 2 * range, lightData.size.y + 2 * range, range); // One-sided
Vector3 dimensions = new Vector3(lightDimensions.x + 2 * range, lightDimensions.y + 2 * range, range); // One-sided
Vector3 extents = 0.5f * dimensions;
Vector3 centerVS = positionVS + extents.z * zAxisVS;

}
else if (gpuLightType == GPULightType.ProjectorBox)
{
Vector3 dimensions = new Vector3(lightData.size.x, lightData.size.y, range); // One-sided
Vector3 dimensions = new Vector3(lightDimensions.x, lightDimensions.y, range); // One-sided
Vector3 extents = 0.5f * dimensions;
Vector3 centerVS = positionVS + extents.z * zAxisVS;

continue;
}
Vector3 lightDimensions = new Vector3(); // X = length or width, Y = height, Z = range (depth)
if (GetLightData(cmd, shadowSettings, camera, gpuLightType, light, additionalLightData, additionalShadowData, lightIndex))
if (GetLightData(cmd, shadowSettings, camera, gpuLightType, light, additionalLightData, additionalShadowData, lightIndex, ref lightDimensions))
{
switch (lightCategory)
{

}
// Then culling side. Must be call in this order as we pass the created Light data to the function
GetLightVolumeDataAndBound(lightCategory, gpuLightType, lightVolumeType, light, m_lightList.lights[m_lightList.lights.Count - 1], worldToView);
GetLightVolumeDataAndBound(lightCategory, gpuLightType, lightVolumeType, light, m_lightList.lights[m_lightList.lights.Count - 1], lightDimensions, worldToView);
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[surfaceData.subsurfaceProfile].a;
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u, 2u * surfaceData.subsurfaceProfile);
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u * surfaceData.subsurfaceProfile, 2u);
FillMaterialIdSssData(surfaceData.subsurfaceProfile,
surfaceData.subsurfaceRadius,

DecodeFromSSSBuffer(inGBuffer0, positionSS, sssData);
subsurfaceProfile = sssData.subsurfaceProfile;
transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u, 2u * subsurfaceProfile);
transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u * subsurfaceProfile, 2u);
radius = sssData.subsurfaceRadius;
thickness = inGBuffer2.g;

2
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl


#endif
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
#endif
};

4
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1210_Lit_BentNormal.unity


affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 2.5
shapeWidth: 4.51
shapeWidth: 2.5
shapeHeight: 4.51
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

2
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2001_Dynamic_Directional.unity


affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 8
shapeHeight: 8
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

8
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2002_Dynamic_Mix.unity


affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 1
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 3.5
shapeHeight: 3.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

54
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting/2003_Light_Parameters.unity


affectSpecular: 1
lightTypeExtent: 1
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 1
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 1.1
shapeWidth: 6
shapeWidth: 1.1
shapeHeight: 6
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 0.2

affectSpecular: 0
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 2
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 2
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 2
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 1.1
shapeWidth: 6
shapeWidth: 1.1
shapeHeight: 6
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 0.8

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 1.1
shapeWidth: 6
shapeWidth: 1.1
shapeHeight: 6
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 1.1
shapeWidth: 6
shapeWidth: 1.1
shapeHeight: 6
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 0.6

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 2
shapeLength: 1.1
shapeWidth: 6
shapeWidth: 1.1
shapeHeight: 6
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 0.4

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 1
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 0
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 1

正在加载...
取消
保存