Change material color with multiple cameras

Is there a way to render objects and update GI based on which camera I use? I’m not really sure if I want to do this since Its just for a possible game-mode that I could scrap, but if there’s an easy way, it would be great.

What I want to do is change these values when a new camera renders.

void UpdateMaterial(Color col)
{
    material.SetColor("_EmissionColor", col);
    material.SetColor("_Color", col);
    DynamicGI.SetEmissive(renderer, col);
}

Is it possible to do it with the cameras OnPreRender/OnPostRender or something?

The intended use is for me to render some stuff differently when doing local multiplayer/couch multiplayer for each player.
For example: Player 1, 2, 3 and 4 each have a flag that’s green. However, when viewing in Player 1s camera, I want Player 1s flag to be green and the other players as red. When viewed in player 2s camera, Player 2s should be green and the others red and so on. I cannot just use four different colors for each player. Its a bit difficult to explain why, but the colors are limited, and there could be a lot more players (bots or even networked players), and I want the players to be able to choose colors themselves, meaning that they could potentially choose the same color.
Or another example: You have Player 1 and 2, splitscreen for an rts. The players want their units to be colored in green for their units on their screen and the other players in red.

As I said, if it’s “too difficult” to create this behaviour, I’ll probably scrap the idea instead. I’ve seen the camera.RenderWithShader(…) too, but I think that’s where “too difficult” or too much of a hassle to be worth it comes in.

One simple solution is to have 2 objects and use layers so each camera only draws the selected version.

Hm, yes, maybe that could be a possible solution. I think it could be quite a few objects though, and if there’s four local players possible then there would be four objects I assume.

I think I’ll try and swap the values on preRender and postRender (hook to the camera with a list or something) and call the appropriate functions and see if that works first, otherwise, multiple objects could be a solution. I’ll look into it and see if any of them work! Thanks.

So it seems that I could get it to work to some extent, but the DynamicGI does not seem to update the values immediately, so I’m guessing it’s once per frame only then right? In that case I think I’m stuck.

DynamicGI.SetEmissive(renderer, col); // Does not work with camera prerender/postrender

Otherwise, it seems to work though. Materials seems to be updated. What i did was create an interface

public interface ICameraRenderChange
{
    void OnCameraPreRender(CharacterInfo info);
    void OnCameraPostRender(CharacterInfo info);
}

and add that to the scripts that I want to change behaviours on. And in a script on the camera i added a list and iterate through the items

void OnPreRender()
    {
        foreach (ICameraRenderChange renderChange in cameraChangers)
        {
            renderChange.OnCameraPreRender(player);
        }
    }
    void OnPostRender()
    {
        foreach (ICameraRenderChange renderChange in cameraChangers)
        {
            renderChange.OnCameraPostRender(player);
        }
    }

And this is the result. (Left is trying to change all the values, right is default)

1 Like