2
$\begingroup$

Not entirely sure how to concisely describe this (or what to Google for). I guess it can be done somehow by using conditionals on the light path..?

I have this scene:

enter image description here

Basically, a "terrain" mesh, and two flat planes intersecting it. Now, I would like to apply a certain texture on the "Yellow" plane, but only on the area directly over the terrain, not over the blue plane.

It's probably clearer what I mean in a top view:

enter image description here

(The clearly yellow area).

The idea is to get some combination of nodes that will give me a 0 or 1 result I can use as "factor" to a mix shader.. but I got stuck trying to find how that could actually be done.


Update: to clarify, I want to apply the texture in the region hit by "vertical" rays, i.e. parallel to the object normals / Z axis, not the camera ray.

$\endgroup$
  • $\begingroup$ It seems the intersecting object is just a flat plane. Is it true for all possible cases? $\endgroup$ – Martynas Žiemys Sep 9 at 10:30
2
$\begingroup$

You need to use the Geometry node with drivers

enter image description here

  • Basically Blender analyses each every portion of the mesh, and for that portion the Geometry node returns its position.

  • The Separate XYZ node extracts the height from that position vector

  • The two Value nodes get their input from two drivers (in the picture there is one of them) that copy the Z position of the two planes

enter image description here

  • With the two Math nodes, set to Less Than, you calculate if that mesh portion is under one of the two planes. The values you get are 1s (White) or 0s (Black)

  • You can use those values as the factor input of two Mix shaders to get your final color

Of course if you have textures you can put them instead of the RGB nodes, replace the Mix nodes with Mix Shaders


EDIT

This is your setup in case of horizontal planes. In case of tilted planes there is more math involved, but it's absolutely possible

$\endgroup$
  • $\begingroup$ Cool, that works great! I was actually looking to get it to affect the material on the "top flat plane" rather than terrain.. I guess that could be done using some more math between the objects, via drivers? I'm going to play with it a bit now. $\endgroup$ – redShadow Sep 9 at 12:10
0
$\begingroup$

Tareyes' answer is probably the best solution, but you could also use a transparent material as the intersecting object and then use Transparency Depth to separate the shaders in the main material:

enter image description here

You can have a few layers with geometry(solidify modifier maybe) and if you needed other transparent materials not to cause the effect you could replace Transparent shaders with Refraction BSDFs with IOR of 1 as transmission in materials is treated differently than transparency.

$\endgroup$
  • $\begingroup$ Nice solution, but there are 2 problems: 1)This method uses the camera rays, so in your video you can see that at the bottom there is a spot that is under the transparent plane, but since the camera is tilted it is directly visible, therefore its painted blu while it should be red. 2)The Transparent Depth it's not object specific so you can't use 2 planes like in the question and you can't even have other transparent objects in your scene (because it would paint it red where it shouldn't) $\endgroup$ – Tareyes Sep 9 at 11:36
  • $\begingroup$ Sure this has limitations, but in some simple situations it might be useful. It's nice that glass shaders still work fine since they are transmission and not transparency. One could use Refraction BSDF shader with IOR of 1 to replace transparency. You can also have layers because Transparent Depth could be chosen simply by adding to it with a Math node(bviously at the cost of having more geometry). Anyway that's just an addition to your solution that is more complete in my opinion. $\endgroup$ – Martynas Žiemys Sep 9 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.