Simple interior tutorial using Lightmapping

From Kray
Jump to: navigation, search


This is a quick tutorial that will guide you through the most important steps of setting up Kray for LightWave.

You can download the scene files here: Lightmap tutorial

Setting up LightWave

First we need to set LightWave ray trace flags to work nicely with Kray's GI. Go to Render Globals panel and check that you have following options right.

This will ensure that GI bounces correctly through transparent surface, casts proper shadows and calculates reflections right.
ITSC Capture 01.png

The next thing I usually do is add motion modifier SunSpot to my main Sun light so that I get correct position of the sun. This also places sun 1km away which we'll use later for Inverse Distance^2 falloff distance in light panel.

ITSC Capture 03.png

Now open your lights properties and set your sunlight to Spot light with Inverse Distance ^ 2 fallof distance of 1km (the distance from Sunspot modifier). Also increase Light Intensity to 150% or 200% or more depending on your taste.

ITSC Capture 02.png

Now our scene is still lacking some global illumination from sky so we'll add sky light. Hopefully you have Skylight plugin installed which is a wonderful plugin from Denis Pontonnier. Note: there is now a newer version of skylight plugin available called SunSky. The new one is even better and more configurable so use that one if you want.

I usually set my sky to values as you see in screenshot below.

ITSC Capture 04.png

Setting up Kray

Quick setup

When you open up Kray you'll be presented with general setup screen. First we'll do quick preview of the scene. Select Low preset from dropdown list which will set all presets on the other tabs to low. This should give us quick preview of light and mood. Also make sure you selected Photon mapping and Cache irradiance is checked. Photon mapping with cache irradiance is the fasted method to render your GI scenes and you're not likely to ever use any other mode except for testing or preview. I've also turned Gamma parameter to 1.6 to make room a bit brighter since 1.0 makes it very contrasty.

ITSC Capture 05.png

This is what you should get in a couple of mins after you press render.

Kray render00000.jpg

Optimizing Photon settings

Okay, you can see in our last render that the GI solution is really smooth but it lacks a lot of contact shadows. This is due to low settings we use. We're going to improve them step by step now. First we're gonna setup our photons right. Switch to Precomputed mode:

ITSC Capture 06.png

and make a render.


This render shows, in simplified explanation, cells where indirect light was computed (sampled). Now the cells are pretty big and the whole image doesn't look too smooth. Each cell contains bunch of photons that have been blurred together to form a cell. We will need more cells to get better accuracy in shadows. We'll tweak that in Photons tab. First switch photon preset to Medium. This preset will raise number of photons and some other not so important settings.

ITSC Capture 07.png

Render out a frame.


You can see in the above render that irradiance is smoother but you cannot really see any shadows forming under sofa for example. This means it will be hard for Kray to produce accurate shadows in Photon map mode. If you checked closely at render log it wrote something like this:

ITSC Capture 08.png

This means that 4700 cells were created for irradiance. That's quite low for a scene like this... We should be getting 30.000 cells rather or something around there... We're gonna try to raise our cells first by turning on Auto for Gi resolution.

ITSC Capture 10.png

This effectively controls how samples are grouped together or something like that. The higher the resolution the bigger the cells will be... When you render a frame this is what you get:


The cells look much smaller actually they're even a bit too small now, and you can clearly see shadow under the sofa. Quite a few splotches have appeared though: this is because Kray wasn't able to smooth out photons well since filter settings (N and irradiance blur) were too low. We're gonna fix that by lowering number of photons. This way each cell will contain less photons which will filter out better. Let's try 300.000 photons instead if 600.000.

ITSC Capture 11.png

If you checked render log you saw there were about 17.000 cells created. That's quite alright. The irradiance isn't completely smooth yet but it should work alright. I'll explain how to get precompute even smoother in advanced users section. You can skip that if you want to go straight to FG.


Advanced tweaking

To get smoother precomputed render you have couple of advanced controls in photons tab. First you have to select custom preset which unlocks all advanced features.

ITSC Capture 12.png

The most important settings are:

N: this is the number of photons that will be filtered togather - hence making smoother irradiance.

Precache blur: this just blurs irradiance making it smoother. (I like using this one instead of N since it's a little bit faster)

Precache distance: this setting will control cells size. If you increase it cells will get larger, lower it and cells will be smaller.

Optimizing FG setting

Next we'll go and optimize settings for a better GI. FG or Final Gathering is the final stage of "photon mapping" rendering. What it does is it computes GI only at important points in an image. This points are selected more densly by Kray on places where it is most likely for a shadow to occur.

First we need to change Diffuse model on General tab to Photon mapping with cache irradiance turned on.


Then let's turn FG preset to Medium.

ITSC Capture 13.png

and see what we get.


Now that's not bad at all! Thank you for your attention and happy rendering! [[Image:]] just kidding... The outcome is quite good but we'll do some optimizing just to show you what you can tweak. From here on we'll go more deeply into how to optimize Kray. One of the most important things with FG is correct density of samples. If the samples are spread too far appart the shadows will look blurred, if they're too close you'll need more rays to get clean rendering. We have couple of controls to control this. The most important ones are:FG threshold, FG rays min and FG max.

FG rays min is the minimum amount of rays Kray will use at specific point. FG max is maximum number of rays at specific point. FG Threshold is the difference between to sampled points. When the difference is bigger than specified value Kray will increase number of rays untill it reaches maximum number of rays (FG max).When number of rays are too low, you will begin to see splotches. When number of rays are too high you'll get longer render times than needed. So the trick is to find a balance between render times vs. quality. We will first check where Kray computes FG points. To do this we need to turn Prerender to 0%, next turn on Show samples All and just for the sake of faster rendering let's turn FG rays max to 100. Also go to sampling tab and set Antialiasing to None.

ITSC Capture 14.png
ITSC Capture 16.png
ITSC Capture 15.png

We get this render:


You can see how Kray places samples (the pink dots) at "strategic" places where it expects shadows to occur. On large flat areas there are very few sampled points because Kray knows lighting won't change much there. On places around corner there are alot more samples to accurately compute shading. The density of samples seems a little sparse in the above image so we will make them closer. We can do that with couple of advanced settings so this is the part where we will unlock "advanced settings". Select Custom from the preset list and settings will get unlocked. The setting that influences density of samples the most is Spatial tolerance. Right now is set to 0.2 but we'll set it to 0.1 and how density of samples changes this way.

ITSC Capture 17.png

You see how the samples are positioned much closer now. This will create more accurate shadows in those places. We can further tune samples with following settings:

ITSC Capture 18.png

Distance Min/Max : this controls minimun and maximum distance between samples. If min and max are exactly the same, samples will be distributed equaly appart across all surfaces (and we don't want that). B/D : this value will add more samples but only to places with high light contrast (corners). This can further improve quality of shadows if needed. I like to keep this value between 0-100% depending on the scene.

This is image with B/D set to 0%. You can see how samples in corners are not as dense as before.


I will now turn B/D to 50% since default 100% seems a bit high...


This looks good to me, we're gonna turn off Show samples now and tweak FG rays. Let's try this settings first and see if it's good enough: FG threshold = 0.0001, FG rays min = 100, FG max = 600.

ITSC Capture 19.png

That looks pretty cool. You can see we get better shadows now than before when we used medium preset. I can't see any splotches either. I think I'm gonna try with even lower FG max to get faster results. Let's try... hmm.. max 300.


You can start seeing some artifacts in the corners and shadows start to fade away also... But we gained 2 minutes. So it's up to you to decide which way you want to go. All there's left now is add some antialiasing. We'll cover Antialiasing in some other tutorial since that needs a bit more explanation. For this tutorial I'm just going to select a medium preset for a start and then customize some settings. Upsample' we can turn to 0 since this is used when you have fine details in your image that normal resolution cannot capture. Z' distance is also a little bit low so I'm gonna turn it up a bit. That's it.

ITSC Capture 20.png

Final words

Here's our final image. (yea I know it needs some surfacing and lighting polishing but that's where you come in!)


Here is a final scene file if you wan't to test it yourself... Hope you enjoyed this and I hope to hear your questions and comments!