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

Commit beaa73e

Browse files
authored
Merge pull request #143 from Yasei-no-otoko/avoid-gc
Avoid GC allocate in ColorGrading GetCurveTexture
2 parents 969f10c + f70f076 commit beaa73e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

PostProcessing/Runtime/Components/ColorGradingComponent.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static class Uniforms
3333
const float k_CurveStep = 1f / k_CurvePrecision;
3434

3535
Texture2D m_GradingCurves;
36+
Color[] m_pixels = new Color[k_CurvePrecision * 2];
3637

3738
public override bool active
3839
{
@@ -236,9 +237,7 @@ Texture2D GetCurveTexture()
236237
};
237238
}
238239

239-
var pixels = new Color[k_CurvePrecision * 2];
240240
var curves = model.settings.curves;
241-
242241
curves.hueVShue.Cache();
243242
curves.hueVSsat.Cache();
244243

@@ -251,17 +250,17 @@ Texture2D GetCurveTexture()
251250
float y = curves.hueVSsat.Evaluate(t);
252251
float z = curves.satVSsat.Evaluate(t);
253252
float w = curves.lumVSsat.Evaluate(t);
254-
pixels[i] = new Color(x, y, z, w);
253+
m_pixels[i] = new Color(x, y, z, w);
255254

256255
// YRGB
257256
float m = curves.master.Evaluate(t);
258257
float r = curves.red.Evaluate(t);
259258
float g = curves.green.Evaluate(t);
260259
float b = curves.blue.Evaluate(t);
261-
pixels[i + k_CurvePrecision] = new Color(r, g, b, m);
260+
m_pixels[i + k_CurvePrecision] = new Color(r, g, b, m);
262261
}
263262

264-
m_GradingCurves.SetPixels(pixels);
263+
m_GradingCurves.SetPixels(m_pixels);
265264
m_GradingCurves.Apply(false, false);
266265

267266
return m_GradingCurves;

0 commit comments

Comments
 (0)