Home Technical Talk

expression to control an attribute depending on light received?

polycounter lvl 7
Offline / Send Message
Yedp polycounter lvl 7
Hello everyone, I'm not good with expressions actually i barely use it in Maya but I was wondering if there is a way to create an expression to control an attribute depending on the light intensity received by an object.
This is more like an experimentation, hopefully you could help me figure this out.
Actually the practical exemple I was thincking of is an eye iris changing automaticly depending on the light received on it, in the scene:

IrisCtrl_test.jpg

So basicly in the exemple I have, there's an attribute named irisCtrl on a curve type of object named C_irisCtrl_1 and that attribute has a driven key controlling the vertex for the iris. The iris is named C_pupil_1 and is currently under a group named C_eye_1.
The tricky part is that I dunno if there's a way to know the overall value of the lights received by an object. Do you think it is possible to find out ?

Replies

  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    I'm not sure about getting the amount of light, since that would vary across the entire surface, but you could potentially do something like taking the dot product of the dominant light direction vs the eye's forward vector. This would not take shadows into account, so depending on how accurate you need it, this may not be sufficient.

    so broadly:
    iris control value = (saturate(dot(lightVector, eyeForwardVector)) - 0.5) * 2;

    This would pretty much translate to fully "closed" when the light is pointed directly at the eye, and fully dilated when the light is anywhere from 90 degrees to behind.
  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    LotekK's idea is probably your only option, perhaps if you can script a ray trace you can check for shadow occlusion as well.
    TO be honest this thing is something you would most probably just keyframe manually. But it's a cool exercise.
  • Yedp
    Options
    Offline / Send Message
    Yedp polycounter lvl 7
    Hey, thanks for the answer, yeah I know this is just a crazy idea mostly when you already have an attribute to control it but yeah I just wanted to explore possibilities, I'm thinking that maybe if there's a way to check the brightness/darkness of a pixel on the object/texture it would be possible to control the attribute more accuratly as well but this seems pretty hard to do and I'm no expert in programmation or anything I'm just curious, I'll look into it though.
  • Kurt Russell Fan Club
    Options
    Offline / Send Message
    Kurt Russell Fan Club polycounter lvl 9
    Id say if you ever did script it, you'd want to do it over time as well. Just making the iris close or dilate based on light would mean it was instantly the right size.

    You'd want it to be lit/in shadow and over a half-second or so to close/open as it adjusts to the light.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    I think this would be a combination of a script node with a script job. Definitely an awesome exercise.
Sign In or Register to comment.