feat: support 'Active Apply Color Space' for linear color space
parent
2b8d3b1385
commit
45c56bbd85
|
@ -332,8 +332,6 @@ namespace Coffee.UIExtensions
|
|||
DestroyUIParticle(current);
|
||||
}
|
||||
|
||||
// #203: When using linear color space, the particle colors are not output correctly.
|
||||
// To fix, set 'Apply Active Color Space' in renderer module to false.
|
||||
var allPsRenderers = targets.OfType<UIParticle>()
|
||||
.SelectMany(x => x.particles)
|
||||
.Where(x => x)
|
||||
|
@ -341,16 +339,6 @@ namespace Coffee.UIExtensions
|
|||
.ToArray();
|
||||
if (0 < allPsRenderers.Length)
|
||||
{
|
||||
var so = new SerializedObject(allPsRenderers);
|
||||
var sp = so.FindProperty("m_ApplyActiveColorSpace");
|
||||
label = "When using linear color space, the particle colors are not output correctly.\n" +
|
||||
"To fix, set 'Apply Active Color Space' in renderer module to false.";
|
||||
if (FixButton(sp.boolValue || sp.hasMultipleDifferentValues, label))
|
||||
{
|
||||
sp.boolValue = false;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
// Check to use 'TEXCOORD*.zw' components as custom vertex stream.
|
||||
foreach (var psr in allPsRenderers)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace Coffee.UIExtensions
|
|||
private static readonly List<Material> s_Materials = new List<Material>(2);
|
||||
private static MaterialPropertyBlock s_Mpb;
|
||||
private static readonly List<UIParticleRenderer> s_Renderers = new List<UIParticleRenderer>();
|
||||
private static readonly List<Color32> s_Colors = new List<Color32>();
|
||||
private static readonly Vector3[] s_Corners = new Vector3[4];
|
||||
private Material _currentMaterialForRendering;
|
||||
private bool _delay;
|
||||
|
@ -380,6 +381,24 @@ namespace Coffee.UIExtensions
|
|||
bounds.extents = extents;
|
||||
workerMesh.bounds = bounds;
|
||||
_lastBounds = bounds;
|
||||
|
||||
// Convert linear color to gamma color.
|
||||
if (QualitySettings.activeColorSpace == ColorSpace.Linear)
|
||||
{
|
||||
Profiler.BeginSample("[UIParticleRenderer] Convert Linear to Gamma");
|
||||
workerMesh.GetColors(s_Colors);
|
||||
var count_c = s_Colors.Count;
|
||||
for (var i = 0; i < count_c; i++)
|
||||
{
|
||||
var c = s_Colors[i];
|
||||
c.r = c.r.LinearToGamma();
|
||||
c.g = c.g.LinearToGamma();
|
||||
c.b = c.b.LinearToGamma();
|
||||
s_Colors[i] = c;
|
||||
}
|
||||
workerMesh.SetColors(s_Colors);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
|
|
|
@ -6,6 +6,25 @@ using Object = UnityEngine.Object;
|
|||
|
||||
namespace Coffee.UIParticleExtensions
|
||||
{
|
||||
public static class Color32Extensions
|
||||
{
|
||||
private static byte[] s_LinearToGammaLut;
|
||||
|
||||
public static byte LinearToGamma(this byte self)
|
||||
{
|
||||
if (s_LinearToGammaLut == null)
|
||||
{
|
||||
s_LinearToGammaLut = new byte[256];
|
||||
for (var i = 0; i < 256; i++)
|
||||
{
|
||||
s_LinearToGammaLut[i] = (byte)(Mathf.LinearToGammaSpace(i / 255f) * 255f);
|
||||
}
|
||||
}
|
||||
|
||||
return s_LinearToGammaLut[self];
|
||||
}
|
||||
}
|
||||
|
||||
public static class Vector3Extensions
|
||||
{
|
||||
public static Vector3 Inverse(this Vector3 self)
|
||||
|
|
Loading…
Reference in New Issue