In order to create a duplicate (copy) of a Custom Render Texture at runtime should I?
A) use the constructor and copy the attributes:
CustomRenderTexture tempCustomRT;
Init()
{
...
skyMaterial = customRT.material;
if (skyMaterial != null)
{
skyMaterial = new Material(skyMaterial);
tempCustomRT = new CustomRenderTexture(customRT.width, customRT.height, customRT.format)
{
dimension = customRT.dimension,
descriptor = customRT.descriptor,
depth = customRT.depth,
antiAliasing = customRT.antiAliasing,
format = customRT.format,
depthStencilFormat = customRT.depthStencilFormat,
initializationMode = customRT.initializationMode,
initializationSource = customRT.initializationSource,
initializationMaterial = skyMaterial,
material = skyMaterial,
shaderPass = customRT.shaderPass,
updateMode = customRT.updateMode,
updatePeriod = customRT.updatePeriod
};
tempCustomRT.Create();
if (tempCustomRT.IsCreated())
{
hdriSkyOverride.hdriSky.value = tempCustomRT;
}
}
...
}
private void OnDestroy()
{
if (tempCustomRT != null)
{
if (tempCustomRT.IsCreated())
{
tempCustomRT.DiscardContents();
tempCustomRT.Release();
}
tempCustomRT = null;
}
}
B) Create a temp custom RT
var tempCustomRT = CustomRenderTexture.GetTemporary(customRT.descriptor);