Skip to content

Pbr sky fixes metal #911

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 6 commits into from
Jun 15, 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
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.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void EvaluatePbrAtmosphere(float3 worldSpaceCameraPos, float3 V, float distAlong

// TODO: Not sure it's possible to precompute cam rel pos since variables
// in the two constant buffers may be set at a different frequency?
const float3 O = worldSpaceCameraPos - _PlanetCenterPosition;
const float3 O = worldSpaceCameraPos - _PlanetCenterPosition.xyz;
const float tFrag = abs(distAlongRay); // Clear the "hit ground" flag

float3 N; float r; // These params correspond to the entry point
Expand Down Expand Up @@ -115,7 +115,7 @@ void EvaluatePbrAtmosphere(float3 worldSpaceCameraPos, float3 V, float distAlong
// We may have swapped X and Y.
float2 ch = abs(ch0 - ch1);

float3 optDepth = ch.x * H.x * _AirSeaLevelExtinction
float3 optDepth = ch.x * H.x * _AirSeaLevelExtinction.xyz
+ ch.y * H.y * _AerosolSeaLevelExtinction;

skyOpacity = 1 - TransmittanceFromOpticalDepth(optDepth); // from 'tEntry' to 'tFrag'
Expand Down Expand Up @@ -242,7 +242,7 @@ void EvaluatePbrAtmosphere(float3 worldSpaceCameraPos, float3 V, float distAlong
float nrmAngle = Remap01(chiAngle, rcpLen, start * rcpLen);
// float angle = saturate((0.5 * PI) - acos(cosChi) * rcp(0.5 * PI));

skyColor *= ExpLerp(_HorizonTint, _ZenithTint, nrmAngle, _HorizonZenithShiftPower, _HorizonZenithShiftScale);
skyColor *= ExpLerp(_HorizonTint.rgb, _ZenithTint.rgb, nrmAngle, _HorizonZenithShiftPower, _HorizonZenithShiftScale);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ float4 EvaluateLight_Directional(LightLoopContext lightLoopContext, PositionInpu
// TODO: Not sure it's possible to precompute cam rel pos since variables
// in the two constant buffers may be set at a different frequency?
float3 X = GetAbsolutePositionWS(posInput.positionWS);
float3 C = _PlanetCenterPosition;
float3 C = _PlanetCenterPosition.xyz;

float r = distance(X, C);
float cosHoriz = ComputeCosineOfHorizonAngle(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void main(uint3 dispatchThreadId : SV_DispatchThreadID)
float3 gN = normalize(gP);

// Shade the ground.
const float3 gBrdf = INV_PI * _GroundAlbedo;
const float3 gBrdf = INV_PI * _GroundAlbedo.rgb;

// TODO: we compute the same thing for many voxels,
// the only real difference is the phase function...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ float DifferenceOfSquares(float a, float b)

float3 AirScatter(float height)
{
return _AirSeaLevelScattering * exp(-height * _AirDensityFalloff);
return _AirSeaLevelScattering.rgb * exp(-height * _AirDensityFalloff);
}

float AirPhase(float LdotV)
Expand All @@ -37,7 +37,7 @@ float AirPhase(float LdotV)

float3 AerosolScatter(float height)
{
return _AerosolSeaLevelScattering * exp(-height * _AerosolDensityFalloff);
return _AerosolSeaLevelScattering.rgb * exp(-height * _AerosolDensityFalloff);
}

float AerosolPhase(float LdotV)
Expand Down Expand Up @@ -285,7 +285,7 @@ float3 ComputeAtmosphericOpticalDepth(float r, float cosTheta, bool aboveHorizon

float2 optDepth = ch * H;

return optDepth.x * _AirSeaLevelExtinction + optDepth.y * _AerosolSeaLevelExtinction;
return optDepth.x * _AirSeaLevelExtinction.xyz + optDepth.y * _AerosolSeaLevelExtinction;
}

float3 ComputeAtmosphericOpticalDepth1(float r, float cosTheta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ void UpdateGlobalConstantBuffer(CommandBuffer cmd, BuiltinSkyParameters builtinP
m_ConstantBuffer._AerosolAnisotropy = pbrSky.aerosolAnisotropy.value;
m_ConstantBuffer._AerosolPhasePartConstant = CornetteShanksPhasePartConstant(pbrSky.aerosolAnisotropy.value);
m_ConstantBuffer._Unused = 0.0f; // Warning fix
m_ConstantBuffer._Unused2 = 0.0f; // Warning fix

m_ConstantBuffer._AirDensityFalloff = 1.0f / airH;
m_ConstantBuffer._AirScaleHeight = airH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,22 @@ unsafe struct ShaderVariablesPhysicallyBasedSky
public float _AerosolDensityFalloff;
public float _AerosolScaleHeight;

public Vector3 _AirSeaLevelExtinction;
public float _AerosolSeaLevelExtinction;
public Vector4 _AirSeaLevelExtinction;
public Vector4 _AirSeaLevelScattering;
public Vector4 _AerosolSeaLevelScattering;
public Vector4 _GroundAlbedo;
public Vector4 _PlanetCenterPosition; // Not used during the precomputation, but needed to apply the atmospheric effect
public Vector4 _HorizonTint;
public Vector4 _ZenithTint;

public Vector3 _AirSeaLevelScattering;
public float _AerosolSeaLevelExtinction;
public float _IntensityMultiplier;

public Vector3 _AerosolSeaLevelScattering;
public float _ColorSaturation;

public Vector3 _GroundAlbedo;
public float _AlphaSaturation;

public Vector3 _PlanetCenterPosition; // Not used during the precomputation, but needed to apply the atmospheric effect
public float _AlphaMultiplier;

public Vector3 _HorizonTint;
public float _HorizonZenithShiftPower;

public Vector3 _ZenithTint;
public float _HorizonZenithShiftScale;
public float _Unused2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ GLOBAL_CBUFFER_START(ShaderVariablesPhysicallyBasedSky, b2)
float _AirScaleHeight;
float _AerosolDensityFalloff;
float _AerosolScaleHeight;
float3 _AirSeaLevelExtinction;
float4 _AirSeaLevelExtinction;
float4 _AirSeaLevelScattering;
float4 _AerosolSeaLevelScattering;
float4 _GroundAlbedo;
float4 _PlanetCenterPosition;
float4 _HorizonTint;
float4 _ZenithTint;
float _AerosolSeaLevelExtinction;
float3 _AirSeaLevelScattering;
float _IntensityMultiplier;
float3 _AerosolSeaLevelScattering;
float _ColorSaturation;
float3 _GroundAlbedo;
float _AlphaSaturation;
float3 _PlanetCenterPosition;
float _AlphaMultiplier;
float3 _HorizonTint;
float _HorizonZenithShiftPower;
float3 _ZenithTint;
float _HorizonZenithShiftScale;
float _Unused2;
CBUFFER_END


Expand Down