Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411425 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 09:07:49 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Camera not rendering to cubemap!
Pages: [1]
Print
Author Topic: Camera not rendering to cubemap!  (Read 2510 times)
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« on: April 11, 2022, 03:58:18 PM »

Hello!

I have an issue where I created a class to generate a lightprobe atlas texture for me, but the camera don't seem to render properly into teh rendertexture, I have no idea why...

someone can help me found what I did wrong?

Code:
private void setCameraData(){
 
        //set camera
        pivot = new GameObject("CaptureScene");
        pivot.AddComponent<Camera>();
 
        //Set camera parameters
        lens = pivot.GetComponent<Camera>();
        lens.backgroundColor = Color.blue;
        lens.clearFlags = CameraClearFlags.SolidColor;
        lens.allowMSAA = false;
        lens.cullingMask = 1 << 8;//what mask?
        //should probably have an alternative for regular scene rendering
        lens.SetReplacementShader(capture, "RenderType");
   
        //set rendertexture
        sceneCapture = new RenderTexture(cubemapSize, cubemapSize, 24);
        sceneCapture.dimension = UnityEngine.Rendering.TextureDimension.Cube;
        sceneCapture.antiAliasing = 1;
        sceneCapture.filterMode = FilterMode.Point;
        sceneCapture.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm;
        sceneCapture.depth = 16;
        sceneCapture.Create();
   
    }
 
 
    public  void updateCell(int x, int y){
        //this fonction capture a cubemap of the scene from the point of view of a given cell
     
        //place camera
        int midcell = cellsize / 2;
        //-------------------- hashed position
        pivot.transform.position = new Vector3((x * cellsize) + midcell, 0, (y * cellsize) + midcell);
        pivot.transform.rotation = Quaternion.identity;
 
        lens.RenderToCubemap(sceneCapture);
 
        updateTile(x, y);
    }
 

The rendertexture seems to be stuck into gray, I can't figuring out why. This is a refactor code, technically I got it to work initially in the old code, but there seems to be no notable difference with the new code except it's now in a class and cleaned up of dead code...
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #1 on: April 14, 2022, 06:45:31 PM »

May I ask what version of Unity you are using? Is this pre-SRP?
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #2 on: April 15, 2022, 11:55:49 PM »

I'm def not using srp, it's built in and 2020.3.23.f1 personal

However a friend helpt me figured it out, the rendertexture wasn't properly connecting for some reason, moved it to the setCameraData() function and it works. Though I'm still tacking weird bugs elsewhere... Which is another thread, probably, once I lost enough hair.

Thanks for stopping by!
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic