Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The version number for this package has increased due to a version update of a r
- Standardized naming for the option regarding Transparent objects being able to receive Screen Space Reflections.
- Making the reflection and refractions of cubemaps distance based.
- Changed Receive SSR to also controls Receive SSGI on opaque objects.
- Improved the punctual light shadow rescale algorithm.

## [10.1.0] - 2020-10-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ internal int GetResolutionFromSettings(ShadowMapType shadowMapType, HDShadowInit
}
}

internal void ReserveShadowMap(Camera camera, HDShadowManager shadowManager, HDShadowSettings shadowSettings, HDShadowInitParameters initParameters, Rect screenRect, HDLightType lightType)
internal void ReserveShadowMap(Camera camera, HDShadowManager shadowManager, HDShadowSettings shadowSettings, HDShadowInitParameters initParameters, VisibleLight visibleLight, HDLightType lightType)
{
if (!m_WillRenderShadowMap)
return;
Expand Down Expand Up @@ -2013,14 +2013,26 @@ internal void ReserveShadowMap(Camera camera, HDShadowManager shadowManager, HDS

if (viewPortRescaling && !shadowIsInCacheSystem)
{
// resize viewport size by the normalized size of the light on screen
float screenArea = screenRect.width * screenRect.height;
viewportSize *= Mathf.Lerp(64f / viewportSize.x, 1f, screenArea);
viewportSize = Vector2.Max(new Vector2(64f, 64f) / viewportSize, viewportSize);
// Formulas: https://www.desmos.com/calculator/tdodbuysut f(x) is the distance between 0 and 1, g(x) is the screen ratio (oscillating to simulate different light sizes)
// The idea is to have a lot of resolution when the camera is close to the light OR the screen area is high.

// linear normalized distance between the light and camera with max shadow distance
float distance01 = Mathf.Clamp01(Vector3.Distance(camera.transform.position, visibleLight.GetPosition()) / shadowSettings.maxShadowDistance.value);
// ease out and invert the curve, give more importance to closer distances
distance01 = 1.0f - Mathf.Pow(distance01, 2);

// normalized ratio between light range and distance
float range01 = Mathf.Clamp01(visibleLight.range / Vector3.Distance(camera.transform.position, visibleLight.GetPosition()));

// Prevent flickering caused by the floating size of the viewport
viewportSize.x = Mathf.Round(viewportSize.x);
viewportSize.y = Mathf.Round(viewportSize.y);
float scaleFactor01 = Mathf.Max(distance01, range01);

// We allow a maximum of 64 rescale between the highest and lowest shadow resolution
// It prevent having too many resolution changes when the player is moving.
const float maxRescaleSteps = 64;
scaleFactor01 = Mathf.RoundToInt(scaleFactor01 * maxRescaleSteps) / maxRescaleSteps;

// resize viewport size by the normalized size of the light on screen
viewportSize = Vector2.Lerp(HDShadowManager.k_MinShadowMapResolution * Vector2.one, viewportSize, scaleFactor01);
}

viewportSize = Vector2.Max(viewportSize, new Vector2(HDShadowManager.k_MinShadowMapResolution, HDShadowManager.k_MinShadowMapResolution));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ int PreprocessVisibleLights(HDCamera hdCamera, CullingResults cullResults, Debug
// Reserve shadow map resolutions and check if light needs to render shadows
if (additionalData.WillRenderShadowMap())
{
additionalData.ReserveShadowMap(hdCamera.camera, m_ShadowManager, hdShadowSettings, m_ShadowInitParameters, light.screenRect, lightType);
additionalData.ReserveShadowMap(hdCamera.camera, m_ShadowManager, hdShadowSettings, m_ShadowInitParameters, light, lightType);
}

// Reserve the cookie resolution in the 2D atlas
Expand Down