Clarification, May 31st 2017: User Firewill kindly provided an answer for the first version of the problem I stated, but I think I was after a more broadly applicable solution, so I'm re-stating my problem here in the hope that it helps solicit that.
As far as I can tell when using cycles freestyle to draw lines, those lines are placed on top of the rendered scene, so none of the objects in the scene get to interact with them in any way.
Take for example the scene below. The glass cube refracts light and effects the way we see the other items:
To emphasize the effect it has, let's overlay an image on the plane so we can see how the glass cube distorts and reflects a grid:
Super. Now let's see if we can draw that same grid with freestyle and see how it looks. First, take the plane, select its edges, and use "Mark Freestyle Edge":
Now render the scene. Oh dear, that's not at all what we were after. No distortion of the grid, no reflection of the grid, no hiding or coloring of the grid.
So, my question is, could I use compositor to render the plane and its freestyle grid together, then "re-insert" it into the render flow so that it can interact with everything else? Giving us a result like this, but with all the benefits of freestyle:
If it helps, here's the blend file for that scene:
Thanks very much for any help you can offer.
Original question: I have a mesh terrain, and a cube that intersects it to form the surface of a lake.
Here you can see how I've roughly thrown that together, with the cube placed underneath the mesh, poking through it to form the lake surface:
Here's what that looks like when it's rendered:
I'm then using freestyle to draw lines along the terrain's visible edges. Unfortunately the lines aren't drawn beneath the surface of the lake water, because freestyle thinks they aren't visible.
To correct this I initially tried using the QI Range setting in freestyle to additionally render the lines below the water, however that came with two problems: firstly other unwanted hidden lines in the scene were also rendered (those hidden behind the hills); and secondly the lake bottom lines were drawn on top of the water, and so didn't appear to be "hidden in the depths".
Here I've rendered only those hidden lines, to illustrate the problem:
Since I couldn't solve my problem with QI Range my next thought was to render the terrain and freestyle lines as one image, the water as another, and then combine them in the compositor.
However, while I've done some simple experimenting with the compositor, I can't for the life of me think how to achieve the effect I want with it. Does anyone have any advice? Or am I trying to solve this in a silly way?
Here's a blend file where you can more clearly see what I'm working with:
Update, May 30th 2017: I've done some more fiddling and broken out the land, water, and freestyle lines into their own layers. I'm rendering then combining the land and freestyle lines (which works great), and then trying to add in the water afterwards. However that step doesn't really work out as I just end up with a cube of water plonked on top of the land, and the lake floor in that part doesn't include the freestyle lines (I'm not sure how to get them in there).
Here's the file that produced all that:
I'm sure I'm missing a pretty obvious bit of knowledge about how compositing works. Could anyone with more savvy in this area explain what I should do to get all of this combined?
Thanks for any advice you can offer.