SO basically I'm trying to transfer content of a temporary cubemap, that capture the scene, into an atlas of flat environement map (using the octohedron mapping).
my plan was to:
1.render a single cubemap at position
2.read and write the cubemap, using custom render texture's shader, to an update zone
3. repeat from 1 until all probe are baked.
However, documentation and example about custom render texture are sparse, especially when dealing with update zone.
That part of the manual say that:
https://docs.unity3d.com/Manual/class-CustomRenderTexture.htmlControlling Custom Render Texture from Script
Most of the functionalities described here can be accessed via the Scripting API. Changing material parameters, update frequency, update zones, requesting an update etc, can all be done with the script.
One thing to keep in mind though is that any update requested for the Custom Texture will happen at a very specific time at the beginning of the frame with the current state of the Custom Texture. This guarantees that any material using this texture will have the up-to-date result.
This means that this kind of pattern:
customRenderTexture.updateZones = updateZones1;
customRenderTexture.Update();
customRenderTexture.updateZones = updateZones2;
customRenderTexture.Update();
Will not yield the “expected” result of one update done with the first array of update zones and then a second update with the other array. This will do two updates with the second array.
The good rule of thumb is that any property modified will only be active in the next frame.
I'm not sure how to handle that right now, I have no idea if there is support for multiple update of multiple zones.
MY code currently is
void renderProbe(){
Camera UVCapture = Capture.GetComponent<Camera>();
List<CustomRenderTextureUpdateZone> zones = new List<CustomRenderTextureUpdateZone>();
IndirectionProbeAtlas.GetUpdateZones(zones);
UVCapture.SetReplacementShader(UV, "RenderType");
UVCapture.backgroundColor = Color.blue;
UVCapture.clearFlags = CameraClearFlags.SolidColor;
int i = 0;
foreach(GameObject probe in ProbeArray){
Capture.transform.position = probe.transform.position;
Capture.transform.rotation = Quaternion.identity;
UVCapture.RenderToCubemap(SceneCapture);
//project cubemap to atlas -> in shader:
//sample cubemap with perpixel octomaping 128 tile in atlas
i++;
}
UVCapture.enabled = false;
}
Please forgive me for the:
It's prototype code.
I'm not using array of cubemap because gles 2.0 don't support it, hence the need to write to an atlas representation to minimize texture fetching.