浏览代码

[PlanarReflection] fixes

/main
Frédéric Vauchelles 7 年前
当前提交
c813f01f
共有 4 个文件被更改,包括 17 次插入30 次删除
  1. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/CameraUtils.cs
  2. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs
  4. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/CameraUtils.cs


return CalculateReflectionMatrix(Plane(position, normal));
}
public static Matrix4x4 CalculateWorldToCameraMatrixMirror(Matrix4x4 worldToCamera, Matrix4x4 reflection)
{
return worldToCamera * reflection;
}
public static Matrix4x4 CalculateReflectionMatrix(Vector4 plane)
{
var reflectionMat = new Matrix4x4();

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


}
}
static Matrix4x4 GetFlipMatrix()
static Matrix4x4 WorldToCamera(Camera camera)
Matrix4x4 flip = Matrix4x4.identity;
bool isLeftHand = ((int)LightDefinitions.s_UseLeftHandCameraSpace) != 0;
if (isLeftHand) flip.SetColumn(2, new Vector4(0.0f, 0.0f, -1.0f, 0.0f));
return flip;
return IsRHS(camera.worldToCameraMatrix)
? camera.worldToCameraMatrix
: Matrix4x4.Scale(new Vector3(1, 1, -1)) * camera.worldToCameraMatrix;
static Matrix4x4 WorldToCamera(Camera camera)
static Matrix4x4 CameraProjection(Camera camera)
return GetFlipMatrix() * camera.worldToCameraMatrix;
return IsRHS(camera.worldToCameraMatrix)
? camera.projectionMatrix
: camera.projectionMatrix * Matrix4x4.Scale(new Vector3(1, 1, -1));
static Matrix4x4 CameraProjection(Camera camera)
static bool IsRHS(Matrix4x4 mat)
return camera.projectionMatrix * GetFlipMatrix();
return Vector3.Dot(Vector3.Cross(mat.GetColumn(0), mat.GetColumn(1)), mat.GetColumn(2)) > 0;
}
public Vector3 GetLightColor(VisibleLight light)

if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
cmd.SetGlobalInt(HDShaderIDs._isCullingInverted, GL.invertCulling ? 1 : 0);
// Cluster
{

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs


nearClipPlane = viewerCamera.nearClipPlane;
farClipPlane = viewerCamera.farClipPlane;
aspect = 1;
fov = viewerCamera.fieldOfView;
fov = Mathf.Max(viewerCamera.fieldOfView, viewerCamera.fieldOfView * viewerCamera.aspect);
worldToCamera = CameraUtils.CalculateWorldToCameraMatrixMirror(worldToCapture, reflectionMatrix);
worldToCamera = worldToCapture * reflectionMatrix;
var clipPlane = CameraUtils.CameraSpacePlane(worldToCamera, probe.captureMirrorPlanePosition, probe.captureMirrorPlaneNormal);
var sourceProj = Matrix4x4.Perspective(fov, aspect, nearClipPlane, farClipPlane);

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


else if (influenceShapeType == ENVSHAPETYPE_BOX)
weight = InfluenceBoxWeight(lightData, bsdfData, positionWS, positionLS, dirLS);
// 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.
// Formula is empirical.

float iblMipLevel = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness);
float sampleWeight = 1;
float3 texCoord = GetSampleEnvCoordinates(lightLoopContext, lightData.envIndex, R, iblMipLevel, sampleWeight);
//weight *= sampleWeight;
uint index = lightData.envIndex >> 1;
float2 positionNCD = ComputeNormalizedDeviceCoordinates(positionWS, _Env2DCaptureVP[index]);
//float2 positionNCD = ComputeNormalizedDeviceCoordinates(_Env2DCapturePositionWS[index] + R, _Env2DCaptureVP[index]);
texCoord = positionNCD.xyy;
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, texCoord, iblMipLevel);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, iblMipLevel, sampleWeight);
weight *= sampleWeight;
// Smooth weighting
weight = Smoothstep01(weight);

envLighting *= Sq(1.0 - preLightData.coatIblF);
// Evaluate the Clear Coat color
texCoord = GetSampleEnvCoordinates(lightLoopContext, lightData.envIndex, coatR, 0.0, sampleWeight);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, texCoord, 0.0);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, sampleWeight);
envLighting += preLightData.coatIblF * preLD.rgb;
// Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF

正在加载...
取消
保存