浏览代码

Merge pull request #1611 from Unity-Technologies/renaming-camerae-relative

HDRP: More renaming for camera relative rendering
/main
GitHub 6 年前
当前提交
79ec2054
共有 13 个文件被更改,包括 89 次插入362 次删除
  1. 18
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs
  2. 254
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl
  3. 16
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  4. 36
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  5. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  6. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/VolumeProjection.hlsl
  7. 14
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  8. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  9. 28
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl
  10. 20
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  11. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitReference.hlsl
  12. 46
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl
  13. 1
      com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs.hlsl

18
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs


};
// These structures share between C# and hlsl need to be align on float4, so we pad them.
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public Vector3 positionWS;
public Vector3 positionRWS;
public Vector3 color;
public int cookieIndex; // -1 if unused
public float volumetricDimmer;

public float specularScale;
};
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public Vector3 positionWS;
public Vector3 positionRWS;
public Vector3 color;
public float rangeAttenuationScale;
public float rangeAttenuationBias;

public float shadowDimmer;
public Vector4 shadowMaskSelector; // Use with ShadowMask feature
public int nonLightmappedOnly; // Use with ShadowMask feature // TODO: make it a bool
public int nonLightmappedOnly; // Use with ShadowMask feature // TODO: make it a bool
public float minRoughness; // This is use to give a small "area" to punctual light, as if we have a light with a radius.
public float diffuseScale;
public float specularScale;

// It allow to have more coherence for the dynamic if in shader code.
// Users can also chose to not have any projection, in this case we use the property minProjectionDistance to minimize code change. minProjectionDistance is set to huge number
// that simulate effect of no shape projection
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public Vector3 capturePositionWS;
public Vector3 capturePositionRWS;
public EnvShapeType influenceShapeType;
// Box: extents = box extents

public float minProjectionDistance;
public Vector3 proxyPositionWS;
public Vector3 proxyPositionRWS;
public Vector3 influencePositionWS;
public Vector3 influencePositionRWS;
public Vector3 influenceForward;
public Vector3 influenceUp;
public Vector3 influenceRight;

254
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl


// PackingRules = Exact
struct DirectionalLightData
{
float3 positionWS;
float3 positionRWS;
float3 color;
int cookieIndex;
float volumetricDimmer;

// PackingRules = Exact
struct LightData
{
float3 positionWS;
float3 positionRWS;
float3 color;
float rangeAttenuationScale;
float rangeAttenuationBias;

// PackingRules = Exact
struct EnvLightData
{
float3 capturePositionWS;
float3 capturePositionRWS;
float3 proxyPositionWS;
float3 proxyPositionRWS;
float3 influencePositionWS;
float3 influencePositionRWS;
float3 influenceForward;
float3 influenceUp;
float3 influenceRight;

float multiplier;
int envIndex;
};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DirectionalLightData
//
float3 GetPositionWS(DirectionalLightData value)
{
return value.positionWS;
}
float3 GetColor(DirectionalLightData value)
{
return value.color;
}
int GetCookieIndex(DirectionalLightData value)
{
return value.cookieIndex;
}
float GetVolumetricDimmer(DirectionalLightData value)
{
return value.volumetricDimmer;
}
float3 GetRight(DirectionalLightData value)
{
return value.right;
}
float3 GetUp(DirectionalLightData value)
{
return value.up;
}
float3 GetForward(DirectionalLightData value)
{
return value.forward;
}
int GetTileCookie(DirectionalLightData value)
{
return value.tileCookie;
}
int GetShadowIndex(DirectionalLightData value)
{
return value.shadowIndex;
}
int GetContactShadowIndex(DirectionalLightData value)
{
return value.contactShadowIndex;
}
float4 GetShadowMaskSelector(DirectionalLightData value)
{
return value.shadowMaskSelector;
}
int GetNonLightmappedOnly(DirectionalLightData value)
{
return value.nonLightmappedOnly;
}
float GetDiffuseScale(DirectionalLightData value)
{
return value.diffuseScale;
}
float GetSpecularScale(DirectionalLightData value)
{
return value.specularScale;
}
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.LightData
//
float3 GetPositionWS(LightData value)
{
return value.positionWS;
}
float3 GetColor(LightData value)
{
return value.color;
}
float GetRangeAttenuationScale(LightData value)
{
return value.rangeAttenuationScale;
}
float GetRangeAttenuationBias(LightData value)
{
return value.rangeAttenuationBias;
}
float GetAngleScale(LightData value)
{
return value.angleScale;
}
float GetAngleOffset(LightData value)
{
return value.angleOffset;
}
int GetCookieIndex(LightData value)
{
return value.cookieIndex;
}
int GetLightType(LightData value)
{
return value.lightType;
}
float3 GetRight(LightData value)
{
return value.right;
}
float3 GetUp(LightData value)
{
return value.up;
}
float3 GetForward(LightData value)
{
return value.forward;
}
int GetShadowIndex(LightData value)
{
return value.shadowIndex;
}
int GetContactShadowIndex(LightData value)
{
return value.contactShadowIndex;
}
float GetShadowDimmer(LightData value)
{
return value.shadowDimmer;
}
float4 GetShadowMaskSelector(LightData value)
{
return value.shadowMaskSelector;
}
int GetNonLightmappedOnly(LightData value)
{
return value.nonLightmappedOnly;
}
float GetMinRoughness(LightData value)
{
return value.minRoughness;
}
float GetDiffuseScale(LightData value)
{
return value.diffuseScale;
}
float GetSpecularScale(LightData value)
{
return value.specularScale;
}
float2 GetSize(LightData value)
{
return value.size;
}
float GetVolumetricDimmer(LightData value)
{
return value.volumetricDimmer;
}
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float3 GetCapturePositionWS(EnvLightData value)
{
return value.capturePositionWS;
}
int GetInfluenceShapeType(EnvLightData value)
{
return value.influenceShapeType;
}
float3 GetProxyExtents(EnvLightData value)
{
return value.proxyExtents;
}
float GetMinProjectionDistance(EnvLightData value)
{
return value.minProjectionDistance;
}
float3 GetProxyPositionWS(EnvLightData value)
{
return value.proxyPositionWS;
}
float3 GetProxyForward(EnvLightData value)
{
return value.proxyForward;
}
float3 GetProxyUp(EnvLightData value)
{
return value.proxyUp;
}
float3 GetProxyRight(EnvLightData value)
{
return value.proxyRight;
}
float3 GetInfluencePositionWS(EnvLightData value)
{
return value.influencePositionWS;
}
float3 GetInfluenceForward(EnvLightData value)
{
return value.influenceForward;
}
float3 GetInfluenceUp(EnvLightData value)
{
return value.influenceUp;
}
float3 GetInfluenceRight(EnvLightData value)
{
return value.influenceRight;
}
float3 GetInfluenceExtents(EnvLightData value)
{
return value.influenceExtents;
}
float GetUnused00(EnvLightData value)
{
return value.unused00;
}
float3 GetBlendDistancePositive(EnvLightData value)
{
return value.blendDistancePositive;
}
float3 GetBlendDistanceNegative(EnvLightData value)
{
return value.blendDistanceNegative;
}
float3 GetBlendNormalDistancePositive(EnvLightData value)
{
return value.blendNormalDistancePositive;
}
float3 GetBlendNormalDistanceNegative(EnvLightData value)
{
return value.blendNormalDistanceNegative;
}
float3 GetBoxSideFadePositive(EnvLightData value)
{
return value.boxSideFadePositive;
}
float3 GetBoxSideFadeNegative(EnvLightData value)
{
return value.boxSideFadeNegative;
}
float GetWeight(EnvLightData value)
{
return value.weight;
}
float GetMultiplier(EnvLightData value)
{
return value.multiplier;
}
int GetEnvIndex(EnvLightData value)
{
return value.envIndex;
}
#endif

16
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


UNITY_BRANCH if (lightData.cookieIndex >= 0)
{
float3 lightToSample = positionWS - lightData.positionWS;
float3 lightToSample = positionWS - lightData.positionRWS;
float3 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample);
color *= cookie;

// Return L vector for punctual light (normalize surface to light), lightToSample (light to surface non normalize) and distances {d, d^2, 1/d, d_proj}
void GetPunctualLightVectors(float3 positionWS, LightData lightData, out float3 L, out float3 lightToSample, out float4 distances)
{
lightToSample = positionWS - lightData.positionWS;
lightToSample = positionWS - lightData.positionRWS;
int lightType = lightData.lightType;
distances.w = dot(lightToSample, lightData.forward);

if (influenceShapeType == ENVSHAPETYPE_SPHERE)
{
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 = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionRWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionRWS;
weight = InfluenceSphereWeight(lightData, normalWS, positionWS, positionIS, dirIS);
}

// 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 = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionRWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionRWS;
weight = InfluenceBoxWeight(lightData, normalWS, positionWS, positionIS, dirIS);
}

// Compute the distance from the light to the back face of the object along the light direction.
float distBackFaceToLight = GetPunctualShadowClosestDistance( lightLoopContext.shadowContext, s_linear_clamp_sampler,
posInput.positionWS, lightData.shadowIndex, L, lightData.positionWS);
posInput.positionWS, lightData.shadowIndex, L, lightData.positionRWS);
// Our subsurface scattering models use the semi-infinite planar slab assumption.
// Therefore, we need to find the thickness along the normal.

36
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


// Rescale for cookies and windowing.
directionalLightData.right = light.light.transform.right * 2 / Mathf.Max(additionalData.shapeWidth, 0.001f);
directionalLightData.up = light.light.transform.up * 2 / Mathf.Max(additionalData.shapeHeight, 0.001f);
directionalLightData.positionWS = light.light.transform.position;
directionalLightData.positionRWS = light.light.transform.position;
directionalLightData.color = GetLightColor(light);
// Caution: This is bad but if additionalData == HDUtils.s_DefaultHDAdditionalLightData it mean we are trying to promote legacy lights, which is the case for the preview for example, so we need to multiply by PI as legacy Unity do implicit divide by PI for direct intensity.

lightData.lightType = gpuLightType;
lightData.positionWS = light.light.transform.position;
lightData.positionRWS = light.light.transform.position;
bool applyRangeAttenuation = additionalLightData.applyRangeAttenuation && (gpuLightType != GPULightType.ProjectorBox);

lightData.size = new Vector2(additionalLightData.shapeWidth, additionalLightData.shapeHeight);
}
float distanceToCamera = (lightData.positionWS - camera.transform.position).magnitude;
float distanceToCamera = (lightData.positionRWS - camera.transform.position).magnitude;
float distanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalLightData.fadeDistance);
float lightScale = additionalLightData.lightDimmer * distanceFade;

lightData.shadowMaskSelector.x = -1.0f;
lightData.nonLightmappedOnly = 0;
}
// Check if the current light is dominant and store it's index to change it's property later,
// as we can't know which one will be dominant before checking all the lights
GetDominantLightWithShadows(additionalshadowData, light, m_lightList.lights.Count -1);

// Then Culling side
var range = lightDimensions.z;
var lightToWorld = light.localToWorld;
Vector3 positionWS = lightData.positionWS;
Vector3 positionWS = lightData.positionRWS;
Vector3 positionVS = worldToView.MultiplyPoint(positionWS);
Matrix4x4 lightToView = worldToView * lightToWorld;

envLightData.influenceRight = influenceToWorld.GetColumn(0).normalized;
envLightData.influenceUp = influenceToWorld.GetColumn(1).normalized;
envLightData.influenceForward = influenceToWorld.GetColumn(2).normalized;
envLightData.capturePositionWS = capturePosition;
envLightData.influencePositionWS = influenceToWorld.GetColumn(3);
envLightData.capturePositionRWS = capturePosition;
envLightData.influencePositionRWS = influenceToWorld.GetColumn(3);
envLightData.envIndex = envIndex;

envLightData.proxyRight = proxyToWorld.GetColumn(0).normalized;
envLightData.proxyUp = proxyToWorld.GetColumn(1).normalized;
envLightData.proxyForward = proxyToWorld.GetColumn(2).normalized;
envLightData.proxyPositionWS = proxyToWorld.GetColumn(3);
envLightData.proxyPositionRWS = proxyToWorld.GetColumn(3);
m_lightList.envLights.Add(envLightData);
return true;

// Caution: 'DirectionalLightData.positionWS' is camera-relative after this point.
int last = m_lightList.directionalLights.Count - 1;
DirectionalLightData lightData = m_lightList.directionalLights[last];
lightData.positionWS -= camPosWS;
lightData.positionRWS -= camPosWS;
m_lightList.directionalLights[last] = lightData;
}
}

// Caution: 'LightData.positionWS' is camera-relative after this point.
int last = m_lightList.lights.Count - 1;
LightData lightData = m_lightList.lights[last];
lightData.positionWS -= camPosWS;
lightData.positionRWS -= camPosWS;
m_lightList.lights[last] = lightData;
}
}

// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
// Caution: 'EnvLightData.positionRWS' is camera-relative after this point.
envLightData.capturePositionWS -= camPosWS;
envLightData.influencePositionWS -= camPosWS;
envLightData.proxyPositionWS -= camPosWS;
envLightData.capturePositionRWS -= camPosWS;
envLightData.influencePositionRWS -= camPosWS;
envLightData.proxyPositionRWS -= camPosWS;
m_lightList.envLights[last] = envLightData;
}
}

cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.whiteTexture);
return;
}
using (new ProfilingSample(cmd, "Deferred Directional Shadow", CustomSamplerId.TPDeferredDirectionalShadow.GetSampler()))
{
Vector4 lightDirection = Vector4.zero;

}
else
kernel = s_deferredDirectionalShadowKernel;
// We use the .w component of the direction/position vectors to choose in the shader the
// light direction of the contact shadows (direction light direction or (pixel position - light position))
if (m_CurrentSunLight != null)

}
if (m_DominantLightIndex != -1)
{
lightPosition = m_DominantLightData.positionWS;
lightPosition = m_DominantLightData.positionRWS;
lightPosition.w = 1;
lightDirection.w = 0;
}

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


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.influencePositionRWS = float3(0.0, 0.0, 0.0);
output.weight = 1.0;
output.multiplier = 1.0;

8
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/VolumeProjection.hlsl


float3 WorldToProxyPosition(EnvLightData lightData, float3x3 worldToPS, float3 positionWS)
{
float3 positionPS = positionWS - lightData.proxyPositionWS;
float3 positionPS = positionWS - lightData.proxyPositionRWS;
positionPS = mul(positionPS, worldToPS).xyz;
return positionPS;
}

#if defined(ENVMAP_FEATURE_INFLUENCENORMAL)
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtents.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionRWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideInfluenceNormalVolume = all(belowPositiveInfluenceNormalVolume >= 1.0) && all(aboveNegativeInfluenceNormalVolume >= 1.0) ? 1.0 : 0;
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionRWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3 WorldToInfluencePosition(EnvLightData lightData, float3x3 worldToIS, float3 positionWS)
{
float3 positionIS = positionWS - lightData.influencePositionWS;
float3 positionIS = positionWS - lightData.influencePositionRWS;
positionIS = mul(positionIS, worldToIS).xyz;
return positionIS;
}

14
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute


float3 coneAxisY = lenMul * light.up;
sampleLight = IntersectRayCone(ray.originWS, ray.jitterDirWS,
light.positionWS, light.forward,
light.positionRWS, light.forward,
coneAxisX, coneAxisY,
t0, t1, tEntr, tExit);
}

float hackMinDistSq = Sq(dt * (0.5 / 7));
float t, distSq, rcpPdf;
ImportanceSamplePunctualLight(rndVal, light.positionWS,
ImportanceSamplePunctualLight(rndVal, light.positionRWS,
ray.originWS, ray.jitterDirWS,
tEntr, tExit, t, distSq, rcpPdf,
hackMinDistSq);

float3 lightToSample = posInput.positionWS - light.positionWS;
float3 lightToSample = posInput.positionWS - light.positionRWS;
float distRcp = rsqrt(distSq);
float dist = distSq * distRcp;
float distProj = dot(lightToSample, light.forward);

// and any temporal instability of anisotropy causes causes visible jitter.
// In order to stabilize the image, we use the voxel center for all
// anisotropy-related calculations.
float3 centerL = light.positionWS - centerWS;
float3 centerL = light.positionRWS - centerWS;
float cosTheta = dot(centerL, ray.centerDirWS) * rsqrt(dot(centerL, centerL));
float phase = CornetteShanksPhasePartVarying(anisotropy, cosTheta);

// 'light.right' and 'light.up' vectors are pre-scaled on the CPU by (2/w) and (2/h).
float3x3 rotMat = float3x3(light.right, light.up, light.forward);
float3 o = mul(rotMat, ray.originWS - light.positionWS);
float3 o = mul(rotMat, ray.originWS - light.positionRWS);
float3 d = mul(rotMat, ray.jitterDirWS);
float range = light.size.x;

posInput.positionWS = GetPointAtDistance(ray, t);
float3 L = -light.forward;
float3 lightToSample = posInput.positionWS - light.positionWS;
float3 lightToSample = posInput.positionWS - light.positionRWS;
float distProj = dot(lightToSample, light.forward);
float4 distances = float4(1, 1, 1, distProj);

// and any temporal instability of anisotropy causes causes visible jitter.
// In order to stabilize the image, we use the voxel center for all
// anisotropy-related calculations.
float3 centerL = light.positionWS - centerWS;
float3 centerL = light.positionRWS - centerWS;
float cosTheta = dot(centerL, ray.centerDirWS) * rsqrt(dot(centerL, centerL));
float phase = CornetteShanksPhasePartVarying(anisotropy, cosTheta);

4
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs


sRGBFlags = m_sRGBFlags;
}
}
// normal to world only uses 3x3 for actual matrix so some data is packed in the unused space
// blend:
// float decalBlend = decalData.normalToWorld[0][3];

// float2 uvScale = float2(decalData.normalToWorld[3][0], decalData.normalToWorld[3][1]);
// float2 uvBias = float2(decalData.normalToWorld[3][2], decalData.normalToWorld[3][3]);
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public struct DecalData
{
public Matrix4x4 worldToDecal;

28
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl


};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DecalData
//
float4x4 GetWorldToDecal(DecalData value)
{
return value.worldToDecal;
}
float4x4 GetNormalToWorld(DecalData value)
{
return value.normalToWorld;
}
float4 GetDiffuseScaleBias(DecalData value)
{
return value.diffuseScaleBias;
}
float4 GetNormalScaleBias(DecalData value)
{
return value.normalScaleBias;
}
float4 GetMaskScaleBias(DecalData value)
{
return value.maskScaleBias;
}
float4 GetBaseColor(DecalData value)
{
return value.baseColor;
}
//
// Debug functions
//
void GetGeneratedDecalSurfaceDataDebug(uint paramId, DecalSurfaceData decalsurfacedata, inout float3 result, inout bool needLinearToSRGB)

20
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


float len = lightData.size.x;
float3 T = lightData.right;
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
// Pick the major axis of the ellipsoid.
float3 axis = lightData.right;

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
float3 P1 = lightData.positionWS - T * (0.5 * len);
float3 P2 = lightData.positionWS + T * (0.5 * len);
float3 P1 = lightData.positionRWS - T * (0.5 * len);
float3 P2 = lightData.positionRWS + T * (0.5 * len);
// Rotate the endpoints into the local coordinate system.
P1 = mul(P1, transpose(preLightData.orthoBasisViewNormal));

IntegrateBSDF_AreaRef(V, positionWS, preLightData, lightData, bsdfData,
lighting.diffuse, lighting.specular);
#else
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
if (dot(lightData.forward, unL) >= 0.0001)
{

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
lightVerts[0] = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight;
lightVerts[0] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * halfHeight;
// Rotate the endpoints into the local coordinate system.
lightVerts = mul(lightVerts, transpose(preLightData.orthoBasisViewNormal));

4
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitReference.hlsl


const float len = lightData.size.x;
const float3 T = lightData.right;
const float3 P1 = lightData.positionWS - T * (0.5 * len);
const float3 P1 = lightData.positionRWS - T * (0.5 * len);
const float dt = len * rcp(sampleCount);
const float off = 0.5 * dt;

u = frac(u + randNum);
// Lights in Unity point backward.
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(-lightData.forward, 0.0), float4(lightData.positionWS, 1.0));
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(-lightData.forward, 0.0), float4(lightData.positionRWS, 1.0));
switch (lightData.lightType)
{

46
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl


float3 vLayerEnergyCoeff[NB_VLAYERS];
// TODOENERGY
// For now since FGD fetches aren't used in compute adding (instead we do non integrated
// Fresnel( ) evaluations and 1 - Fresnel( ) which is wrong, the former only ok for analytical
// lights for the top interface for R12), we will use these for FGD fetches but keep them
// For now since FGD fetches aren't used in compute adding (instead we do non integrated
// Fresnel( ) evaluations and 1 - Fresnel( ) which is wrong, the former only ok for analytical
// lights for the top interface for R12), we will use these for FGD fetches but keep them
// for BSDF( ) eval for analytical lights since the later don't use FGD terms.

//float topIor = bsdfData.coatIor;
// TODO:
// We will avoid using coatIor directly as with the fake refraction, it can cause TIR
// which even when handled in EvalIridescence (tested), doesn't look pleasing and
// which even when handled in EvalIridescence (tested), doesn't look pleasing and
// creates a discontinuity.
float scale = clamp((1.0-bsdfData.coatPerceptualRoughness), 0.0, 1.0);
float topIor = lerp(1.0001, bsdfData.coatIor, scale);

float theta[NB_NORMALS];
float2 uv[TOTAL_NB_LOBES];
// These 2 cases will generate the same code when no dual normal maps since COAT_NORMAL_IDX == BASE_NORMAL_IDX == 0,
// These 2 cases will generate the same code when no dual normal maps since COAT_NORMAL_IDX == BASE_NORMAL_IDX == 0,
// and one will be pruned out:
theta[COAT_NORMAL_IDX] = FastACosPos(NdotV[COAT_NORMAL_IDX]);
theta[BASE_NORMAL_IDX] = FastACosPos(NdotV[BASE_NORMAL_IDX]);

preLightData.TdotV = TdotV;
preLightData.BdotV = BdotV;
#endif
// perceptualRoughness is use as input and output here
float3 outNormal;
float outPerceptualRoughness;

if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_IRIDESCENCE))
{
float3 fresnelIridescent = preLightData.fresnelIridforCalculatingFGD;
#ifdef IRIDESCENCE_RECOMPUTE_PERLIGHT
float topIor = 1.0; // default air on top.
fresnelIridescent = EvalIridescence(topIor, savedLdotH, bsdfData.iridescenceThickness, bsdfData.fresnel0);

float NdotV = ClampNdotV(unclampedNdotV);
float LdotV = dot(L, V);
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
// TODOENERGYDIFFUSE:
// TODOENERGYDIFFUSE:
// but we would need to balance it with the term used from e_Ti0 == preLightData.diffuseEnergy, as
// but we would need to balance it with the term used from e_Ti0 == preLightData.diffuseEnergy, as
// If we use the same term, we could just apply it in the end to diffuse light since coat can't produce diffuse lighting,
// so diffuse lighting from the base interface should all have the term applied. (Then, we would need to make sure the
// If we use the same term, we could just apply it in the end to diffuse light since coat can't produce diffuse lighting,
// so diffuse lighting from the base interface should all have the term applied. (Then, we would need to make sure the
// energy term is separate from diffuseFGD.) But the terms are not the same:
//
// Even without energy conservation, preLightData.diffuseEnergyTransmitted should still != preLightData.diffuseEnergy

float len = lightData.size.x;
float3 T = lightData.right;
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
// Pick the major axis of the ellipsoid.
float3 axis = lightData.right;

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
float3 P1 = lightData.positionWS - T * (0.5 * len);
float3 P2 = lightData.positionWS + T * (0.5 * len);
float3 P1 = lightData.positionRWS - T * (0.5 * len);
float3 P2 = lightData.positionRWS + T * (0.5 * len);
// Rotate the endpoints into the local coordinate system.
float3 localP1 = mul(P1, transpose(preLightData.orthoBasisViewNormal[BASE_NORMAL_IDX]));

ltcValue *= lightData.diffuseScale;
// TODOENERGYDIFFUSE: In Lit with Lambert, there's no diffuseFGD, it is one. In our case, we also
// need a diffuse energy term when vlayered. See preLightData.diffuseEnergyTransmitted
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
lighting.diffuse += bsdfData.transmittance * ltcValue;

IntegrateBSDF_AreaRef(V, positionWS, preLightData, lightData, bsdfData,
lighting.diffuse, lighting.specular);
#else
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
if (dot(lightData.forward, unL) >= 0.0001)
{

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
lightVerts[0] = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight;
lightVerts[0] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * halfHeight;
// Rotate the endpoints into the local coordinate system.
float4x3 localLightVerts = mul(lightVerts, transpose(preLightData.orthoBasisViewNormal[BASE_NORMAL_IDX]));

1
com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs.hlsl


#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)
#define SHADEROPTIONS_USE_DISNEY_SSS (1)
#endif
正在加载...
取消
保存