Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Call SRGBToLinear in Bloom FragPrefilter Pass #629

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from

Conversation

gam0022
Copy link

@gam0022 gam0022 commented Aug 1, 2018

I fixed the Bloom Effect implementation: Calling SRGBToLinear() in the FragPrefilter Pass is missing.

This change makes Bloom Effect maintain the same appearance regardless of the Unity's Color Space setting (Gamma or Linear).

Details

The Bloom threshold is in Linear Space.

float lthresh = Mathf.GammaToLinearSpace(settings.threshold.value);

On the other hand, Bloom FragPrefilter does not convert to Linear Space.

half4 FragPrefilter13(VaryingsDefault i) : SV_Target
{
half4 color = DownsampleBox13Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy);
return Prefilter(SafeHDR(color), i.texcoord);
}
half4 FragPrefilter4(VaryingsDefault i) : SV_Target
{
half4 color = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy);
return Prefilter(SafeHDR(color), i.texcoord);
}

The UberShader Pass calls LinearToSRGB().

#if UNITY_COLORSPACE_GAMMA
{
output = LinearToSRGB(output);
}
#endif

It means that the Linear Space Threshold is compared with the SRGB Space RenderTexutre when UNITY_COLORSPACE_GAMMA is defined (Unity Color Space: Gamma).

I fixed this implementation so that the Bloom Effect works properly even if UNITY_COLORSPACE_GAMMA is defined or not.

Results

Before (v2 branch)

The intensity of Bloom is changed by Unity's color space setting (Gamma or Linear).

before_gamma

before_linear

After (this branch)

It maintains the same appearance regardless of the Unity's color space setting.

fixed_gamma

fixed_linear

The original image belongs to the following site.
http://www.humus.name/index.php?page=Textures&ID=18

@gam0022
Copy link
Author

gam0022 commented Sep 26, 2018

@Chman Would you please review?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant