I have to add rendered trees to a photo. As I've never done any comping like this (and never used render elements), how should I go about it in TG and Photoshop? I need the trees and a mask to eliminate any TG background and atmo, and paste just the leaves/trunk over the photo. So I will probably need a certain render layer. But which one?
I also need the shadows without any ground, separately I guess. That can probably just be multiplied over the photo in photoshop.
Can anyone enlighten me?
(https://media.discordapp.net/attachments/1297828493446479902/1297828493714788382/TG_trees_over_photo.jpg?ex=67175879&is=671606f9&hm=1e6fe454965002a006522d032b93e0c24cd128b5ac60e0a8bd15d8b473165abd&=&format=webp&width=525&height=350)
Hi Dune,
Great question. First let me point you to the online documentation for compositing Terragen render elements. In this wiki, we used Fusion as our compositing software, but you can substitute Photoshop for it along with the appropriate Photoshop blending mode: https://planetside.co.uk/wiki/index.php?title=Compositing_Terragen_Render_Elements
To help you understand "all" the render elements, think of it like this. A normal render from Terragen outputs a "beauty pass"; that is, all the terrain, objects, atmosphere, lighting, etc. are taken into account and create the final image. Render layers allow the user to assemble these separate element back into the beauty pass.
The Render Layer window is divided into 3 sections. Each section allows the user to break down the render layers into more specific elements. For example, to recreate the beauty pass from Terragen, all you really need to start with is the SurfaceRGB, CloudRGB, and AtmosphereRGB render elements. If your combine these three render elements on top of each other in an additive mode, you'll get the beauty pass. This allows the user to modify each render element as they see fit. Perhaps changing the colour saturation of the SurfaceRGB element, or increasing the brightness of the cloud element, etc.
You can go deeper too, and that's what the second section is for. Here you can break apart direct lighting verses indirect lighting. All you need to do to recreate the "full" lighting is combine the two elements back together in additive mode.
The third section, the Data section, allows you to export other types of data such as zdepth, etc.
So for your project, think about what you might want to have control over in Photoshop.
My approach would be something like this. I would save a tiff file from the renderer's Output Image File param. This would give me a beauty pass with all the Terragen tonemapping and how I expect the final composited render element to look. If I thought I would only need to breakdown the render into "basic" parts, on the Render Layer's Render Elements tab I would enable the checkboxes in the first section. If your Terragen project has no clouds in it, you don't need to enable CloudRGB and CloudAlpha.
If you want to render your trees against a black background, group the tree objects together in Terragen, then assign the group to one of the Object groups under the Render Layer's Object tab. Set the group's render mode to Visible and enable Cast Shadows And Other Rays. Set the All Other Objects render mode to invisible, but you may need to enable their shadow casting and other rays, if they have an effect on the trees. For example, the buildings in the photo casting shadows on the trees.
One last note, if saving render layers in EXR format, Terragen's tonemapping will not be embedded into the EXR images. That's why I save the output image, in order to have a reference to how I want it to look.
I would be curious to watch the progress of your shot on the forum. Don't hesitate to ask questions, we're happy to help!
Great. Thanks very much Kevin! I'll do some experimenting and follow up on this here, once the commission is official.
Kevin's suggestions are great, however they might be a bit too cumbersome or inpractical with Photoshop. The 'problem' with EXRs and Render elements would be that they need to be composed in linear float 32bits which Photoshop is not really good at. Photoshop also doesn't support de-multiplying alpha so you'll have to tweak the alpha channel a bit.
Also, most production renderers mostly have dedicated background/matte materials that do not display in the render/alpha or let you specify how they look to the direct visibility rays and other ray elements like reflection, GI etc. Without it you need to get around that.
For the trees, I'd just save the final output as Tif (so it's gamma corrected plus has all the tonemapping baked in). For the alpha channel you'll need to disable direct visibility for anything else.
For the shadows, I'd simply render the trees on a white ground (plane/terrain) and just multiply it over your background image in Photoshop. You would probably need to do some level correction on this render because tonemapping will probably move your whitepoint to a non-white color. Or, if TG supports a shadow element, use this one. This will probably be linear so you'll need to apply a gamma correction on it.
If the ground is not flat you'll need to re-model the ground so the shadows 'follow' whatever the geometry is.
Thanks very much for additional info. I don't really know what demultiplying alpha means, but I guess I'll find out once I try this.
What do you mean by 'For the alpha channel you'll need to disable direct visibility for anything else'? You mean in TG's render elements settings?
I was also thinking of rendering twice; trees and shrub just floating (atmo set to secondary only) so I can make a transparent tif and easily paste over in PS, another render for shadows with trees set to invisible, indeed on a white ground and multiply over in PS.
I also thought about building the undulating ground, but I think that won't be necessary.
'For the alpha channel you'll need to disable direct visibility for anything else' - what I meant that whatever is behind the trees doesn't contribute to alpha, in case there's a terrain or something else behind it.
Yeah, in PS this 2 layer approach is quick and effective as it gives you good control for blending and correcting layers individually, and it's an easy setup here.
In my view, TG lacks quite a bit functionality in terms of composing even if you have a fully fledged comp app. No additional arbitrary mask buffers (so you could add only a few selected objects or items to a mask element), no matte/shadow shaders etc. Even if you went the render element way you'd probably end up needing to render different visibility setups forcing you to keep track what's enabled or disabled for each render setup etc. To be fair, this is sometimes needed even with all the options available.
Thanks for the quick reply. Going to work on it...
I can probably keep it very simple.
1: for only shadows set all tree objects to invisible, and render just planet (base color white) and atmo (whitened, haze raised), or a white background card. Multiply in PS.
2: render only the trees with all atmo on, but not rendering planet or atmo, resulting in floating trees on black.
The only thing then is that I need to cut out the trees by using the alpha. I don't think TG can export/save a transparent tif/exr? If I save the render as exr and open in PS as transparency, the black background is still there. So is there any way to really have only the trees?
Not sure, but it's a simple thing to do in PS. Or is there a reason you'd want the file already to be processed that way where pixels where alpha is black are already removed?
If TG saves to PNG you might try that one.
As for EXRs in PS - PS just doesn't support EXRs correctly, just expect it to do strange or unexpected things with it ;)
EDIT - this looks nice already! Sure, the perspective is slightly off :D
You might find this useful for generating a shadow pass:
https://planetside.co.uk/wiki/index.php?title=Shadow_Catcher_Shader
Alpha channels aren't included in TG renders in the normal way, but you can save the alpha to a separate image. One way to do this is to simply hit 'A' on the keyboard in the Render View and then save that image. Alphas can also be saved as Render Elements / Extra Output Images if you want to go that route.
If you did want to explore rendering out from TGD as Exr with render passes to Photoshop, you can try Exr-Io (https://www.exr-io.com/) it's a free download to import such files into Photoshop. It can handle channels and import them as layers i.e render elements (diffuse, specular etc) Seems later verisons of TGD can output the render elements in one Exr file, not tested as I'm not up to date with Terragen, but as a basic Exr importer it works very well.
Thanks guys! I did find a way to extract a transparent image from beauty pass and alpha in PS, but just wondered if a direct transparency would be possible from TG. Saves a process.
And indeed, I don't really like exr, and never save as such (always tif). Yeah, perspective could be better ;)
I'll check out the exr-io, and the shadow catcher, thanks!
The most difficult thing is to get the right angle, and POV. The focal length from the photo given to me didn't exactly match the angle I eyeballed, but I'm getting somewhere.
I still need to make the proper pathway (this was just an idea, which they need to approve), and some more stuff needed.
Dune, I think you mentioned that you had an older copy of Lightwave. It has a feature called "match perspective" that might help solve the camera position for you. You could export the camera solve as an FBX, or perhaps just type the coordinates from Lightwave into Terragen. Here's a video I found online about the feature: https://www.youtube.com/watch?v=wCZo1oDE7zo
Thanks Kevin. Very interesting feature. But I'm afraid my LW is ancient (2015), and I don't think it's in there. I'll check it out anyway.
Perhaps if I use a card in front of the camera in TG, I can project the image, and flip between world and card to match camera in TG by eyeballing, you've just given me that idea. With a glass shader, half transparent and RTP it may even work better. Just a theory ...
It`s in LW 2015.3 for sure.
CHeers, Klaus
I'm going to have a look, but I'm not that familiar with Layout, mostly use Modeler.
I did try my theory, and it kind of works. Problem is that the card shifts as well if moving/rotating the camera, so ther are two fields to work until it looks okay, a bit of a fickle way. So here's a feature request: make it possible to project a photo on the preview screen. Would that be easy/feasible?
Are you sure your TG camera matches the real world one? Did you match the focal length, sensor dimensions and image aspect ratio? To me it looks like your TG result has a wider lens.
I doubt it, indeed. Looks like the perspective in the render is 'deeper'. Photo was taken with 19mm focal length data said, but using that in TG didn't work with the base square - my main aim was to match the square field of grass with the lines in the pavement - lining up, so I eyeballed even lower, more wide angle (15ยบ). But the distant stuff moves away of course. Not easy at all. Lens distortion may also play a role, perhaps.
Do you know the crop factor of the camera that took the photo? That will impact the field of view. What reports in the meta data most likely won't translate to a TG camera. So if the camera has a crop factor of 1.5 and the lens is 19mm it will have an "effective" focal length of 28.5. I say "effective" as the focal length doesn't change - just the field of view (have a look at https://proedu.com/blogs/photography-fundamentals/crop-factor-explained-understanding-its-impact-in-photography?srsltid=AfmBOop5pqojaH4otw486eOZdumMMcxIrQo9NcEeMBig4NKX3jcCJp0P)
Lens distortion is also a factor, especially with such a wide angle focal length. It's common practise in VFX to undistort footage to match with CG elements then re-distort once the shot has been compostited, but that invloves shooting test grids to calculate the distortion (usually done in something like Nuke, but open source Natron can do it apparently) but if you didn't take the photo that wouldn't be an option.
A lot of this is perhaps beyond the scope of your project, but figuring out the effect of the cameras crop factor might get you closer to the right TG camera settings with more confidence.
EDIT: Assume you've done this but getting the the sensor size of the camera and setting that in the TG camera will be optimal. The default settings of 36 x24mm are for a full frame sensor which has a crop factor of 1.
Yeah, digitalguru is right.
Find out the camera model and look up its technical data, then use whatever the sensor size is for TG's camera sensor size, and then you can use the focal length from the image's EXIF data in TG without any conversion (e.g. crop factor).
It's important to use the same image aspect ratio, so if the image is 3:2, you need to use the same ratio in TG. Otherwise you might end up with different camera height and vertical rotation to match it, but it will inevitably lead to problems.
Lens distortion will play some role, too, and I second digitalguru's advice to apply optical correction in PS or Lightroom. It's negligible with some lenses or situations but since you need to cover a large area of the image, it makes sense to correct for lens distortion, too.
Let me know if you need more help with this, we can get in touch over email/skype etc. Setting this up correctly shouldn't take too long.
This is a quick LightWave thingie. The scene file for LW 2015.3 is attached as well.
CHeers, Klaus
Thanks very much for your replies, gents, very much appreciated! The metadata also said something about the camera, some Canon, I'll have to look it up. Very understandable, the article about cropfactor.
And thanks for the offer for more help on this, but I just got a mail from the client that they (suddenly) have budget problems, and would I mind letting it rest for a while ::) Well, it's an interesting subject, and may come up again anyway (or later), so efforts weren't wasted at all.
I'll check out LW 15 too, Klaus, thanks!