Krakatoa Shadows Generator¶
Available in Krakatoa 1.6.0 and higher.
Overview¶
- The Krakatoa Shadows Generators appears on the list of available shadow types on 3ds Max lights.
- It also provides a sub-type for casting shadows from geometry onto geometry.
- The Krakatoa Shadows Generator provides a file name for each light.
- When rendering in Krakatoa with >Save Attenuation Maps checked, it writes a multi-layer OpenEXR file for each frame, containing depth and opacity information at one or more depths.
- When rendering in Scanline or V-Ray, it reads from the OpenEXR file for the current frame and calculates shadows based on the depth and opacity data. If the specified file is not found, an error will be thrown.
User Interface¶
- The Krakatoa Shadows Generator implements the following UI controls:
Load Path text field¶
- This text field contains the absolute path to the Attenuation Map to be loaded when rendering in renderers like Scanline or VRay.
- The text field can be set manually or automatically when rendering in Krakatoa and saving Attenuation Maps with the Auto Update On Render option checked.
Save Path text field¶
- The text field shows the path to save Attenuation Map EXR files to when rendering in Krakatoa.
- The path can be an absolute path to a fixed disk location
- The keyword $renderdir can be used to replace a portion of the path with the current Render Output path set in the Render Setup dialog.
- The keyword $objectname can be used to replace a portion of the path with the name of the light the Shadow Generator belongs to.
- The default path is $renderdir$objectname_0000.exr which means that the Attenuation Map will be saved to the same path as the Render Output and will be named according to the Light’s name.
- It is possible to mix the two methods for specifying the path, for example
- $renderdirshadows$objectname_0000.exr will save to a sub-folder of the render output path.
- c:temp$objectnameshadows_0000.exr will save to an absolute path c:temp into a sub-folder named according to the light’s name with a static file name “shadows_0000.exr”
Pick A Save Location… button¶
- This button can be used to open a save file dialog to specify the absolute path to save the Attenuation Map to.
Auto Update On Render checkbox¶
This option controls whether the Load Path will be updated to the current Save Path when an Attenuation Map is saved by Krakatoa.
- When checked (default), each time Krakatoa saves an Attenuation Map, the Load Path will be updated to the current absolute version of the Save Path automatically.
- When unchecked, the Load Path will not be changed automatically and saving new Attenuation Maps to new paths will not switch the Shadow Generator to use them.
Note:
The above can be useful when a version of previously saved Attenuation Maps is to be used in renderers other than Krakatoa while new versions of the Attenuation Maps are still being produced (for example in multiple test runs until the final look is achieved). In other words, unchecking the Auto Update On Render option lets you “freeze” a specific version of the Attenuation Map rendered previously to be used outside of Krakatoa.
Resolution spinner¶
- This value defines the resolution of the Attenuation Map.
- This value is similar to the Shadow Map Size value, but is independent from it.
- When combining Krakatoa Shadows with Shadow Maps, it is a good idea to keep the two resolutions the same or similar.
Sample Count spinner¶
- This integer value defines the number of samples to store in the Attenuation Map. The default is 1.
- When saving one layer, the Z-depth layer will contain the distance from the light to the closest particle, and the only sample will be taken at a distance controlled by the Sample Spacing spinner.
- Geometry between the first particle and the first sample will interpolate linearly.
- Any geometry beyond the first sample will use the first sample’s attenuation value as a constant value without interpolation.
- When the Sample Count is greater than 1, there will be multiple samples taken at equal distances controlled by the Sample Spacing value along the ray behind the first particle’s depth.
- A geometry object inside the shadow volume that falls between samples will interpolate the shadow value based on the closest two samples.
- If it is farther than the last sample, it will shade with the value stored in the last sample just like in the first case with one sample.
- See the sub-topic Understanding The Sample Count and Spacing Parameters below for details.
Sample Spacing spinner¶
- This value defines the distance between samples along the light ray.
- See the Sample Count topic above and the sub-topic Understanding The Sample Count and Spacing Parameters below for details.
- The default value is 1.0 Generic Unit.
Exponential Spacing checkbox¶
- This option controls whether the Sample Spacing is incremented linearly or exponentially.
- When set to true (default), the distance between the samples will increase exponentially, thus capturing more detail in the beginning of the range and less in the darker areas far away from the first sample.
- When set to false, the distance between the samples will be uniform and equal to the Sample Spacing value.
Geometry Shadows On checkbox¶
- This option controls whether the Geometry Shadows generator (see below) will be applied when rendering outside of Krakatoa.
- By default, this option is checked and the Krakatoa Attenuation Maps will be combined with the specified Geometry Shadows generator to produce the full shadowing from both particles and geometry objects.
- When unchecked, only the Krakatoa shadows will be applied (for example for test renders when trying to analyze the look of the Attenuation Map without the influence of the Geometry Shadows, or when creating a fill light that should pass through geometry but still cast shadows from particles)
Geometry Shadows drop-down list¶
- This list contains all other installed Shadow Generators except for the Krakatoa Shadows.
- It can be used to define the method for casting regular shadows from geometry onto geometry.
- When rendering in Krakatoa, it won’t be used at all.
- When rendering in another renderer like Scanline or VRay, and if the On checkbox is checked, it will be combined with the shadows from the Krakatoa Shadows Generator to produce the final shadow including particles to geometry and geometry to geometry.
Understanding The Sample Count and Spacing Parameters¶
- The quality of the volumetric shadow produced by the Krakatoa Shadow Generator depends mainly on the Shadow Map Size and the Sample Count and Spacing Parameters.
- While the Shadow Map Size is easy to understand and is similar to the Shadow Map Size of the regular Shadow Map Generator of 3ds Max, the Sample Count and Spacing Parameters require a closer look.
The Theory¶
- The 3ds Max Shadow Map is a Depth Map which contains the Z distance from the light to a surface point where the shadow begins - any geometry surface beyond that distance will be considered in shadow.
- The Krakatoa Deep Attenuation Map is different in that it contains both a Depth Map defining the beginning of the shadow just like with the 3ds Max Shadow Map, and one or more Attenuation samples at user-defined distances behind the starting point defined by the Depth Map.
- The Krakatoa Shadow Generator assumes that the Attenuation value at the distance from the light source defined by the Depth Map value is equal to zero (no attenuation). Thus, the Depth Map represents the FIRST sample of the map and its Attenuation value is always zero.
- If the Sample Count is set to 1, one Attenuation Sample will be stored in the Deep Attenuation Map file, but it is in fact the SECOND sample after the 0 value at the Depth Map distance from the light.
- A surface point that has to be rendered within the range between the Depth Map sample (Attenuation 0) and the first sample (0 < Attenuation <= 1) will be shadowed by linearly interpolating the values of the two samples based on the point’s position within the range.
- If the Sample Count is greater than 1, additional Attenuation samples will be taken either at exponentially longer or at equal distance behind the previous Sample (depending on the Exponential Spacing option) and their values will also be linearly interpolated to determine the amount of shadowing of a point that lies between them.
- If a surface point rendered in Scanline or another non-Krakatoa renderer lies beyond the last available sample stored in the Deep Attenuation Map file, it will use the value of the last Attenuation layer WITHOUT any interpolation. This means that the shadow behind the last sample taken will appear constant even if this does not reflect the actual density of the particle volume.
Example Setup¶
- Now let’s take a look at a simple practical test which will visualize the above rules.
- The demo setup consists of a Box Primitive with size of 100x100x100 Generic Units turned into 10 million particles with random distribution via a PRT Volume.
- A Spot Light illuminates the Particle Box from the right side along the negative X axis.
- A Camera is looking at the Particle Box along the positive Y axis.
- A diagonal Plane connects the farther right vertical edge of the box with the front left edge of the box. This plane will be used as the “screen” that will receive the shadows when rendering in Scanline.
- A Krakatoa Shadow Generator with Shadow Map Size of 512 and various Sample Settings is used in Krakatoa to generate Deep Opacity Maps which are then rendered in Scanline and get projected onto the diagonal plane.
Linear Sampling Test Results¶
- For this test, we will turn off the “Exponential Spacing” option and see how sampling at equal distances affects the quality of the shadows at various Count and Spacing settings.
- First, let’s see what happens if we set the Sample Count to 1 and the Sample Spacing to 10.0.
- Since our particle box is 100 units thick, the Shadow only “knows” about the first 10.0 units inside the volume and the rest of the illuminated diagonal plane is in constant shadow beyond that point.
- Note that we are using a spot light so the light rays enter the volume under different angles. This causes the bright stripes on top and bottom of the shadow because the light ray exits the volume before it can take the second Attenuation sample and the value stored reflects the lower density of the volume between the light and the sample point.
- Next, let’s keep the Sample Count at 1 and increase the Sample Spacing to 50.0.
- The result is half of the plane showing linear interpolation between 0 and the Attenuation values sampled at 50.0 units behind the point where the light ray entered the volume, the rest of the plane has constant shadow value.
- Now we increase the Sample Spacing to 100.0 while keeping the Sample Count at 1.
- This way, we get the shadow within the whole volume of the particle box interpolated linearly.
- But we have to keep in mind that the falloff inside the volume is in reality exponential and a single sample cannot reflect this correctly.
- Let’s increase the Sample Count to 5 but reduce the Sample Spacing to 10.0 units.
- This will give us 5 samples within the first 50.0 units of the volume and constant shadow beyond that.
- This is obviously incorrect - only half of the volume is represented with a closer approximation of the exponential falloff.
We can of course increase the Sample Spacing to 20.0 units while keeping the Sample Count at 5. This reduces the quality of the sampling in the first half of the volume a bit, but reflects somewhat closer the correct falloff within the whole volume of the particle box:
- Finally, let’s take 10 samples every 10.0 units to get some finer quality shadows within the complete volume:
- As you can see, this shadow is quite similar to the previous one, but has twice as many samples.
- The file size of the Deep Attenuation Map file is 2,549,890 bytes, as opposed to 1,470,769 bytes for the 5 samples / 20 units map above.
- Thus, if the quality of the above map is good enough, you can save a lot of disk space by using less samples with a longer step.
- All 1 Sample maps produced Deep Attenuation Map files of 604,517 bytes size, but they should only be used if the object in shadow is BEHIND the particle box and NOT INSIDE the volume.
Exponential Spacing¶
- For the following tests, we enable Exponential Spacing.
- The following rendering used only 2 Samples with Spacing of 30.0 units.
- Thus the first sample after the initial hit was at 30 units and the next one at 60 more units, covering a range of 90 units.
- Pixels farther than 90 units used the value stored in the last sample.
- As you can see, with only two samples we get a fairly smooth result:
- The next rendering uses 3 Samples with Spacing of 15.0 units.
- This means that the first sample after the initial hit is taken at 15.0 units, the next one 30.0 units farther and the last one 60.0 units behind it.
- This covers 105 units, so all pixels of the plane are covered by valid linearly interpolated values.
- The next rendering uses 5 Samples with Spacing of 5.0 units.
- This means that the distance between the samples grows like this: 5.0, 10.0, 20.0, 40.0, 80.0, with the first four samples covering a range of 75 units and the last 25 units interpolated based on the last sample at 155 units.
- The right image shows the Linear 5 Samples, 20.0 units Spacing rendering shown earlier for comparison:
- Finally, here is a comparison of 10 Samples, 0.15 units Exponential Spacing vs. 10 Samples, 10 Units Linear Spacing:
Conclusion¶
- The Sample Count and Spacing of the Krakatoa Shadow Map let you sample the particle volume at one or more layers behind the beginning of the shadow.
- The Sample Count of 1 should only be used when the geometry object(s) to receive shadows do not penetrate the Particle cloud and are behind the whole volume.
- In that situation, they will always receive the same shadow amount regardless of the number of samples stored in the Deep Opacity Map.
- The Sample Count should be increased when one or more geometry objects intersect with the volume in order to produce correct shadows falloff across the surface of the object within the particle volume.
- The Sample Spacing should be set to produce enough samples to reflect the exponential nature of the Opacity Falloff within the volume.
Krakatoa Shadows Manipulator¶
- When a light with a Krakatoa Shadows Generator is selected and the Manipulate Mode is turned on, a Manipulator Gizmo will be drawn around the selected light representing the Sample Spacing and Count visually and allowing tweaking of these values without using the Command Panel:
- There will be two or more gizmos, either circular or rectangular, representing the beginning of the shadows (which is assumed to be at 40 units from the source but can be tweaked) and the samples taken along the light ray.
- The first gizmo will be bright orange and cannot be selected. In its center, an orange circle can be used to manipulate the location of the shadows start. This value is NOT used by the Shadows Generator and is for visualization purposes only!
- A green + marker above the center of the first gizmo can be clicked to add more Samples to the Krakatoa Shadows Generator.
- A red x marker below the center of the first gizmo can be clicked to remove Samples from the Krakatoa Shadows Generator until the value reaches 1.
- The second gizmo represents the first sample plane at a distance equal to the Sample Spacing. In its center, a green circle can be used to move the location of the first sample plane and thus define the Sample Spacing interactively.
- If the Sample Count is greater than 1, there will be more gizmos with gradually changing color towards red.
- The following screenshots illustrate the manipulator gizmo with Exponential Spacing turned off:
- Here is the Omni light gizmo with Exponential Spacing on and 5 Samples with Spacing of 5:
NOTE:
- The Manipulator Gizmo does NOT represent the ACTUAL distribution of samples in the final Attenuation Map!
- Please remember that the beginning of sampling depends on the Z-DEPTH value stored for each light ray, which in turn depends on the position of the first particle encountered along that ray.
- Thus, the Manipulator only shows the distribution based on ONLY ONE user-defined depth value (represented by the first plane’s distance from the light and tweaked using the small orange circle handle).
