material dependent on camera being rendered?

Hello,

I would like to choose a material for an object depending on which camera is being rendered. Is there a way to know which camera is being rendered? Or any other way to achieve this? I also thought about using geometry instancing and a GLSL mat but I don’t see this capability in the version of Touch I’m using (077, build 2501).

Thanks!

If you are looking to have different materials on the same COMP, for different render TOPs, there currently isn’t an easy way to do this.
In the next build there will be a GLSL page on all Render and Render Pass TOPs, which allows you to pass uniforms to all of your GLSL MATs on a per render basis. Using this you can pass a different value for each Render to let the GLSL MATs know which camera is being used. This doesn’t help you if you are using Phong MATs though.

In future there will be a Switch MAT that you will be able to put an expression into, which will allow you to select which MAT to use on a per-render basis.

More answers below for simpler cases.

You can set this up using some DATs and a CHOP as an index.

Somehow, you must be switching the camera that is doing the rendering in the Render TOP, so when you switch cameras you could switch material automatically as well.

If you make a 2 column table, first column would be the camera path, second column the material you want associated with that camera. Follow this Table DAT with a Select DAT that selects the row you currently want to render with (ie camera1 and material1). Now you can add a Constant CHOP and export its value as an index select the desired row. So using the Constant CHOP value you are now selecting a camera and material by selecting out 1 row from the table.

Then in your Render TOP and Geometry COMP where the camera and material are referenced respectively, use a tab() expression to get the proper values from the Select DAT. I’ve attached an example which shows the basics of this setup.

cammat_example.tox (1.14 KB)

seems ben beat me to it. here’s the file anyway (you’ll need to change the name of the cam in the render top manually)
MatPerCam.toe (6.53 KB)

Might have beat you to it, but yours has pretty easter egg colors! :smiley:

and that’s why it took me so long to create that demo :mrgreen:

Thanks everyone for these solutions! I think I’ll be able to work with the table lookup solution until switch MAT is available.

The assumption that I am ‘switching’ the camera is not so accurate because I want both cameras to be rendered at every frame (stereoscopic). I currently have two separate render nodes whose outputs were composited differently depending on whether I wanted anaglyph or side by side final output.

But I think the table lookup will work if I just toggle between cam1 and cam2. The remaining issue might be that I would halve the frame rate if I did that. To be continued.

If you are doing stereo and you need a material per camera I would share the geometry between two geometry components and apply a different material to each one. The only thing in each geometry component would be an in SOP with its display and render flags on.

Also take note of the render pass TOP in this example where the second camera and object are rendered. This is the best way to do 2 full render passes.

J
matpercam.tox (2.96 KB)