浏览代码

[PlanarProbe] (wip) packing envlightdata structure

/main
Frédéric Vauchelles 7 年前
当前提交
4ad995e4
共有 5 个文件被更改,包括 299 次插入56 次删除
  1. 244
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  2. 60
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.custom.hlsl
  3. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  4. 40
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  5. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

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


[GenerateHLSL]
public struct EnvLightData
{
public Vector3 capturePositionWS;
// Packing order depends on chronological access to avoid cache misses
// Proxy properties
public float capturePositionWSX;
public float capturePositionWSY;
public float capturePositionWSZ;
public Vector3 influencePositionWS;
public int envIndex;
// Box: extents = box extents
// Sphere: extents.x = sphere radius
public float proxyExtentsX;
public float proxyExtentsY;
public float proxyExtentsZ;
// User can chose if they use This is use in case we want to force infinite projection distance (i.e no projection);
public float minProjectionDistance;
public Vector3 influenceForward;
public float proxyPositionWSX;
public float proxyPositionWSY;
public float proxyPositionWSZ;
public Vector3 influenceUp;
public Vector3 influenceRight;
public Vector3 influenceExtents; // extents of the env light
public float dimmer;
public Vector3 blendDistancePositive; //+X,+Y,+Z
public Vector3 blendDistanceNegative; //-X,-Y,-Z
public Vector3 blendNormalDistancePositive; //+X,+Y,+Z
public Vector3 blendNormalDistanceNegative; //-X,-Y,-Z
public Vector3 boxSideFadePositive; //+X,+Y,+Z
public Vector3 boxSideFadeNegative; //-X,-Y,-Z
public Vector3 sampleDirectionDiscardWS;
// User can chose if they use This is use in case we want to force infinite projection distance (i.e no projection);
public float minProjectionDistance;
// Influence properties
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 proxyPositionWS;
public EnvShapeType proxyShapeType;
public float influenceExtentsX;
public float influenceExtentsY;
public float influenceExtentsZ;
public float unused00;
// Box: extents = box extents
// Sphere: extents.x = sphere radius
public Vector3 proxyExtents;
public int unused14;
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 float boxSideFadePositiveX;
public float boxSideFadePositiveY;
public float boxSideFadePositiveZ;
public float boxSideFadeNegativeX;
public float boxSideFadeNegativeY;
public float boxSideFadeNegativeZ;
public float dimmer;
public float unused01;
public float sampleDirectionDiscardWSX;
public float sampleDirectionDiscardWSY;
public float sampleDirectionDiscardWSZ;
// Sampling properties
public int envIndex;
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); }

proxyForwardZ = value.z;
}
}
public Vector3 proxyUp
{
get { return new Vector3(proxyUpX, proxyUpY, proxyUpZ); }

proxyUpZ = value.z;
}
}
public Vector3 proxyRight
{
get { return new Vector3(proxyRightX, proxyRightY, proxyRightZ); }

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;
}
}
};

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


// Packing accessors
//-----------------------------------------------------------------------------
float3 EnvLightData_GetCapturePositionWS(EnvLightData lightData)
{
return float3(lightData.capturePositionWSX, lightData.capturePositionWSY, lightData.capturePositionWSZ);
}
float3 EnvLightData_GetProxyPositionWS(EnvLightData lightData)
{
return float3(lightData.proxyPositionWSX, lightData.proxyPositionWSY, lightData.proxyPositionWSZ);
}
float3 EnvLightData_GetProxyForward(EnvLightData lightData)
{
return float3(lightData.proxyForwardX, lightData.proxyForwardY, lightData.proxyForwardZ);

float3 EnvLightData_GetProxyRight(EnvLightData lightData)
{
return float3(lightData.proxyRightX, lightData.proxyRightY, lightData.proxyRightZ);
}
float3 EnvLightData_GetProxyExtents(EnvLightData lightData)
{
return float3(lightData.proxyExtentsX, lightData.proxyExtentsY, lightData.proxyExtentsZ);
}
float3 EnvLightData_GetInfluencePositionWS(EnvLightData lightData)
{
return float3(lightData.influencePositionWSX, lightData.influencePositionWSY, lightData.influencePositionWSZ);
}
float3 EnvLightData_GetInfluenceForward(EnvLightData lightData)
{
return float3(lightData.influenceForwardX, lightData.influenceForwardY, lightData.influenceForwardZ);
}
float3 EnvLightData_GetInfluenceUp(EnvLightData lightData)
{
return float3(lightData.influenceUpX, lightData.influenceUpY, lightData.influenceUpZ);
}
float3 EnvLightData_GetInfluenceRight(EnvLightData lightData)
{
return float3(lightData.influenceRightX, lightData.influenceRightY, lightData.influenceRightZ);
}
float3 EnvLightData_GetInfluenceExtents(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.influenceExtentsY, lightData.influenceExtentsZ);
}
float3 EnvLightData_GetBlendDistancePositive(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendDistancePositiveY, lightData.blendDistancePositiveZ);
}
float3 EnvLightData_GetBlendDistanceNegative(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendDistanceNegativeY, lightData.blendDistanceNegativeZ);
}
float3 EnvLightData_GetBlendNormalDistancePositive(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendNormalDistancePositiveY, lightData.blendNormalDistancePositiveZ);
}
float3 EnvLightData_GetBlendNormalDistanceNegative(EnvLightData lightData)
{
return float3(lightData.influenceExtentsX, lightData.blendNormalDistanceNegativeY, lightData.blendNormalDistanceNegativeZ);
}
#endif

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


envLightData.proxyUp = proxyToWorld.GetColumn(1).normalized;
envLightData.proxyForward = proxyToWorld.GetColumn(2).normalized;
envLightData.proxyPositionWS = proxyToWorld.GetColumn(3);
envLightData.proxyShapeType = probe.proxyShapeType;
m_lightList.envLights.Add(envLightData);

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


// This code will be inlined as lightLoopContext is hardcoded in the light loop
if (lightLoopContext.sampleReflection == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
{
if (cacheType == ENVCACHETYPE_TEXTURE2D)
{
//_Env2DCaptureVP is in capture space
float4 ndc = ComputeClipSpaceCoordinates(texCoord, _Env2DCaptureVP[index]);
ndc *= rcp(ndc.w);
ndc.xy = ndc.xy * 0.5 + 0.5;
float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc.xy, index, 0);
color.a = any(ndc.xyz < 0) || any(ndc.xyz > 1) ? 0 : 1;
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_ENVIRONMENT_PROXY_VOLUME)
return ApplyDebugProjectionVolume(color, texCoord, _DebugEnvironmentProxyDepthScale);
#endif
/*return float4(
(ndc.xyz > 0.5) * 0.5 + color.rgb * 0.5,
color.a);*/
return color;
}
else if (cacheType == ENVCACHETYPE_CUBEMAP)
// if (cacheType == ENVCACHETYPE_TEXTURE2D)
// {
// //_Env2DCaptureVP is in capture space
// float4 ndc = ComputeClipSpaceCoordinates(texCoord, _Env2DCaptureVP[index]);
// ndc *= rcp(ndc.w);
// ndc.xy = ndc.xy * 0.5 + 0.5;
//
// float4 color = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc.xy, index, 0);
// color.a = any(ndc.xyz < 0) || any(ndc.xyz > 1) ? 0 : 1;
//
//#ifdef DEBUG_DISPLAY
// if (_DebugLightingMode == DEBUGLIGHTINGMODE_ENVIRONMENT_PROXY_VOLUME)
// return ApplyDebugProjectionVolume(color, texCoord, _DebugEnvironmentProxyDepthScale);
//#endif
// /*return float4(
// (ndc.xyz > 0.5) * 0.5 + color.rgb * 0.5,
// color.a);*/
// return color;
// }
//else if (cacheType == ENVCACHETYPE_CUBEMAP)
{
float4 color = SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_EnvCubemapTextures, s_trilinear_clamp_sampler, texCoord, index, lod);
color.a = 1;

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


projectionDistance = IntersectSphereProxy(lightData, dirPS, positionPS);
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
}
weight = InfluenceSphereWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
}
else if (projectionShapeType == ENVSHAPETYPE_BOX)
{

projectionDistance = IntersectBoxProxy(lightData, dirPS, positionPS);
coatR = (positionWS + projectionDistance * coatR) - lightData.capturePositionWS;
}
weight = InfluenceBoxWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
if (influenceShapeType == ENVSHAPETYPE_SPHERE)
weight = InfluenceSphereWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
else if (influenceShapeType == ENVSHAPETYPE_BOX)
weight = InfluenceBoxWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
//if (influenceShapeType == ENVSHAPETYPE_SPHERE)
// weight = InfluenceSphereWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
//else if (influenceShapeType == ENVSHAPETYPE_BOX)
// weight = InfluenceBoxWeight(lightData, bsdfData, positionWS, positionIS, dirIS);
// When we are rough, we tend to see outward shifting of the reflection when at the boundary of the projection volume
// Also it appear like more sharp. To avoid these artifact and at the same time get better match to reference we lerp to original unmodified reflection.

正在加载...
取消
保存