Search Unity

Linear color space and washed out particle colors

Discussion in 'General Graphics' started by loboflex, Feb 21, 2018.

  1. loboflex

    loboflex

    Joined:
    Feb 24, 2014
    Posts:
    4
    Hello!

    Recently we changed from gamma to linear colors and have gotten some nice results as far as landscapes go. However, along the way all our particlesystems became sort of washed out, and a lot less saturated, as if they're missing some sort of gamma correction.

    You can see the different results here:


    The top is with linear colors, where the black smoke becomes kinda grey-ish and the explosions lose a lot of their luster. The bottom is with gamma where the smoke and explosions look just fine, but landscapes (not really shown) dont look as good.

    Am I missing some sort of obvious gamma correction setting on particle systems, or doing something wrong? Do I need a different set of shaders for the particles than the standard ones that come with unity?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    LasseWestmark and karl_jones like this.
  3. loboflex

    loboflex

    Joined:
    Feb 24, 2014
    Posts:
    4
    Alright, thanks for the answer. We'll see if we can figure something out. :)
     
  4. LasseWestmark

    LasseWestmark

    Joined:
    Mar 18, 2014
    Posts:
    12
    Hi, did you ever find a satisfactory solution? We have the same problem and I've been fiddling around with the shader and I can't really find any solution.

    This is the fragment program I have now:

    fixed4 frag (v2f i) : SV_Target
    {
    #ifdef SOFTPARTICLES_ON
    float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    float partZ = i.projPos.z;
    float fade = saturate (_InvFade * (sceneZ-partZ));
    i.color.a *= fade;
    #endif
    fixed4 col = i.color * tex2D(_MainTex, i.texcoord) * 2.0f;
    //LinearSpace fix
    #ifdef UNITY_COLORSPACE_GAMMA
    //Do nothing
    #else
    //i.color.rgb = LinearToGammaSpace(i.color.rgb);
    col.rgb = LinearToGammaSpace(col.rgb);
    // col.rgb = pow(col.rgb,0.454545);
    #endif
    // col *= 2.0f;

    UNITY_APPLY_FOG(i.fogCoord, col);
    return col;
    }


    As you can see I've tried some stuff. With no correction it's darker and washed out, and with my correction it's overbright.

    Edit:

    Ok I think I've found the problem and it's a two part one.

    First only the vertex color part of the tinting needs to be converted, and needs to go from gamma to linear. The color from the shader "_TintColor" is already in the correct space.

    Secondly particle shaders normally has this property where they multiply the final output by 2.0, assuming this is for making overbright particles easier. This also doesn't work because halfing a color in the inspector (128,128,128,128) and multiplying by two isn't the same as (255,255,255,255). This is because some conversion is happening in the inspector on the color picker I assume.

    Anyway for future reference here is my working fragment program:

    fixed4 frag (v2f i) : SV_Target
    {
    #ifdef SOFTPARTICLES_ON
    float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    float partZ = i.projPos.z;
    float fade = saturate (_InvFade * (sceneZ-partZ));
    i.color.a *= fade;
    #endif

    //LinearSpace fix
    #ifdef UNITY_COLORSPACE_GAMMA
    //Do nothing
    #else
    i.color.rgb = GammaToLinearSpace(i.color.rgb);
    #endif
    fixed4 col = tex2D(_MainTex, i.texcoord) * _TintColor * i.color;

    UNITY_APPLY_FOG(i.fogCoord, col);
    return col;
    }
     
    Last edited: Mar 20, 2018
    richardkettlewell likes this.
  5. loboflex

    loboflex

    Joined:
    Feb 24, 2014
    Posts:
    4
    Oh hi!

    We didn't really find a proper solution, but adjusting the bloom and compensating as best as possible when choosing particle colors (everything is _really_ dark) gave us results that were "good enough".

    Looks like the issue has been fixed for a future release now though, so maybe things will work out on their own soon. :)
     
    richardkettlewell likes this.
  6. LukePeek

    LukePeek

    Joined:
    Nov 29, 2013
    Posts:
    38
    Did anything ever get implemented to solve this automatically? The above linked issue says it was fixed in 2018.2, but in 2018.3 it still happens.
     
  7. loboflex

    loboflex

    Joined:
    Feb 24, 2014
    Posts:
    4
    Yeah, it was fixed, but if you've got old particle systems from before the fix then you've gotta check the "Apply Active Color Space" checkbox under the Renderer tab in your particle systems.



    This is checked by default on new particlesystems.
     
    richardkettlewell likes this.
  8. LukePeek

    LukePeek

    Joined:
    Nov 29, 2013
    Posts:
    38
    Ahh thanks! Totally missed that.
     
  9. jeorgegar

    jeorgegar

    Joined:
    Oct 25, 2018
    Posts:
    2
    I can not solve the problem, change my unity version from 2018.2 to 2019.1 and my particle system is affected when going from Gamma to Linear. the box '' apply Active Color Space '' is activated. I'm not good at Shader and I do not understand very well how to apply what LasseWestmark did. I hope you can help me thanks!
    linear linear.png
    gamma gamma.png
     
  10. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,638
    Did you see loboflex's post under that? There is no need to fix the shader any more. You just need to use the "apply color space" checkbox.
     
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    This is a different problem. The check box solves the issue of the color being passed to the particles isn't in the correct color space for the rendering, but it doesn't solve the fact that blending acts differently between linear and gamma space.

    Basically the check box will help otherwise fully opaque particles to be roughly the same color whereas before they would have been very different. Additive particles and partially transparent alpha blended particles will still look different and there's no easy solution to that. The best you can do is try to boost the brightness of your particles, maybe by using an HDR color multiplier on the material itself.
     
    jeorgegar and kdgalla like this.
  12. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,638
    Darn. I hadn't noticed this yet. WHY CAN'T ANYTHING EVER BE EASY?! ;)
     
    jeorgegar likes this.
  13. jeorgegar

    jeorgegar

    Joined:
    Oct 25, 2018
    Posts:
    2
    Thanks for clarifying Bgolus, I thought it was the same problem. after your submission .. for now this is the best result that I have opted for : linear2.png
    :confused: