public void ComputeTransferFunction() { Vector4[] transferFunc = new Vector4[256]; Cubic[] colorCubic = Cubic.CalculateCubicSpline(mColorKnots.Count - 1, mColorKnots); Cubic[] alphaCubic = Cubic.CalculateCubicSpline(mAlphaKnots.Count - 1, mAlphaKnots); int numTF = 0; for (int i = 0; i < mColorKnots.Count - 1; i++) { int steps = mColorKnots[i + 1].IsoValue - mColorKnots[i].IsoValue; for (int j = 0; j < steps; j++) { float k = (float)j / (float)(steps - 1); transferFunc[numTF++] = colorCubic[i].GetPointOnSpline(k); } } numTF = 0; for (int i = 0; i < mAlphaKnots.Count - 1; i++) { int steps = mAlphaKnots[i + 1].IsoValue - mAlphaKnots[i].IsoValue; for (int j = 0; j < steps; j++) { float k = (float)j / (float)(steps - 1); transferFunc[numTF++].w = alphaCubic[i].GetPointOnSpline(k).w; } } for (int i = 0; i < colorarray.Length; i++) { // Debug.Log(i+" "+transferFunc[i]); if (transferFunc[i].w > 1) { transferFunc[i].w = 1; } if (transferFunc[i].w < alphaValueThreadshold) { transferFunc[i].w = 0; } colorarray[i] = transferFunc[i]; //Debug.Log(i + " " + transferFunc[i]); } // material.SetColorArray("_ColorArray", colorarray); }