We’ve considered a lot of options here, and have come to three solutions that should work (almost) perfectly based on your specific needs (of course, some settings might need tweaking). We’ve also considered using custom attributes and expressions, but the setup gets too complicated. So here’s 3 setups that require a minimum amount of setup time and should (hopefully) work for you.
All setups rely on the singleShadingSwitch, where all of your objects but one receive a constant float value for the bumpMult, then the one object receives a value based on some calculations.
1. VRayFalloff
A VRayFalloff texture is set to distance blend based on camera Z. You’ll need to tweak the far/near range. The texture outputs 0-1 values based on what color is used. The output is fed to a condition node, which clamps the value to either 0 or 1 based on the 0.5 mid value (i.e. if output>=0.5, then 1, else 0). The ‘1’ case hardcodes a 1 value to be used for bumpMult, otherwise we hardcode a 0.1 value for bumpMult, and the condition feeds into VRayMtl.bumpMult.
Pros: easy to setup
Cons: Works on pixels, not objects! This means that if part(s) of your ‘special’ object is on one side of the near/far distance range, while the rest of it is on the other side - it will receive different bump mults based on what pixels it takes in the image. I suppose this could be used in a scenario, where your character does *not* come gradually closer to the camera, but instead you have different cameras for the mid-shots and the close-ups. So - use with caution.
2. Distance between with pre-frame MEL
A distanceBetween node gets you the distance from an object to the camera. I’ve used a sphere (the two cubes are the ones with constant mults).
The problem here is switching the cameras. To avoid having too many nodes, I’ve used a MEL scripts that looks up the current camera and connects it to one side of the distanceBetween, while the sphere is always connected.
The script is executed pre-frame, and checks if the camera actually needs changing to avoid any errors/warnings printed. I’ve inserted some debug prints that you can remove, but the scripts is:
string $cam = `vrend -query -camera`;
string $connected[] = `listConnections -t transform distanceBetween2`;
if ($cam != $connected[1]) {
connectAttr -f ($cam + ".worldMatrix[0]") distanceBetween2.inMatrix2;
print ("\n=== Connecting camera " + $cam + " ===");
} else {
print ("\n=== Camera " + $cam + " already connected ===");
}
Note: in my case I’m relying on having my sphere always connected to the first matrix input (index 0) of the distanceBetween, and the camera - always to the second one (index 1)!!! (Can be improved, didn’t have the time).
Pros: Works on objects, not pixels.
Cons: requires scripting
3. Distance between with post-translate python
Same as the previous setup, only the camera does not actually ‘change’. I’m feeding the distanceBetween with the transformation of the renderView plugin (essentially the camera) that gets exported after the scene is translated to VRay in memory (or to vrscene on disk).
Since you can’t have more than one camera in a vrscene, whatever new camera is used for your frame/sequence/etc is translated as a single renderView plugin. I’m always getting that exact transform to feed the distanceBetween.
Essentially, the code is shorter and is used as post-translate python access to the exported vrscene (works for gui renders, batch renders and vrscene export that goes to a render farm/standalone).
from vray.utils import *
dist = findByName('distanceBetween2')[0]
cam = findByType('RenderView')[0]
camT = cam.get('transform')
dist.set('transform2', camT)
Pros: works on objects, not pixels.
Cons: requires (less) scripting. Camera is changed only in Maya, can’t be changed after the vrscene is exported.
Notes: There might be some tweaking required to get this to work, but let me know if you come across any problems.
Also - let me know if you can use these setups, I don’t know much about your project other than what you’ve shared here, so I might have missed a detail that you need to account for.
In any case - I hope you find this helpful. Let me know if there’s anything else.
SCENE FILES: custom_bump_mult.zip
I’ve not included the texture used for the scenes, just use any normal map.
custom_bump_mult.zip (176 KB)