Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411595 Posts in 69386 Topics- by 58445 Members - Latest Member: YomiKu_0

May 07, 2024, 06:18:56 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Unwrapping cubemap to an atlas
Pages: [1]
Print
Author Topic: Unwrapping cubemap to an atlas  (Read 1445 times)
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« on: October 25, 2019, 06:01:44 PM »

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.html
Quote
Quote
Controlling 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:
Code: (CSharp)
customRenderTexture.updateZones = updateZones1;
customRenderTexture.Update();
customRenderTexture.updateZones = updateZones2;
customRenderTexture.Update();
Quote
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

Code: (CSharp)
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:
Code: (CSharp)
int i = 0;    foreach
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.
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1 on: October 27, 2019, 09:22:10 AM »



Here is my problem, I have a camera that render to the cubemap, how do activate it so it count as rendering a frame, without it rendering to the main windows? Where I hijack the code so my atlas get filled correctly?

This making me mad lol

It has ignored all the zones and only cared about the last one!

How do I make it so it fills everything?

Code:
void renderProbe(){
        Camera UVCapture = Capture.GetComponent<Camera>();
        List<CustomRenderTextureUpdateZone> zones = new List<CustomRenderTextureUpdateZone>();
        CustomRenderTextureUpdateZone[] updating = new CustomRenderTextureUpdateZone[1];
        IndirectionProbeAtlas.GetUpdateZones(zones);
         
        UVCapture.SetReplacementShader(UV, "RenderType");
        UVCapture.backgroundColor = Color.blue;
        UVCapture.clearFlags = CameraClearFlags.SolidColor;
 
        int i = 0;
        foreach(GameObject probe in ProbeArray){
            //render at position on grid
            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
         
            //set the update zone
            updating[0] = zones[i];
         
            IndirectionProbeAtlas.SetUpdateZones(updating);
            IndirectionProbeAtlas.Update();
            i++;
        }
        UVCapture.enabled = false;
    }

How do I force a frame?
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #2 on: November 11, 2019, 08:56:26 PM »

Solved the problem, custom render texture and render texture aren't the same, custom render texture are only initialized after one cycle, moving to render texture since I'm unwrapping manually already did the work.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic