Forums > MaxMSP

Reflecting colored light… jit.expr question, what else? float and int issues?

September 19, 2011 | 6:11 pm

I am trying to modify one video stream based on another video stream, and I am trying to use jit.expr. What I am trying to so is:

output pixel = video1 * (video2 / 255)

The jit .expr I am trying to use is:

jit.expr @expr in[0]*(in[1]/255)

If the "/" is a "+" then I get output, the "/" gives me black pixels. I basically want to stay in integer land which "+" does but I know that "/" gets me into floats.

I checked my math in excel and it works. What I am trying to do is:

video1 = a colored light source
video2 = a colored background

The math is to modify the "reflected light" seen based on the color of the background. I am assuming that the RGB values fall into 0 to 255. Are there some float versus integer/char things going on? Do I have to force conversions? I looked all over that’s why I am here now…

Am I crazy?


September 19, 2011 | 7:05 pm

Hi Neal,
You don’t need to divide by 255 in this case. Jit.expr natively processes everything as float32, so char values are converted to 0.-1. before running the expression. In the case of char input, jit.expr will convert back to char at the output as well.


September 19, 2011 | 7:15 pm

Andrew,

Thanks for the feedback… What I am trying to do is calculate the color of a reflected colored light from a colored surface. So I want to know how much red is in the surface pixel so I divide the red amount R by 255 to get a percentage. I then multiply the incoming light by this percentage to know how much red to reflect back. I am doing this for each R G B channel. My math seems to return black if I do it to all the channels.

output pixel red = video1 pixel red * (video2 pixel red / 255)
output pixel green = video1 pixel green * (video2 pixel green / 255)
output pixel blue = video1 pixel blue * (video2 pixel blue / 255)

If I do only it to the blue I get video but darker. If I add green the video is even darker, add red, just black. Are my math assumptions wrong?


Viewing 3 posts - 1 through 3 (of 3 total)