Skip to content

Commit

Permalink
Fix SSAO is flipped when not rendering to render texture [closes #49]
Browse files Browse the repository at this point in the history
  • Loading branch information
Delt06 committed Apr 15, 2023
1 parent 2772d9a commit be0b942
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Render(ScriptableRenderContext context, Camera camera, in ToonCamera
return;
}

Setup(globalRampSettings, toonShadowSettings, postProcessingSettings, ssaoSettings);
Setup(globalRampSettings, toonShadowSettings, postProcessingSettings);
_postProcessing.Setup(_context, postProcessingSettings, _settings, _colorFormat, _camera, _rtWidth,
_rtHeight
);
Expand Down Expand Up @@ -164,8 +164,7 @@ private bool Cull(in ToonShadowSettings toonShadowSettings)
}

private void Setup(in ToonRampSettings globalRampSettings,
in ToonShadowSettings toonShadowSettings, in ToonPostProcessingSettings postProcessingSettings,
in ToonSsaoSettings ssaoSettings)
in ToonShadowSettings toonShadowSettings, in ToonPostProcessingSettings postProcessingSettings)
{
SetupLighting(globalRampSettings, toonShadowSettings);

Expand All @@ -178,7 +177,6 @@ private void Setup(in ToonRampSettings globalRampSettings,

_renderToTexture = _settings.AllowHdr || _msaaSamples > 1 ||
postProcessingSettings.HasFullScreenEffects() ||
ssaoSettings.Enabled ||
!Mathf.Approximately(renderScale, 1.0f)
;
_colorFormat = _settings.AllowHdr ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
Expand Down
9 changes: 8 additions & 1 deletion Packages/com.deltation.toon-rp/ShaderLibrary/SSAO.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ float3 _ToonRP_SSAO_Pattern_Scale;
float2 _ToonRP_SSAO_Pattern_Ramp;
float2 _ToonRP_SSAO_Pattern_DistanceFade;

float SampleAmbientOcclusionRaw(const float2 screenUv)
float SampleAmbientOcclusionRaw(float2 screenUv)
{
#if UNITY_UV_STARTS_AT_TOP
if (_ProjectionParams.x > 0.0)
{
screenUv.y = 1 - screenUv.y;
}
#endif // UNITY_UV_STARTS_AT_TOP

return SAMPLE_TEXTURE2D(_ToonRP_SSAOTexture, sampler_ToonRP_SSAOTexture, screenUv).x;
}

Expand Down

0 comments on commit be0b942

Please sign in to comment.