Skip to content

PBR Sky renderer now shares its internal precomputation table between different instances. #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 14, 2020
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
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 @@ -596,6 +596,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed shader graphs not casting semi-transparent and color shadows (case 1242617)
- Fixed thin refraction mode not working properly.
- Fixed assert on tests caused by probe culling results being requested when culling did not happen. (case 1246169)
- Fixed over consumption of GPU memory by the Physically Based Sky.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class NewSky : SkySettings
}
return hash;
}

public override int GetHashCode(Camera camera)
{
// Implement if your sky depends on the camera settings (like position for instance)
return GetHashCode();
}
}

```
Expand Down Expand Up @@ -159,6 +165,10 @@ class NewSkyRenderer : SkyRenderer
}

```
### Important note:
If your sky renderer has to manage heavy data (like precomputed textures or similar things) then particular care has to be taken. Indeed, one instance of the renderer will exist per camera so by default if this data is a member of the renderer, it willl also be duplicated in memory.
Since each sky renderer can have very different needs, the responsbility to share this kind of data is the renderer's and need to be implemented by the user.

<a name="RenderingShader"></a>

## Sky rendering Shader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Experimental.Rendering;
Expand All @@ -17,6 +18,7 @@ namespace UnityEngine.Rendering.HighDefinition
/// HDCamera class.
/// This class holds all information for a given camera. Constants used for shading as well as buffers persistent from one frame to another etc.
/// </summary>
[DebuggerDisplay("({camera.name})")]
public class HDCamera
{
#region Public API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,6 @@ internal int GetPrecomputationHashCode()
unchecked
{
#if UNITY_2019_3 // In 2019.3, when we call GetHashCode on a VolumeParameter it generate garbage (due to the boxing of the generic parameter)
// These parameters affect precomputation.
hash = hash * 23 + earthPreset.value.GetHashCode();
hash = hash * 23 + planetaryRadius.value.GetHashCode();
hash = hash * 23 + groundTint.value.GetHashCode();

hash = hash * 23 + airMaximumAltitude.value.GetHashCode();
hash = hash * 23 + airDensityR.value.GetHashCode();
hash = hash * 23 + airDensityG.value.GetHashCode();
hash = hash * 23 + airDensityB.value.GetHashCode();
hash = hash * 23 + airTint.value.GetHashCode();

hash = hash * 23 + aerosolMaximumAltitude.value.GetHashCode();
hash = hash * 23 + aerosolDensity.value.GetHashCode();
hash = hash * 23 + aerosolTint.value.GetHashCode();
hash = hash * 23 + aerosolAnisotropy.value.GetHashCode();

hash = hash * 23 + numberOfBounces.value.GetHashCode();

// These parameters affect precomputation.
hash = hash * 23 + earthPreset.overrideState.GetHashCode();
hash = hash * 23 + planetaryRadius.overrideState.GetHashCode();
Expand Down Expand Up @@ -376,32 +358,6 @@ public override int GetHashCode()
{
#if UNITY_2019_3 // In 2019.3, when we call GetHashCode on a VolumeParameter it generate garbage (due to the boxing of the generic parameter)
// These parameters do NOT affect precomputation.
hash = hash * 23 + sphericalMode.value.GetHashCode();
hash = hash * 23 + seaLevel.value.GetHashCode();
hash = hash * 23 + planetCenterPosition.value.GetHashCode();
hash = hash * 23 + planetRotation.value.GetHashCode();

if (groundColorTexture.value != null)
hash = hash * 23 + groundColorTexture.value.GetHashCode();

if (groundEmissionTexture.value != null)
hash = hash * 23 + groundEmissionTexture.value.GetHashCode();

hash = hash * 23 + groundEmissionMultiplier.value.GetHashCode();

hash = hash * 23 + spaceRotation.value.GetHashCode();

if (spaceEmissionTexture.value != null)
hash = hash * 23 + spaceEmissionTexture.value.GetHashCode();

hash = hash * 23 + spaceEmissionMultiplier.value.GetHashCode();
hash = hash * 23 + colorSaturation.value.GetHashCode();
hash = hash * 23 + alphaSaturation.value.GetHashCode();
hash = hash * 23 + alphaMultiplier.value.GetHashCode();
hash = hash * 23 + horizonTint.value.GetHashCode();
hash = hash * 23 + zenithTint.value.GetHashCode();
hash = hash * 23 + horizonZenithShift.value.GetHashCode();

hash = hash * 23 + sphericalMode.overrideState.GetHashCode();
hash = hash * 23 + seaLevel.overrideState.GetHashCode();
hash = hash * 23 + planetCenterPosition.overrideState.GetHashCode();
Expand Down
Loading