im trying to use the basic render stack not the lightweight lwrp urp to separate two render stages to perform effects to selected objects and overlay them back onto the bottom render pass.
The passes are |
Skybox
Selected objects with custom magicness without skybox
im essentially trying to simply get the current stage of rendering of the skybox without objects in the view. Though in my reading skybox happens after everything and internally is composited via masks. So that wont work I guess. So I might need to keep working in lwrp again anyhow https://docs.unity3d.com/Manual/GraphicsCommandBuffers.html
I dont want to simply apply a screen filter over everything rendered during OnRenderImage
I have tried to not clear the buffer m_DisplaceBuffer.ClearRenderTarget(true, true, Color.clear);
but I dont see a way to just render into the buffer without a renderer
Im also using the Frame debugger to step though the passes to find if I can reach that
m_DisplaceBuffer = new CommandBuffer();
m_DisplaceBuffer.name = "Skyyyybox BufffferZ";
m_Cameras[cam] = m_DisplaceBuffer;
int tempID = Shader.PropertyToID("_Temp1Zzz");
m_DisplaceBuffer.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear);
m_DisplaceBuffer.SetRenderTarget(tempID);
m_DisplaceBuffer.ClearRenderTarget(true, true, Color.clear);
// this does not work for the skybox since theres no ClearRenderTarget
// m_DisplaceBuffer.DrawRenderer(r, _flatColorMat);
m_DisplaceBuffer.SetGlobalTexture("_map", tempID);
cam.AddCommandBuffer(CameraEvent.AfterSkybox, m_DisplaceBuffer);
There’s no way to just render the skybox with command buffers, no.
However you can just do what everyone did before command buffers, which is add a new camera to the scene as a child of your main camera, set the depth to a value less the main camera, set it to clear to the skybox, set the culling mask to nothing, and assign a render texture as it’s target, either an asset or from script with a temporary target. Alternatively you can set those settings on the main camera and call Render() on it, then set it back to the previous settings.
So I had issues with trying to get the single camera to render to skybox texture and then back to targetTexture = null timing and mix with nessasasry CommandBuffers as well for other passes
So below is how I solved it for now.
In the scene Create a second camera and parent to main camera, setactive to false so it only renders on the render command
I also have a plane in the scene to see the texture working
if you have the magic combo to make a single camera work and retain a targetTexture none so it can render to the game view that would be great!
This ultimately wont be the answer to using this in AR to overlay the render scene to the camera frames. Those tend to have their own api and event callback function to patch into. BUt that should help someone when tinkering with this since I could not find any same code cira 2011
void SetSkyBoxOnlyCameraSettings(){
_skyboxCam.cullingMask = 0;
_skyboxCam.depth = -2;
_skyboxCam.clearFlags = CameraClearFlags.Skybox;
}
// command buffers will not work to get the skybox
// ugh
void RenderSkyBoxOnly_CM(){
// skyBox_MagicBuffer = new CommandBuffer();
// skyBox_MagicBuffer.name = "Skyyyyyyyyy Box only";
// // m_Cameras[_cam] = skyBox_MagicBuffer;
// int colorTexId = Shader.PropertyToID("_SkyyyyyyboxTemp");
// skyBox_MagicBuffer.GetTemporaryRT(colorTexId, -1, -1, 24, FilterMode.Bilinear);
// skyBox_MagicBuffer.SetRenderTarget(colorTexId);
// skyBox_MagicBuffer.ClearRenderTarget(true, true, Color.magenta); // clear before drawing to it each frame!!
// // set render texture as globally accessable 'glow map' texture
// skyBox_MagicBuffer.SetGlobalTexture("_SkyyyyyboxOnly", colorTexId);
// _cam.AddCommandBuffer(skyBoxEventsEnum, skyBox_MagicBuffer);
// _cam.Render();
// its too tricky to get the same camera to render out to textures
// _skyboxCam
SetSkyBoxOnlyCameraSettings();
_skyboxCam.depthTextureMode = DepthTextureMode.Depth;
if (_skyBoxRenderTexture == null)
{
_skyBoxRenderTexture = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.ARGB32);
_skyBoxRenderTextureDepth = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.Depth);
}
// _skyboxCam.SetTargetBuffers(_skyBoxRenderTexture.colorBuffer, _skyBoxRenderTextureDepth.depthBuffer);
_skyboxCam.targetTexture = _skyBoxRenderTexture;
_skyboxCam.Render();
Shader.SetGlobalTexture("_SkyyyyyboxOnly", _skyBoxRenderTexture);
// ResetCameraSettings();
// _cam.targetTexture = null;
}