Hi, I need some help for render texture, imagine i want to blend 2 Camera. So in my scene i have two camera, (camera1) and (camera2). (camera1) have some objects and (camera2) have other objects, everything is shaded, light, shadow... If i understand correctly, i need to create a render Texture for each camera, maybe i need to use graphics.Blit to blend them? I want to Add rendertexture1 and 2, add like photoshop image process ( add, multiply....) Is it possible? Someone can show me a way? Thanks a lot
If you just need to render the context of one camera on top of the other, all you need to do is to configure the depth of the cameras, set both of them to clear depth only and render the correct layers.
Its not really clear, i want to Multiply one on the other. So why i need to use only the depth ? Do you have a bit of command reference to help me ? Im in C# for this process. thanks
It's not really clear exactly what it is you want. Could you explain a bit more in detail and perhaps provide an illustration or example?
This is a simple example, i have 2 camera, each camera with a different batch of asset (in different layer) i want to multiply on camera onver the other, with a multiply blending, to get one image. Something like that : Thanks for your help
Here's a quick example of multiply of two cameras. The source camera is multiplied onto the destination camera and the result is displayed in GUI. For clarity, the render is done on a red background and the GUI display is scaled down. The overlay camera needs to be set to only render objects in the overlay layer, the destination camera needs to be set to not render stuff in the overlay layer and the objects need to be placed in the correct layers ofcourse. Code (csharp): using UnityEngine; using System.Collections; public class Multiply : MonoBehaviour { public Camera source, destination; private RenderTexture renderTexture; private Texture2D sourceRender, destinationRender; void Start () { renderTexture = new RenderTexture (Screen.width, Screen.height, 24); sourceRender = new Texture2D (Screen.width, Screen.height); destinationRender = new Texture2D (Screen.width, Screen.height); } void Update () { RenderTexture active = RenderTexture.active; RenderTexture.active = renderTexture; RenderTexture target = source.targetTexture; source.targetTexture = renderTexture; source.Render (); sourceRender.ReadPixels (new Rect (0.0f, 0.0f, renderTexture.width, renderTexture.height), 0, 0); source.targetTexture = target; Color background = destination.backgroundColor; destination.backgroundColor = Color.red; target = destination.targetTexture; destination.targetTexture = renderTexture; destination.Render (); destinationRender.ReadPixels (new Rect (0.0f, 0.0f, renderTexture.width, renderTexture.height), 0, 0); destination.targetTexture = target; destination.backgroundColor = background; RenderTexture.active = active; Color[] sourcePixels = sourceRender.GetPixels (), destinationPixels = destinationRender.GetPixels (); for (int i = 0; i < sourcePixels.Length; i++) { destinationPixels[i] = new Color ( (sourcePixels[i].r * destinationPixels[i].r) / 1.0f, (sourcePixels[i].g * destinationPixels[i].g) / 1.0f, (sourcePixels[i].b * destinationPixels[i].b) / 1.0f, (sourcePixels[i].a * destinationPixels[i].a) / 1.0f ); } destinationRender.SetPixels (destinationPixels); destinationRender.Apply (); } void OnGUI () { GUI.DrawTexture (new Rect (0.0f, 0.0f, 300.0f, 300.0f), destinationRender); } } https://gist.github.com/1118288
But i always getting the source camera over the source camera. I have the corrent culling mask, so im rendering the right layer, but always, the source camera is shows in red over the source camera. Its seems to not taking care of the destination camera. Im right ?
Hi, thanks again for your help. It seems the multiply script not wokring correctly if my camera is set to deferred lighting. Is it possible ? I need to set in deferred lighting, because im using soft shader and i want the maximum quality in my game. Any suggestion?
That shouldn't affect this script as it simply asks the camera to render what it sees to textures. Do note that this is an example of using RenderTextures to solve the problem where in reality your most optimal solution would be a shader. I'm unfortunately not familiar with shader syntax (one of those things it seems I just never get around to).
If you want, i can build you a test scene, its really affect the inclusive exclusive light if im in deferred lighting or not. Its weird enh! Do you want a test seen to double check my saying?
Unfortunately I don't really have the time to go through peoples individual projects. Make sure that all cameras are set to the same rendering mode and continue debugging from there.