浏览代码

Revert modification of lightdefinition for envlight

This isn't necessary and need to be change before users start to do
modification
/2018.1
sebastienlagarde 6 年前
当前提交
115e53ee
共有 8 个文件被更改,包括 113 次插入560 次删除
  1. 259
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  2. 289
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  3. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl
  4. 48
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/VolumeProjection.hlsl
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl
  6. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  7. 35
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.custom.hlsl
  8. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.custom.hlsl.meta

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


public struct EnvLightData
{
// Packing order depends on chronological access to avoid cache misses
// Caution: The struct need to be align on byte16 (not strictly needed for structured buffer but if we do array later better).
public float capturePositionWSX;
public float capturePositionWSY;
public float capturePositionWSZ;
public Vector3 capturePositionWS;
public float proxyExtentsX;
public float proxyExtentsY;
public float proxyExtentsZ;
public Vector3 proxyExtents;
public float proxyPositionWSX;
public float proxyPositionWSY;
public float proxyPositionWSZ;
public float proxyForwardX;
public float proxyForwardY;
public float proxyForwardZ;
public float proxyUpX;
public float proxyUpY;
public float proxyUpZ;
public float proxyRightX;
public float proxyRightY;
public float proxyRightZ;
public Vector3 proxyPositionWS;
public Vector3 proxyForward;
public Vector3 proxyUp;
public Vector3 proxyRight;
public float influencePositionWSX;
public float influencePositionWSY;
public float influencePositionWSZ;
public float influenceForwardX;
public float influenceForwardY;
public float influenceForwardZ;
public float influenceUpX;
public float influenceUpY;
public float influenceUpZ;
public float influenceRightX;
public float influenceRightY;
public float influenceRightZ;
public Vector3 influencePositionWS;
public Vector3 influenceForward;
public Vector3 influenceUp;
public Vector3 influenceRight;
public float influenceExtentsX;
public float influenceExtentsY;
public float influenceExtentsZ;
public Vector3 influenceExtents;
public float blendDistancePositiveX;
public float blendDistancePositiveY;
public float blendDistancePositiveZ;
public float blendDistanceNegativeX;
public float blendDistanceNegativeY;
public float blendDistanceNegativeZ;
public float blendNormalDistancePositiveX;
public float blendNormalDistancePositiveY;
public float blendNormalDistancePositiveZ;
public float blendNormalDistanceNegativeX;
public float blendNormalDistanceNegativeY;
public float blendNormalDistanceNegativeZ;
public Vector3 blendDistancePositive;
public Vector3 blendDistanceNegative;
public Vector3 blendNormalDistancePositive;
public Vector3 blendNormalDistanceNegative;
public float boxSideFadePositiveX;
public float boxSideFadePositiveY;
public float boxSideFadePositiveZ;
public float boxSideFadeNegativeX;
public float boxSideFadeNegativeY;
public float boxSideFadeNegativeZ;
public Vector3 boxSideFadePositive;
public Vector3 boxSideFadeNegative;
public float sampleDirectionDiscardWSX;
public float sampleDirectionDiscardWSY;
public float sampleDirectionDiscardWSZ;
public Vector3 sampleDirectionDiscardWS;
public Vector3 capturePositionWS
{
get { return new Vector3(capturePositionWSX, capturePositionWSY, capturePositionWSZ); }
set
{
capturePositionWSX = value.x;
capturePositionWSY = value.y;
capturePositionWSZ = value.z;
}
}
public Vector3 proxyExtents
{
get { return new Vector3(proxyExtentsX, proxyExtentsY, proxyExtentsZ); }
set
{
proxyExtentsX = value.x;
proxyExtentsY = value.y;
proxyExtentsZ = value.z;
}
}
public Vector3 proxyPositionWS
{
get { return new Vector3(proxyPositionWSX, proxyPositionWSY, proxyPositionWSZ); }
set
{
proxyPositionWSX = value.x;
proxyPositionWSY = value.y;
proxyPositionWSZ = value.z;
}
}
public Vector3 proxyForward
{
get { return new Vector3(proxyForwardX, proxyForwardY, proxyForwardZ); }
set
{
proxyForwardX = value.x;
proxyForwardY = value.y;
proxyForwardZ = value.z;
}
}
public Vector3 proxyUp
{
get { return new Vector3(proxyUpX, proxyUpY, proxyUpZ); }
set
{
proxyUpX = value.x;
proxyUpY = value.y;
proxyUpZ = value.z;
}
}
public Vector3 proxyRight
{
get { return new Vector3(proxyRightX, proxyRightY, proxyRightZ); }
set
{
proxyRightX = value.x;
proxyRightY = value.y;
proxyRightZ = value.z;
}
}
public Vector3 influenceExtents
{
get { return new Vector3(influenceExtentsX, influenceExtentsY, influenceExtentsZ); }
set
{
influenceExtentsX = value.x;
influenceExtentsY = value.y;
influenceExtentsZ = value.z;
}
}
public Vector3 influencePositionWS
{
get { return new Vector3(influencePositionWSX, influencePositionWSY, influencePositionWSZ); }
set
{
influencePositionWSX = value.x;
influencePositionWSY = value.y;
influencePositionWSZ = value.z;
}
}
public Vector3 influenceForward
{
get { return new Vector3(influenceForwardX, influenceForwardY, influenceForwardZ); }
set
{
influenceForwardX = value.x;
influenceForwardY = value.y;
influenceForwardZ = value.z;
}
}
public Vector3 influenceUp
{
get { return new Vector3(influenceUpX, influenceUpY, influenceUpZ); }
set
{
influenceUpX = value.x;
influenceUpY = value.y;
influenceUpZ = value.z;
}
}
public Vector3 influenceRight
{
get { return new Vector3(influenceRightX, influenceRightY, influenceRightZ); }
set
{
influenceRightX = value.x;
influenceRightY = value.y;
influenceRightZ = value.z;
}
}
public Vector3 blendDistancePositive
{
get { return new Vector3(blendDistancePositiveX, blendDistancePositiveY, blendDistancePositiveZ); }
set
{
blendDistancePositiveX = value.x;
blendDistancePositiveY = value.y;
blendDistancePositiveZ = value.z;
}
}
public Vector3 blendDistanceNegative
{
get { return new Vector3(blendDistanceNegativeX, blendDistanceNegativeY, blendDistanceNegativeZ); }
set
{
blendDistanceNegativeX = value.x;
blendDistanceNegativeY = value.y;
blendDistanceNegativeZ = value.z;
}
}
public Vector3 blendNormalDistancePositive
{
get { return new Vector3(blendNormalDistancePositiveX, blendNormalDistancePositiveY, blendNormalDistancePositiveZ); }
set
{
blendNormalDistancePositiveX = value.x;
blendNormalDistancePositiveY = value.y;
blendNormalDistancePositiveZ = value.z;
}
}
public Vector3 blendNormalDistanceNegative
{
get { return new Vector3(blendNormalDistanceNegativeX, blendNormalDistanceNegativeY, blendNormalDistanceNegativeZ); }
set
{
blendNormalDistanceNegativeX = value.x;
blendNormalDistanceNegativeY = value.y;
blendNormalDistanceNegativeZ = value.z;
}
}
public Vector3 boxSideFadePositive
{
get { return new Vector3(boxSideFadePositiveX, boxSideFadePositiveY, boxSideFadePositiveZ); }
set
{
boxSideFadePositiveX = value.x;
boxSideFadePositiveY = value.y;
boxSideFadePositiveZ = value.z;
}
}
public Vector3 boxSideFadeNegative
{
get { return new Vector3(boxSideFadeNegativeX, boxSideFadeNegativeY, boxSideFadeNegativeZ); }
set
{
boxSideFadeNegativeX = value.x;
boxSideFadeNegativeY = value.y;
boxSideFadeNegativeZ = value.z;
}
}
public Vector3 sampleDirectionDiscardWS
{
get { return new Vector3(sampleDirectionDiscardWSX, sampleDirectionDiscardWSY, sampleDirectionDiscardWSZ); }
set
{
sampleDirectionDiscardWSX = value.x;
sampleDirectionDiscardWSY = value.y;
sampleDirectionDiscardWSZ = value.z;
}
}
};
[GenerateHLSL]

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


// PackingRules = Exact
struct EnvLightData
{
float capturePositionWSX;
float capturePositionWSY;
float capturePositionWSZ;
float3 capturePositionWS;
float proxyExtentsX;
float proxyExtentsY;
float proxyExtentsZ;
float3 proxyExtents;
float proxyPositionWSX;
float proxyPositionWSY;
float proxyPositionWSZ;
float proxyForwardX;
float proxyForwardY;
float proxyForwardZ;
float proxyUpX;
float proxyUpY;
float proxyUpZ;
float proxyRightX;
float proxyRightY;
float proxyRightZ;
float influencePositionWSX;
float influencePositionWSY;
float influencePositionWSZ;
float influenceForwardX;
float influenceForwardY;
float influenceForwardZ;
float influenceUpX;
float influenceUpY;
float influenceUpZ;
float influenceRightX;
float influenceRightY;
float influenceRightZ;
float influenceExtentsX;
float influenceExtentsY;
float influenceExtentsZ;
float3 proxyPositionWS;
float3 proxyForward;
float3 proxyUp;
float3 proxyRight;
float3 influencePositionWS;
float3 influenceForward;
float3 influenceUp;
float3 influenceRight;
float3 influenceExtents;
float blendDistancePositiveX;
float blendDistancePositiveY;
float blendDistancePositiveZ;
float blendDistanceNegativeX;
float blendDistanceNegativeY;
float blendDistanceNegativeZ;
float blendNormalDistancePositiveX;
float blendNormalDistancePositiveY;
float blendNormalDistancePositiveZ;
float blendNormalDistanceNegativeX;
float blendNormalDistanceNegativeY;
float blendNormalDistanceNegativeZ;
float boxSideFadePositiveX;
float boxSideFadePositiveY;
float boxSideFadePositiveZ;
float boxSideFadeNegativeX;
float boxSideFadeNegativeY;
float boxSideFadeNegativeZ;
float3 blendDistancePositive;
float3 blendDistanceNegative;
float3 blendNormalDistancePositive;
float3 blendNormalDistanceNegative;
float3 boxSideFadePositive;
float3 boxSideFadeNegative;
float sampleDirectionDiscardWSX;
float sampleDirectionDiscardWSY;
float sampleDirectionDiscardWSZ;
float3 sampleDirectionDiscardWS;
int envIndex;
};

//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float GetCapturePositionWSX(EnvLightData value)
{
return value.capturePositionWSX;
}
float GetCapturePositionWSY(EnvLightData value)
float3 GetCapturePositionWS(EnvLightData value)
return value.capturePositionWSY;
}
float GetCapturePositionWSZ(EnvLightData value)
{
return value.capturePositionWSZ;
return value.capturePositionWS;
float GetProxyExtentsX(EnvLightData value)
float3 GetProxyExtents(EnvLightData value)
return value.proxyExtentsX;
}
float GetProxyExtentsY(EnvLightData value)
{
return value.proxyExtentsY;
}
float GetProxyExtentsZ(EnvLightData value)
{
return value.proxyExtentsZ;
return value.proxyExtents;
float GetProxyPositionWSX(EnvLightData value)
float3 GetProxyPositionWS(EnvLightData value)
return value.proxyPositionWSX;
return value.proxyPositionWS;
float GetProxyPositionWSY(EnvLightData value)
float3 GetProxyForward(EnvLightData value)
return value.proxyPositionWSY;
return value.proxyForward;
float GetProxyPositionWSZ(EnvLightData value)
float3 GetProxyUp(EnvLightData value)
return value.proxyPositionWSZ;
return value.proxyUp;
float GetProxyForwardX(EnvLightData value)
{
return value.proxyForwardX;
}
float GetProxyForwardY(EnvLightData value)
{
return value.proxyForwardY;
}
float GetProxyForwardZ(EnvLightData value)
float3 GetProxyRight(EnvLightData value)
return value.proxyForwardZ;
return value.proxyRight;
float GetProxyUpX(EnvLightData value)
float3 GetInfluencePositionWS(EnvLightData value)
return value.proxyUpX;
}
float GetProxyUpY(EnvLightData value)
{
return value.proxyUpY;
return value.influencePositionWS;
float GetProxyUpZ(EnvLightData value)
float3 GetInfluenceForward(EnvLightData value)
return value.proxyUpZ;
return value.influenceForward;
float GetProxyRightX(EnvLightData value)
float3 GetInfluenceUp(EnvLightData value)
return value.proxyRightX;
return value.influenceUp;
float GetProxyRightY(EnvLightData value)
float3 GetInfluenceRight(EnvLightData value)
return value.proxyRightY;
return value.influenceRight;
float GetProxyRightZ(EnvLightData value)
float3 GetInfluenceExtents(EnvLightData value)
return value.proxyRightZ;
}
float GetInfluencePositionWSX(EnvLightData value)
{
return value.influencePositionWSX;
}
float GetInfluencePositionWSY(EnvLightData value)
{
return value.influencePositionWSY;
}
float GetInfluencePositionWSZ(EnvLightData value)
{
return value.influencePositionWSZ;
}
float GetInfluenceForwardX(EnvLightData value)
{
return value.influenceForwardX;
}
float GetInfluenceForwardY(EnvLightData value)
{
return value.influenceForwardY;
}
float GetInfluenceForwardZ(EnvLightData value)
{
return value.influenceForwardZ;
}
float GetInfluenceUpX(EnvLightData value)
{
return value.influenceUpX;
}
float GetInfluenceUpY(EnvLightData value)
{
return value.influenceUpY;
}
float GetInfluenceUpZ(EnvLightData value)
{
return value.influenceUpZ;
}
float GetInfluenceRightX(EnvLightData value)
{
return value.influenceRightX;
}
float GetInfluenceRightY(EnvLightData value)
{
return value.influenceRightY;
}
float GetInfluenceRightZ(EnvLightData value)
{
return value.influenceRightZ;
}
float GetInfluenceExtentsX(EnvLightData value)
{
return value.influenceExtentsX;
}
float GetInfluenceExtentsY(EnvLightData value)
{
return value.influenceExtentsY;
}
float GetInfluenceExtentsZ(EnvLightData value)
{
return value.influenceExtentsZ;
return value.influenceExtents;
float GetBlendDistancePositiveX(EnvLightData value)
{
return value.blendDistancePositiveX;
}
float GetBlendDistancePositiveY(EnvLightData value)
{
return value.blendDistancePositiveY;
}
float GetBlendDistancePositiveZ(EnvLightData value)
{
return value.blendDistancePositiveZ;
}
float GetBlendDistanceNegativeX(EnvLightData value)
{
return value.blendDistanceNegativeX;
}
float GetBlendDistanceNegativeY(EnvLightData value)
{
return value.blendDistanceNegativeY;
}
float GetBlendDistanceNegativeZ(EnvLightData value)
{
return value.blendDistanceNegativeZ;
}
float GetBlendNormalDistancePositiveX(EnvLightData value)
{
return value.blendNormalDistancePositiveX;
}
float GetBlendNormalDistancePositiveY(EnvLightData value)
{
return value.blendNormalDistancePositiveY;
}
float GetBlendNormalDistancePositiveZ(EnvLightData value)
{
return value.blendNormalDistancePositiveZ;
}
float GetBlendNormalDistanceNegativeX(EnvLightData value)
{
return value.blendNormalDistanceNegativeX;
}
float GetBlendNormalDistanceNegativeY(EnvLightData value)
{
return value.blendNormalDistanceNegativeY;
}
float GetBlendNormalDistanceNegativeZ(EnvLightData value)
{
return value.blendNormalDistanceNegativeZ;
}
float GetBoxSideFadePositiveX(EnvLightData value)
float3 GetBlendDistancePositive(EnvLightData value)
return value.boxSideFadePositiveX;
return value.blendDistancePositive;
float GetBoxSideFadePositiveY(EnvLightData value)
float3 GetBlendDistanceNegative(EnvLightData value)
return value.boxSideFadePositiveY;
return value.blendDistanceNegative;
float GetBoxSideFadePositiveZ(EnvLightData value)
float3 GetBlendNormalDistancePositive(EnvLightData value)
return value.boxSideFadePositiveZ;
return value.blendNormalDistancePositive;
float GetBoxSideFadeNegativeX(EnvLightData value)
float3 GetBlendNormalDistanceNegative(EnvLightData value)
return value.boxSideFadeNegativeX;
return value.blendNormalDistanceNegative;
float GetBoxSideFadeNegativeY(EnvLightData value)
float3 GetBoxSideFadePositive(EnvLightData value)
return value.boxSideFadeNegativeY;
return value.boxSideFadePositive;
float GetBoxSideFadeNegativeZ(EnvLightData value)
float3 GetBoxSideFadeNegative(EnvLightData value)
return value.boxSideFadeNegativeZ;
return value.boxSideFadeNegative;
}
float GetDimmer(EnvLightData value)
{

{
return value.unused01;
}
float GetSampleDirectionDiscardWSX(EnvLightData value)
{
return value.sampleDirectionDiscardWSX;
}
float GetSampleDirectionDiscardWSY(EnvLightData value)
{
return value.sampleDirectionDiscardWSY;
}
float GetSampleDirectionDiscardWSZ(EnvLightData value)
float3 GetSampleDirectionDiscardWS(EnvLightData value)
return value.sampleDirectionDiscardWSZ;
return value.sampleDirectionDiscardWS;
}
int GetEnvIndex(EnvLightData value)
{

#endif
#include "LightDefinition.cs.custom.hlsl"

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


#include "LightDefinition.cs.hlsl"
#define SETTER_FLOAT3(data, field, value)\
data.##field##X = value.x;\
data.##field##Y = value.y;\
data.##field##Z = value.z
// 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.
EnvLightData InitSkyEnvLightData(int envIndex)

output.influenceShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
SETTER_FLOAT3(output, influenceForward, float3(0.0, 0.0, 1.0));
SETTER_FLOAT3(output, influenceUp, float3(0.0, 1.0, 0.0));
SETTER_FLOAT3(output, influenceRight, float3(1.0, 0.0, 0.0));
SETTER_FLOAT3(output, influencePositionWS, float3(0.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);
SETTER_FLOAT3(output, proxyForward, float3(0.0, 0.0, 1.0));
SETTER_FLOAT3(output, proxyUp, float3(0.0, 1.0, 0.0));
SETTER_FLOAT3(output, proxyRight, float3(1.0, 0.0, 0.0));
output.proxyForward = float3(0.0, 0.0, 1.0);
output.proxyUp = float3(0.0, 1.0, 0.0);
output.proxyRight = float3(1.0, 0.0, 0.0);
#undef SETTER_FLOAT3
#endif // UNITY_LIGHT_UTILITIES_INCLUDED

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


{
return transpose(
float3x3(
GetProxyRight(lightData),
GetProxyUp(lightData),
GetProxyForward(lightData)
lightData.proxyRight,
lightData.proxyUp,
lightData.proxyForward
)
); // worldToLocal assume no scaling
}

float3 positionPS = positionWS - GetProxyPositionWS(lightData);
float3 positionPS = positionWS - lightData.proxyPositionWS;
positionPS = mul(positionPS, worldToPS).xyz;
return positionPS;
}

float sphereOuterDistance = lightData.proxyExtentsX;
float sphereOuterDistance = lightData.proxyExtents.x;
float projectionDistance = IntersectRaySphereSimple(positionPS, dirPS, sphereOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)

float IntersectBoxProxy(EnvLightData lightData, float3 dirPS, float3 positionPS)
{
float3 boxOuterDistance = GetProxyExtents(lightData);
float3 boxOuterDistance = lightData.proxyExtents;
float projectionDistance = IntersectRayAABBSimple(positionPS, dirPS, -boxOuterDistance, boxOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)

float InfluenceSphereWeight(EnvLightData lightData, BSDFData bsdfData, float3 positionWS, float3 positionLS, float3 dirLS)
{
float lengthPositionLS = length(positionLS);
float sphereInfluenceDistance = lightData.influenceExtentsX - lightData.blendDistancePositiveX;
float sphereInfluenceDistance = lightData.influenceExtents.x - lightData.blendDistancePositive.x;
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositiveX, 0.0001)); // avoid divide by zero
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositive.x, 0.0001)); // avoid divide by zero
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtentsX - lightData.blendNormalDistancePositiveX) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - GetCapturePositionWS(lightData)));
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtents.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float InfluenceBoxWeight(EnvLightData lightData, BSDFData bsdfData, float3 positionWS, float3 positionIS, float3 dirIS)
{
float3 influenceExtents = GetInfluenceExtents(lightData);
float3 influenceExtents = lightData.influenceExtents;
// 2. Process the position influence
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection.
#if defined(ENVMAP_FEATURE_PERFACEINFLUENCE) || defined(ENVMAP_FEATURE_INFLUENCENORMAL) || defined(ENVMAP_FEATURE_PERFACEFADE)

#if defined(ENVMAP_FEATURE_PERFACEINFLUENCE)
// Influence falloff for each face
float3 negativeFalloff = negativeDistance / max(0.0001, GetBlendDistanceNegative(lightData));
float3 positiveFalloff = positiveDistance / max(0.0001, GetBlendDistancePositive(lightData));
float3 negativeFalloff = negativeDistance / max(0.0001, lightData.blendDistanceNegative);
float3 positiveFalloff = positiveDistance / max(0.0001, lightData.blendDistancePositive);
// Fallof is the min for all faces
float influenceFalloff = min(

float alpha = saturate(influenceFalloff);
#else
float distFace = DistancePointBox(positionIS, -influenceExtents + lightData.blendDistancePositiveX, influenceExtents - lightData.blendDistancePositiveX);
float alpha = saturate(1.0 - distFace / max(lightData.blendDistancePositiveX, 0.0001));
float distFace = DistancePointBox(positionIS, -influenceExtents + lightData.blendDistancePositive.x, influenceExtents - lightData.blendDistancePositive.x);
float alpha = saturate(1.0 - distFace / max(lightData.blendDistancePositive.x, 0.0001));
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, GetBlendNormalDistancePositive(lightData));
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, GetBlendNormalDistanceNegative(lightData));
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - GetCapturePositionWS(lightData)));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

// We consider R.x as cos(X) and then fade as angle from 60°(=acos(1/2)) to 75°(=acos(1/4))
// For positive axes: axisFade = (R - 1/4) / (1/2 - 1/4)
// <=> axisFace = 4 * R - 1;
float3 faceFade = saturate((4 * dirIS - 1) * GetBoxSideFadePositive(lightData))
+ saturate((-4 * dirIS - 1) * GetBoxSideFadeNegative(lightData));
float3 faceFade = saturate((4 * dirIS - 1) * lightData.boxSideFadePositive)
+ saturate((-4 * dirIS - 1) * lightData.boxSideFadeNegative);
alpha *= saturate(faceFade.x + faceFade.y + faceFade.z);
#endif

{
return transpose(
float3x3(
GetInfluenceRight(lightData),
GetInfluenceUp(lightData),
GetInfluenceForward(lightData)
lightData.influenceRight,
lightData.influenceUp,
lightData.influenceForward
)
); // worldToLocal assume no scaling
}

float3 positionIS = positionWS - GetInfluencePositionWS(lightData);
float3 positionIS = positionWS - lightData.influencePositionWS;
positionIS = mul(positionIS, worldToIS).xyz;
return positionIS;
}

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl


// PackingRules = Exact
struct DecalData
{
float4x4 worldToDecal;
float4x4 worldToDecal;
float4x4 normalToWorld;
};

float4x4 GetWorldToDecal(DecalData value)
{
return value.worldToDecal;
}
float4x4 GetNormalToWorld(DecalData value)
{
return value.normalToWorld;

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


{
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
float3 capturePositionWS = GetCapturePositionWS(lightData);
float3 capturePositionWS = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// Test again for clear coat

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
float3 capturePositionWS = GetCapturePositionWS(lightData);
float3 capturePositionWS = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// TODO: add distance based roughness

float roughness = PerceptualRoughnessToRoughness(preLightData.iblPerceptualRoughness);
R = lerp(R, preLightData.iblR, saturate(smoothstep(0, 1, roughness * roughness)));
float3 sampleDirectionDiscardWS = GetSampleDirectionDiscardWS(lightData);
float3 sampleDirectionDiscardWS = lightData.sampleDirectionDiscardWS;
if (dot(sampleDirectionDiscardWS, R) < 0)
return lighting;

35
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.custom.hlsl


#ifndef LIGHTDEFINITION_CUSTOM_HLSL
#define LIGHTDEFINITION_CUSTOM_HLSL
//-----------------------------------------------------------------------------
// Packing accessors
//-----------------------------------------------------------------------------
#define GETTER_FLOAT3(Type, Name, field)\
float3 Name(Type data)\
{\
return float3(data.##field##X, data.##field##Y, data.##field##Z);\
}
GETTER_FLOAT3(EnvLightData, GetCapturePositionWS, capturePositionWS)
GETTER_FLOAT3(EnvLightData, GetProxyPositionWS, proxyPositionWS)
GETTER_FLOAT3(EnvLightData, GetProxyForward, proxyForward)
GETTER_FLOAT3(EnvLightData, GetProxyUp, proxyUp)
GETTER_FLOAT3(EnvLightData, GetProxyRight, proxyRight)
GETTER_FLOAT3(EnvLightData, GetProxyExtents, proxyExtents)
GETTER_FLOAT3(EnvLightData, GetInfluencePositionWS, influencePositionWS)
GETTER_FLOAT3(EnvLightData, GetInfluenceForward, influenceForward)
GETTER_FLOAT3(EnvLightData, GetInfluenceUp, influenceUp)
GETTER_FLOAT3(EnvLightData, GetInfluenceRight, influenceRight)
GETTER_FLOAT3(EnvLightData, GetInfluenceExtents, influenceExtents)
GETTER_FLOAT3(EnvLightData, GetBlendDistancePositive, blendDistancePositive)
GETTER_FLOAT3(EnvLightData, GetBlendDistanceNegative, blendDistanceNegative)
GETTER_FLOAT3(EnvLightData, GetBlendNormalDistancePositive, blendNormalDistancePositive)
GETTER_FLOAT3(EnvLightData, GetBlendNormalDistanceNegative, blendNormalDistanceNegative)
GETTER_FLOAT3(EnvLightData, GetBoxSideFadePositive, boxSideFadePositive)
GETTER_FLOAT3(EnvLightData, GetBoxSideFadeNegative, boxSideFadeNegative)
GETTER_FLOAT3(EnvLightData, GetSampleDirectionDiscardWS, sampleDirectionDiscardWS)
#undef GETTER_FLOAT3
#endif

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


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