Skip to content

Have the PBR Sky not render black when below horizon #1116

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 2 commits into from
Jul 3, 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
3 changes: 2 additions & 1 deletion com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changelog
# Changelog
All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
Expand Down Expand Up @@ -866,6 +866,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added missing tooltips and improved the UI of the aperture control (case 1254916).
- Fixed wrong tooltips in the Dof Volume (case 1256641).
- The `CustomPassLoadCameraColor` and `CustomPassSampleCameraColor` functions now returns the correct color buffer when used in after post process instead of the color pyramid (which didn't had post processes).
- PBR Sky now doesn't go black when going below sea level, but it instead freezes calculation as if on the horizon.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo
var pbrSky = builtinParams.skySettings as PhysicallyBasedSky;

// TODO: the following expression is somewhat inefficient, but good enough for now.
Vector3 X = builtinParams.worldSpaceCameraPos;
float r = Vector3.Distance(X, pbrSky.GetPlanetCenterPosition(X));
float R = pbrSky.GetPlanetaryRadius();
Vector3 cameraPos = builtinParams.worldSpaceCameraPos;
Vector3 planetCenter = pbrSky.GetPlanetCenterPosition(cameraPos);
float R = pbrSky.GetPlanetaryRadius();

bool isPbrSkyActive = r > R; // Disable sky rendering below the ground
Vector3 cameraToPlanetCenter = planetCenter - cameraPos;
float r = cameraToPlanetCenter.magnitude;
cameraPos = planetCenter - Mathf.Max(R, r) * cameraToPlanetCenter.normalized;

CommandBuffer cmd = builtinParams.commandBuffer;

Expand All @@ -461,7 +463,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo
pbrSky.spaceRotation.value.z);

s_PbrSkyMaterialProperties.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
s_PbrSkyMaterialProperties.SetVector(HDShaderIDs._WorldSpaceCameraPos1, builtinParams.worldSpaceCameraPos);
s_PbrSkyMaterialProperties.SetVector(HDShaderIDs._WorldSpaceCameraPos1, cameraPos);
s_PbrSkyMaterialProperties.SetMatrix(HDShaderIDs._ViewMatrix1, builtinParams.viewMatrix);
s_PbrSkyMaterialProperties.SetMatrix(HDShaderIDs._PlanetRotation, Matrix4x4.Rotate(planetRotation));
s_PbrSkyMaterialProperties.SetMatrix(HDShaderIDs._SpaceRotation, Matrix4x4.Rotate(spaceRotation));
Expand Down Expand Up @@ -499,7 +501,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo

s_PbrSkyMaterialProperties.SetInt(HDShaderIDs._RenderSunDisk, renderSunDisk ? 1 : 0);

int pass = (renderForCubemap ? 0 : 2) + (isPbrSkyActive ? 0 : 1);
int pass = (renderForCubemap ? 0 : 2);

CloudLayer.Apply(builtinParams.cloudLayer, m_PbrSkyMaterial);

Expand Down