daveborck
July 25, 2025 13:22:49
Hi,
I need to make a shader using materialx that is white when seen in camera view and black when offscreen. So far the only way I managed to do that is using mtlxposition with camera_path:ndc plugged into texcoord of mtlximage node where I can put a white image and make everything outside black with Default Color parameter.
That sounds very awkward though. Is there more procedural way that doesn't require a white image?
Thanks for any suggestions
Dawid
Tanto
July 25, 2025 13:53:46
Sorry, can't upload a file, so here goes:
Separate your ndc position into three floats.
For the X and Y components: subtract 0.5, and find the absolute value of the result.
Plug that into a If greater conditional, so that if greater than 0.5, value is 0, otherwise, value is 1.
Do that for both X and Y, multiply both together, and plug the result into all inputs of a combine3.
vicvl92
July 26, 2025 02:02:48
Tanto
Sorry, can't upload a file, so here goes:
Separate your ndc position into three floats.
For the X and Y components: subtract 0.5, and find the absolute value of the result.
Plug that into a If greater conditional, so that if greater than 0.5, value is 0, otherwise, value is 1.
Do that for both X and Y, multiply both together, and plug the result into all inputs of a combine3.
Wow, I happened to need exactly this kind of effect — thank you so much for the tip!
Is there a way to adjust the edge sharpness without affecting the core matte?
Tanto
July 28, 2025 11:26:25
vicvl92
Sorry, can't upload a file, so here goes:
Wow, I happened to need exactly this kind of effect — thank you so much for the tip!
Is there a way to adjust the edge sharpness without affecting the core matte?
Sure, instead of using If greater, use a Range:
inlow: 0.5
inhigh: 0.6
outlow: 1
outhigh: 0
Adjust inhigh and gamma as needed for your desired falloff.
daveborck
July 30, 2025 11:27:07
Finally had time to test it and it worked very well indeed!
Thanks a lot, very clever
vicvl92
Aug. 2, 2025 08:16:31
Tanto
vicvl92
Sorry, can't upload a file, so here goes:
Wow, I happened to need exactly this kind of effect — thank you so much for the tip!
Is there a way to adjust the edge sharpness without affecting the core matte?
Sure, instead of using If greater, use a Range:
inlow: 0.5
inhigh: 0.6
outlow: 1
outhigh: 0
Adjust inhigh and gamma as needed for your desired falloff.
Hi Tanto, thanks for the reply. I got one more question to ask.
I was trying to extract the matte from the backface based on the camera’s view angle. But it doesn’t seem to work as expected on single-sided geometry like the grid plane and torus inner face that shown in the screenshot — probably because it doesn’t have depth (Z coordinate). Do you know how to achieve this effect? Here’s what I’ve tried so far(not sure i am doing right or wrong):
vicvl92
Aug. 5, 2025 05:47:38
Gladly, I found the solution.
Here's the workaround: