Integrating 3D models with photography
Interested in integrating your 3D work with the real world? This might help
# 1 23-02-2012 , 02:27 PM
Registered User
Join Date: Jan 2012
Posts: 6

Let rendered camera control light?

Hi!

Is it possible (Maya 2012) to, depending on which camera is rendered, turn certain lights on or off?

I.e. I have two cameras, one "front" and one "back" basically. I also have three light sources, one "frontLight", one "backLight" and one we could call "fillLight".

Now, if a scene is rendered with the "front" camera, I want "frontLight" turned ON, and "backLight" turned OFF. And vice versa of course. The "fillLight" will always be on, for all intents and purposes here anyway.

Now, where would I go look for how to solve this? I was hoping to find something I could do in the Hypershade or something, like connect an "currentRender" attribute of the camera to the visibility attribute of the light or something along those line.

But I have not yet found anything (I am a newbie in Maya, it's not normally my field of work) on Google or in the help that has pointed me in the right direction. Not knowing the exact terminology due to being a newb doesn't exactly help either user added image

Any help appreciated!

# 2 23-02-2012 , 03:29 PM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
You might have to resort to a bit of MEL scripting. You would need to use getAttr and setAttr to get the relevant attribute of the camera and set the attribute of the light intensity or something. Sorry, it's been a while since I did any MEL so I can't give you all the details.

# 3 23-02-2012 , 04:07 PM
Registered User
Join Date: Jan 2012
Posts: 6

You might have to resort to a bit of MEL scripting. You would need to use getAttr and setAttr to get the relevant attribute of the camera and set the attribute of the light intensity or something. Sorry, it's been a while since I did any MEL so I can't give you all the details.

Yeah, I figured something like that as well, possibly a pre-render MEL script. The problem is, I don't know what attribute to look for user added image

I assume that the camera attribute .renderable (if I recall correctly), doesn't really say that THIS camera is the currently rendered one.

Thanks anyway though.

# 4 23-02-2012 , 05:08 PM
Subscriber
Join Date: Oct 2011
Posts: 139
I'm not sure if I understand you correctly.. but how about just putting each light on a separate layer? That way you can turn them on and off, depending which camera you render from. Or you could also just turn down the intensity to 0 on the lights you don't want to render in current render.. and then turn it back on and turn the other light off.

# 5 23-02-2012 , 05:46 PM
Perfecto's Avatar
Registered User
Join Date: Mar 2007
Location: TN (USA)
Posts: 1,889
As nov2011 mentioned, adjusting light intensity seems like an easy route. If you're rendering out an animation, perhaps you could key frame the light intensity of each light so that the right light is lit at certain times during the animation. If not rendering out an animation then putting the lights on different layers would indeed be a simple solution.


Don't be satisfied with what you can do but rather strive to do the things you can't do!
Exceed Expectations!
# 6 23-02-2012 , 07:07 PM
Registered User
Join Date: Jan 2012
Posts: 6
Good points, both nov2011 and Perfecto.

As it stands now, I *do* have both lights in separate layers, so that's how I'm using it now. I was simply thinking there might be some way to, depending on which camera is used for the (batch or otherwise) render, automatically turn one or the other light (or layer, for that matter) on or off.

However, I might just see if I can render it out as frames of an animation. I.e. create a new camera for this purpose, making frame 1 have the same position as frontCamera with frontLight turned on, and frame 2 moves the camera to the position of backCamera and turns on backLight...

At least it is a possible solution, even if it wasn't what I was originally looking for. Never bad to think outside the box, so to speak - I was rendering still images, but might end up rendering frames of an animation. user added image

Any further suggestions is of course still welcome!

# 7 23-02-2012 , 08:24 PM
Perfecto's Avatar
Registered User
Join Date: Mar 2007
Location: TN (USA)
Posts: 1,889
I think in all fairness, stwert makes a very valid point with Mel. Although I don't know much mel myself, it's said that if a Maya artist (modeler, texture artist, animator, etc) learns scritping, it takes your skills to a whole new level. You'll be able to do much more than you could otherwise, including the light behavior you're looking for.

I think it's definitely worth your time learning some mel. Not only does it open up new possibilities for you, it can also speed up your workflow quite a bit. You can't go wrong learning it.


Don't be satisfied with what you can do but rather strive to do the things you can't do!
Exceed Expectations!
# 8 23-02-2012 , 08:59 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
You could always do something like the following. Run it in the script editor. I've modified it from my script here

You can change the attributes to whatever you want. A " ImageFormats instance has no attribute 'oldOutf'" error might pop up, but don't worry. It doesn't affect anything. What it does, is turn on a light, and render from a camera. Turn off the first light, and turn on the second. Render. Save both of these out.

Hope it helps.

-John

Code:
// these values can be changed
string $cameraAName = "persp1";
string $cameraBName = "persp2";

string $lightAName = "pointLight1";
string $lightBName = "pointLight2";

string $filename = "render";

// don't change anything below this line
string $directory = (`workspace -q -rd` + "images/");

string $renderPanel;
string $renderPanels[] = `getPanel -scriptType "renderWindowPanel"`;

if(size($renderPanels)) 
    $renderPanel = $renderPanels[0];
else
{
    $renderPanel = `scriptedPanel -type "renderWindowPanel" -unParent renderView`;

    scriptedPanel -e -label "Render View" $renderPanel;
}

// render camera A
setAttr ($lightAName + ".visibility") 1;
setAttr ($lightBName + ".visibility") 0;

render  -x `getAttr defaultResolution.width` -y `getAttr defaultResolution.height` $cameraAName;

string $concatFilename = $directory + ($filename + "A");

catch(eval(renderWindowSaveImageCallback ($renderPanel, $concatFilename, `getAttr defaultRenderGlobals.imageFormat`)));

// render camera B
setAttr ($lightAName + ".visibility") 0;
setAttr ($lightBName + ".visibility") 1;

render  -x `getAttr defaultResolution.width` -y `getAttr defaultResolution.height` $cameraBName;

$concatFilename = $directory + ($filename + "B");

catch(eval(renderWindowSaveImageCallback ($renderPanel, $concatFilename, `getAttr defaultRenderGlobals.imageFormat`)));


Imagination is more important than knowledge.

Last edited by NextDesign; 23-02-2012 at 09:07 PM.
# 9 24-02-2012 , 08:48 AM
Registered User
Join Date: Jan 2012
Posts: 6

I think it's definitely worth your time learning some mel. Not only does it open up new possibilities for you, it can also speed up your workflow quite a bit. You can't go wrong learning it.

Indeed it is, and I have. I normally develop web sites, so I'm not a stranger to scripting in various languages and have been programming for some 20 years now user added image Thing is, it's mostly an isolated case I need this for, and I can't sink too much time into it now or it will cost me more than the client pays user added image

Other than that, I've spent quite a lot of time trying to get to grips with it. But as with so many other cases, it's what you produce that is most important, not HOW you produce it.

You could always do something like the following. Run it in the script editor. I've modified it from my script here

Heya ND, and I did indeed already check out your scripting a bit, but never got it to work properly (the render took just 10-20 seconds, while a proper render took a lot longer - dunno why). Now that I actually have a working solution (a 2-frame animation which moves the camera + turns on/off lights) I can start to experiment a bit more in my spare time (wait, what? no such thing!).

Looking at the script, it pretty much looks exactly the same as the one I tried user added image

Thanks both of you, Maya has been an eye-opener (shame I can't afford a personal license, would've been fun to just "fiddle about" with) and has definitely created a craving for more. Not to mention that I've started to look at the real world with eyes that look at how light and shadow falls and all that. Work hazard I guess user added image

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads