Unity supports 3D Texture use and creation from shader and script. While use cases of 3D Textures might not seem as straightforward at first, they can be an integral part of implementing specific kinds of effects such as 3D Color Correction.
Currently, 3D Textures can only be created from script. The following snippet creates a “neutral” 3D texture where, if used as a lookup texture in 3D Color Correction, the performed correction will be the identity.
function CreateIdentityLut (dim : int, tex3D : Texture3D)
{
var newC : Color[] = new Color[dim * dim * dim];
var oneOverDim : float = 1.0f / (1.0f * dim - 1.0f);
for(var i : int = 0; i < dim; i++) {
for(var j : int = 0; j < dim; j++) {
for(var k : int = 0; k < dim; k++) {
newC[i + (j*dim) + (k*dim*dim)] = new Color((i*1.0f)*oneOverDim, (j*1.0f)*oneOverDim, (k*1.0f)*oneOverDim, 1.0f);
}
}
}
tex3D.SetPixels (newC);
tex3D.Apply ();
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information