浏览代码

[PlanarProbe] (wip) packing envlightdata structure

/main
Frédéric Vauchelles 7 年前
当前提交
eff3ca9e
共有 6 个文件被更改,包括 340 次插入188 次删除
  1. 302
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  2. 110
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.hlsl
  4. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl
  5. 53
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/VolumeProjection.hlsl
  6. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

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


// PackingRules = Exact
struct EnvLightData
{
float3 capturePositionWS;
float capturePositionWSX;
float capturePositionWSY;
float capturePositionWSZ;
float3 influencePositionWS;
int envIndex;
float3 influenceForward;
float proxyExtentsX;
float proxyExtentsY;
float proxyExtentsZ;
float minProjectionDistance;
float proxyPositionWSX;
float proxyPositionWSY;
float proxyPositionWSZ;
float3 influenceUp;
float3 influenceRight;
float3 influenceExtents;
float dimmer;
float3 blendDistancePositive;
float3 blendDistanceNegative;
float3 blendNormalDistancePositive;
float3 blendNormalDistanceNegative;
float3 boxSideFadePositive;
float3 boxSideFadeNegative;
float3 sampleDirectionDiscardWS;
float minProjectionDistance;
float3 proxyPositionWS;
int proxyShapeType;
float3 proxyExtents;
int unused14;
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;
float unused00;
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;
float dimmer;
float unused01;
float sampleDirectionDiscardWSX;
float sampleDirectionDiscardWSY;
float sampleDirectionDiscardWSZ;
int envIndex;
};
//

//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float3 GetCapturePositionWS(EnvLightData value)
float GetCapturePositionWSX(EnvLightData value)
{
return value.capturePositionWSX;
}
float GetCapturePositionWSY(EnvLightData value)
{
return value.capturePositionWSY;
}
float GetCapturePositionWSZ(EnvLightData value)
return value.capturePositionWS;
return value.capturePositionWSZ;
float3 GetInfluencePositionWS(EnvLightData value)
float GetProxyExtentsX(EnvLightData value)
return value.influencePositionWS;
return value.proxyExtentsX;
int GetEnvIndex(EnvLightData value)
float GetProxyExtentsY(EnvLightData value)
return value.envIndex;
return value.proxyExtentsY;
float3 GetInfluenceForward(EnvLightData value)
float GetProxyExtentsZ(EnvLightData value)
return value.influenceForward;
return value.proxyExtentsZ;
float GetProxyForwardX(EnvLightData value)
float GetMinProjectionDistance(EnvLightData value)
return value.proxyForwardX;
return value.minProjectionDistance;
}
float GetProxyPositionWSX(EnvLightData value)
{
return value.proxyPositionWSX;
}
float GetProxyPositionWSY(EnvLightData value)
{
return value.proxyPositionWSY;
}
float GetProxyPositionWSZ(EnvLightData value)
{
return value.proxyPositionWSZ;
float3 GetInfluenceUp(EnvLightData value)
float GetProxyForwardX(EnvLightData value)
return value.influenceUp;
return value.proxyForwardX;
float3 GetInfluenceRight(EnvLightData value)
{
return value.influenceRight;
}
float3 GetInfluenceExtents(EnvLightData value)
float GetProxyUpX(EnvLightData value)
return value.influenceExtents;
return value.proxyUpX;
float GetDimmer(EnvLightData value)
float GetProxyUpY(EnvLightData value)
return value.dimmer;
return value.proxyUpY;
float3 GetBlendDistancePositive(EnvLightData value)
float GetProxyUpZ(EnvLightData value)
return value.blendDistancePositive;
return value.proxyUpZ;
float GetProxyUpX(EnvLightData value)
float GetProxyRightX(EnvLightData value)
return value.proxyUpX;
return value.proxyRightX;
float3 GetBlendDistanceNegative(EnvLightData value)
float GetProxyRightY(EnvLightData value)
return value.blendDistanceNegative;
return value.proxyRightY;
float GetProxyUpY(EnvLightData value)
float GetProxyRightZ(EnvLightData value)
return value.proxyUpY;
return value.proxyRightZ;
float3 GetBlendNormalDistancePositive(EnvLightData value)
float GetInfluencePositionWSX(EnvLightData value)
return value.blendNormalDistancePositive;
return value.influencePositionWSX;
float GetProxyUpZ(EnvLightData value)
float GetInfluencePositionWSY(EnvLightData value)
return value.proxyUpZ;
return value.influencePositionWSY;
float3 GetBlendNormalDistanceNegative(EnvLightData value)
float GetInfluencePositionWSZ(EnvLightData value)
return value.blendNormalDistanceNegative;
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;
}
float GetUnused00(EnvLightData value)
{
return value.unused00;
}
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 GetProxyRightX(EnvLightData value)
float GetBlendNormalDistancePositiveZ(EnvLightData value)
return value.proxyRightX;
return value.blendNormalDistancePositiveZ;
float3 GetBoxSideFadePositive(EnvLightData value)
float GetBlendNormalDistanceNegativeX(EnvLightData value)
return value.boxSideFadePositive;
return value.blendNormalDistanceNegativeX;
}
float GetBlendNormalDistanceNegativeY(EnvLightData value)
{
return value.blendNormalDistanceNegativeY;
}
float GetBlendNormalDistanceNegativeZ(EnvLightData value)
{
return value.blendNormalDistanceNegativeZ;
}
float GetBoxSideFadePositiveX(EnvLightData value)
{
return value.boxSideFadePositiveX;
}
float GetBoxSideFadePositiveY(EnvLightData value)
{
return value.boxSideFadePositiveY;
}
float GetBoxSideFadePositiveZ(EnvLightData value)
{
return value.boxSideFadePositiveZ;
float GetProxyRightY(EnvLightData value)
float GetBoxSideFadeNegativeX(EnvLightData value)
return value.proxyRightY;
return value.boxSideFadeNegativeX;
float3 GetBoxSideFadeNegative(EnvLightData value)
float GetBoxSideFadeNegativeY(EnvLightData value)
return value.boxSideFadeNegative;
return value.boxSideFadeNegativeY;
float GetProxyRightZ(EnvLightData value)
float GetBoxSideFadeNegativeZ(EnvLightData value)
return value.proxyRightZ;
return value.boxSideFadeNegativeZ;
float3 GetSampleDirectionDiscardWS(EnvLightData value)
float GetDimmer(EnvLightData value)
return value.sampleDirectionDiscardWS;
return value.dimmer;
float GetMinProjectionDistance(EnvLightData value)
float GetUnused01(EnvLightData value)
return value.minProjectionDistance;
return value.unused01;
float3 GetProxyPositionWS(EnvLightData value)
float GetSampleDirectionDiscardWSX(EnvLightData value)
return value.proxyPositionWS;
return value.sampleDirectionDiscardWSX;
int GetProxyShapeType(EnvLightData value)
float GetSampleDirectionDiscardWSY(EnvLightData value)
return value.proxyShapeType;
return value.sampleDirectionDiscardWSY;
float3 GetProxyExtents(EnvLightData value)
float GetSampleDirectionDiscardWSZ(EnvLightData value)
return value.proxyExtents;
return value.sampleDirectionDiscardWSZ;
int GetUnused14(EnvLightData value)
int GetEnvIndex(EnvLightData value)
return value.unused14;
return value.envIndex;
}

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


// Packing accessors
//-----------------------------------------------------------------------------
float3 EnvLightData_GetCapturePositionWS(EnvLightData lightData)
{
return float3(lightData.capturePositionWSX, lightData.capturePositionWSY, lightData.capturePositionWSZ);
#define GETTER_FLOAT3(Type, field)\
float3 Type##_##Get##_##field(Type data)\
{\
return float3(data.##field##X, data.##field##Y, data.##field##Z);\
float3 EnvLightData_GetProxyPositionWS(EnvLightData lightData)
{
return float3(lightData.proxyPositionWSX, lightData.proxyPositionWSY, lightData.proxyPositionWSZ);
}
#define SETTER_FLOAT3(data, field, value)\
data.##field##X = value.x;\
data.##field##Y = value.y;\
data.##field##Z = value.z
float3 EnvLightData_GetProxyForward(EnvLightData lightData)
{
return float3(lightData.proxyForwardX, lightData.proxyForwardY, lightData.proxyForwardZ);
}
GETTER_FLOAT3(EnvLightData, capturePositionWS);
#define EnvLightData_Set_capturePositionWS(data, value) SETTER_FLOAT3(data, capturePositionWS, value)
float3 EnvLightData_GetProxyUp(EnvLightData lightData)
{
return float3(lightData.proxyUpX, lightData.proxyUpY, lightData.proxyUpZ);
}
GETTER_FLOAT3(EnvLightData, proxyPositionWS);
#define EnvLightData_Set_proxyPositionWS(data, value) SETTER_FLOAT3(data, proxyPositionWS, value)
float3 EnvLightData_GetProxyRight(EnvLightData lightData)
{
return float3(lightData.proxyRightX, lightData.proxyRightY, lightData.proxyRightZ);
}
GETTER_FLOAT3(EnvLightData, proxyForward);
#define EnvLightData_Set_proxyForward(data, value) SETTER_FLOAT3(data, proxyForward, value)
float3 EnvLightData_GetProxyExtents(EnvLightData lightData)
{
return float3(lightData.proxyExtentsX, lightData.proxyExtentsY, lightData.proxyExtentsZ);
}
GETTER_FLOAT3(EnvLightData, proxyUp);
#define EnvLightData_Set_proxyUp(data, value) SETTER_FLOAT3(data, proxyUp, value)
float3 EnvLightData_GetInfluencePositionWS(EnvLightData lightData)
{
return float3(lightData.influencePositionWSX, lightData.influencePositionWSY, lightData.influencePositionWSZ);
}
GETTER_FLOAT3(EnvLightData, proxyRight);
#define EnvLightData_Set_proxyRight(data, value) SETTER_FLOAT3(data, proxyRight, value)
float3 EnvLightData_GetInfluenceForward(EnvLightData lightData)
{
return float3(lightData.influenceForwardX, lightData.influenceForwardY, lightData.influenceForwardZ);
}
GETTER_FLOAT3(EnvLightData, proxyExtents);
#define EnvLightData_Set_proxyExtents(data, value) SETTER_FLOAT3(data, proxyExtents, value)
float3 EnvLightData_GetInfluenceUp(EnvLightData lightData)
{
return float3(lightData.influenceUpX, lightData.influenceUpY, lightData.influenceUpZ);
}
GETTER_FLOAT3(EnvLightData, influencePositionWS);
#define EnvLightData_Set_influencePositionWS(data, value) SETTER_FLOAT3(data, influencePositionWS, value)
float3 EnvLightData_GetInfluenceRight(EnvLightData lightData)
{
return float3(lightData.influenceRightX, lightData.influenceRightY, lightData.influenceRightZ);
}
GETTER_FLOAT3(EnvLightData, influenceForward);
#define EnvLightData_Set_influenceForward(data, value) SETTER_FLOAT3(data, influenceForward, value)
GETTER_FLOAT3(EnvLightData, influenceUp);
#define EnvLightData_Set_influenceUp(data, value) SETTER_FLOAT3(data, influenceUp, value)
GETTER_FLOAT3(EnvLightData, influenceRight);
#define EnvLightData_Set_influenceRight(data, value) SETTER_FLOAT3(data, influenceRight, value)
float3 EnvLightData_GetInfluenceExtents(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.influenceExtentsY, lightData.influenceExtentsZ);
}
GETTER_FLOAT3(EnvLightData, influenceExtents);
#define EnvLightData_Set_influenceExtents(data, value) SETTER_FLOAT3(data, influenceExtents, value)
GETTER_FLOAT3(EnvLightData, blendDistancePositive);
#define EnvLightData_Set_blendDistancePositive(data, value) SETTER_FLOAT3(data, blendDistancePositive, value)
GETTER_FLOAT3(EnvLightData, blendDistanceNegative);
#define EnvLightData_Set_blendDistanceNegative(data, value) SETTER_FLOAT3(data, blendDistanceNegative, value)
GETTER_FLOAT3(EnvLightData, blendNormalDistancePositive);
#define EnvLightData_Set_blendNormalDistancePositive(data, value) SETTER_FLOAT3(data, blendNormalDistancePositive, value)
GETTER_FLOAT3(EnvLightData, blendNormalDistanceNegative);
#define EnvLightData_Set_blendNormalDistanceNegative(data, value) SETTER_FLOAT3(data, blendNormalDistanceNegative, value)
float3 EnvLightData_GetBlendDistancePositive(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendDistancePositiveY, lightData.blendDistancePositiveZ);
}
GETTER_FLOAT3(EnvLightData, boxSideFadePositive);
#define EnvLightData_Set_boxSideFadePositive(data, value) SETTER_FLOAT3(data, boxSideFadePositive, value)
float3 EnvLightData_GetBlendDistanceNegative(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendDistanceNegativeY, lightData.blendDistanceNegativeZ);
}
GETTER_FLOAT3(EnvLightData, boxSideFadeNegative);
#define EnvLightData_Set_boxSideFadeNegative(data, value) SETTER_FLOAT3(data, boxSideFadeNegative, value)
float3 EnvLightData_GetBlendNormalDistancePositive(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendNormalDistancePositiveY, lightData.blendNormalDistancePositiveZ);
}
GETTER_FLOAT3(EnvLightData, sampleDirectionDiscardWS);
#define EnvLightData_Set_sampleDirectionDiscardWS(data, value) SETTER_FLOAT3(data, sampleDirectionDiscardWS, value)
float3 EnvLightData_GetBlendNormalDistanceNegative(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendNormalDistanceNegativeY, lightData.blendNormalDistanceNegativeZ);
}
#undef GETTER_FLOAT3
#endif

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


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

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

EnvLightData envLightSky = InitSkyEnvLightData(0);
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, bsdfData,
ENVSHAPETYPE_SKY, ENVSHAPETYPE_SKY,
ENVSHAPETYPE_SKY,
GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION, reflectionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}

EnvLightData envLightSky = InitSkyEnvLightData(0);
IndirectLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, envLightSky, bsdfData,
ENVSHAPETYPE_SKY, ENVSHAPETYPE_SKY,
ENVSHAPETYPE_SKY,
GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION, refractionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}

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


EnvLightData output;
output.influenceShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
output.capturePositionWS = float3(0.0, 0.0, 0.0);
EnvLightData_Set_capturePositionWS(output, 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);
output.influenceExtents = float3(0.0, 0.0, 0.0);
EnvLightData_Set_influenceForward(output, float3(0.0, 0.0, 1.0));
EnvLightData_Set_influenceUp(output, float3(0.0, 1.0, 0.0));
EnvLightData_Set_influenceRight(output, float3(1.0, 0.0, 0.0));
EnvLightData_Set_influencePositionWS(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_influenceExtents(output, 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.blendNormalDistanceNegative = float3(0.0, 0.0, 0.0);
output.boxSideFadePositive = float3(0.0, 0.0, 0.0);
output.boxSideFadeNegative = float3(0.0, 0.0, 0.0);
EnvLightData_Set_blendDistancePositive(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_blendDistanceNegative(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_blendNormalDistancePositive(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_blendNormalDistanceNegative(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_boxSideFadePositive(output, float3(0.0, 0.0, 0.0));
EnvLightData_Set_boxSideFadeNegative(output, float3(0.0, 0.0, 0.0));
output.sampleDirectionDiscardWS = float3(0.0, 0.0, 0.0);
EnvLightData_Set_sampleDirectionDiscardWS(output, float3(0.0, 0.0, 0.0));
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);
EnvLightData_Set_proxyForward(output, float3(0.0, 0.0, 1.0));
EnvLightData_Set_proxyUp(output, float3(0.0, 1.0, 0.0));
EnvLightData_Set_proxyRight(output, float3(1.0, 0.0, 0.0));
EnvLightData_Set_proxyPositionWS(output, float3(0.0, 0.0, 0.0));
output.proxyExtents = float3(0.0, 0.0, 0.0);
EnvLightData_Set_proxyExtents(output, float3(0.0, 0.0, 0.0));
return output;
}

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


{
return transpose(
float3x3(
EnvLightData_GetProxyRight(lightData),
EnvLightData_GetProxyUp(lightData),
EnvLightData_GetProxyForward(lightData)
EnvLightData_Get_proxyRight(lightData),
EnvLightData_Get_proxyUp(lightData),
EnvLightData_Get_proxyForward(lightData)
)
); // worldToLocal assume no scaling
}

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

float sphereOuterDistance = lightData.proxyExtents.x;
float sphereOuterDistance = lightData.proxyExtentsX;
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 = lightData.proxyExtents;
float3 boxOuterDistance = EnvLightData_Get_proxyExtents(lightData);
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.influenceExtents.x - lightData.blendDistancePositive.x;
float sphereInfluenceDistance = lightData.influenceExtentsX - lightData.blendDistancePositiveX;
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositive.x, 0.0001)); // avoid divide by zero
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositiveX, 0.0001)); // avoid divide by zero
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtents.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtentsX - lightData.blendNormalDistancePositiveX) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - EnvLightData_Get_capturePositionWS(lightData)));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float InfluenceBoxWeight(EnvLightData lightData, BSDFData bsdfData, float3 positionWS, float3 positionIS, float3 dirIS)
{
float3 boxOuterDistance = lightData.influenceExtents;
float3 influenceExtents = EnvLightData_Get_influenceExtents(lightData);
float3 negativeDistance = boxOuterDistance + positionIS;
float3 positiveDistance = boxOuterDistance - positionIS;
float3 negativeDistance = influenceExtents + positionIS;
float3 positiveDistance = influenceExtents - positionIS;
float3 negativeFalloff = negativeDistance / max(0.0001, lightData.blendDistanceNegative);
float3 positiveFalloff = positiveDistance / max(0.0001, lightData.blendDistancePositive);
float3 negativeFalloff = negativeDistance / max(0.0001, EnvLightData_Get_blendDistanceNegative(lightData));
float3 positiveFalloff = positiveDistance / max(0.0001, EnvLightData_Get_blendDistancePositive(lightData));
// Fallof is the min for all faces
float influenceFalloff = min(

float alpha = saturate(influenceFalloff);
#else
float distFace = DistancePointBox(positionIS, -lightData.influenceExtents + lightData.blendDistancePositive.x, lightData.influenceExtents - lightData.blendDistancePositive.x);
float alpha = saturate(1.0 - distFace / max(lightData.blendDistancePositive.x, 0.0001));
float distFace = DistancePointBox(positionIS, -influenceExtents + lightData.blendDistancePositiveX, influenceExtents - lightData.blendDistancePositiveX);
float alpha = saturate(1.0 - distFace / max(lightData.blendDistancePositiveX, 0.0001));
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, EnvLightData_Get_blendNormalDistancePositive(lightData));
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, EnvLightData_Get_blendNormalDistanceNegative(lightData));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - EnvLightData_Get_capturePositionWS(lightData)));
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) * lightData.boxSideFadePositive) + saturate((-4 * dirIS - 1) * lightData.boxSideFadeNegative);
float3 faceFade = saturate((4 * dirIS - 1) * EnvLightData_Get_boxSideFadePositive(lightData))
+ saturate((-4 * dirIS - 1) * EnvLightData_Get_boxSideFadeNegative(lightData));
alpha *= saturate(faceFade.x + faceFade.y + faceFade.z);
#endif

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

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


IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
int influenceShapeType, int projectionShapeType, int GPUImageBasedLightingType,
int influenceShapeType, int GPUImageBasedLightingType,
inout float hierarchyWeight)
{
IndirectLighting lighting;

float projectionDistance = 0;
// 1. First process the projection
// Note: using influenceShapeType and projectionShapeType instead of (lightData|proxyData).shapeType allow to make compiler optimization in case the type is know (like for sky)
if (projectionShapeType == ENVSHAPETYPE_SPHERE)
if (influenceShapeType == ENVSHAPETYPE_SPHERE)
R = (positionWS + projectionDistance * R) - lightData.capturePositionWS;
float3 capturePositionWS = EnvLightData_Get_capturePositionWS(lightData);
R = (positionWS + projectionDistance * R) - capturePositionWS;
// Test again for clear coat
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION && HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))

coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
coatR = (positionWS + projectionDistance * coatR) - capturePositionWS;
else if (projectionShapeType == ENVSHAPETYPE_BOX)
else if (influenceShapeType == ENVSHAPETYPE_BOX)
R = (positionWS + projectionDistance * R) - lightData.capturePositionWS;
float3 capturePositionWS = EnvLightData_Get_capturePositionWS(lightData);
R = (positionWS + projectionDistance * R) - capturePositionWS;
// TODO: add distance based roughness

dirPS = mul(coatR, worldToPS);
projectionDistance = IntersectBoxProxy(lightData, dirPS, positionPS);
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
coatR = (positionWS + projectionDistance * coatR) - capturePositionWS;
}
weight = InfluenceBoxWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
}

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

正在加载...
取消
保存