PBR Workflows – Advanced Shaders

This document is intended for VR / AR artists. These tutorials will help artists to generate relevant assets for use with one of the advanced FX shaders and instruct artists how to apply those shaders within Edit-3d.

 

PBR Workflows

Advanced Shaders

DATE

05/06/2015

PRINCIPAL AUTHOR

S Hickey;

SECONDARY AUTHORS

Darrell James

VERSION

 

UPDATE

 

MISC

Docs style applied Dec 2020

Overview

This document is intended for VR / AR artists. These tutorials will help artists to generate relevant assets for use with one of the advanced FX shaders and instruct artists how to apply those shaders within Edit-3d.

It is intended for artists who are already familiar with Edit-3d. For more information about any of the topics covered here, please email support@rtsw.co.uk.

Generic technical guidelines

The following diagram illustrates the general guidelines Edit-3d designers can use when implementing PBR-based fx nodes:

Shader Requirements

Fresnel Reflection (FR) Requirements

The fresnel reflection (FR) shader is a fast reflection shader that approximates reflections on an object loosely based on real world physics. To implement this shader you will need:

  • The fx file: FresnelShaderSphere.fx (this should be placed in the GMData/CGPrograms/ folder of your project).
  • An 8bit (or 16bit) per channel spherical environment map.
  • A UV unwrapped 3D object with the following maps:
    • Diffuse.
    • Specularity.
    • Tangent Space Normal.

Physically Based Rendering (PBR) Requirements

The physically based rendering (PBR) shader is a robust shader that mimics physical lighting based on material properties. PBR requires an extensive set of maps. These are normally generated by third applications such as Quixel Suite or Substance Painter. It is beyond the scope of this document to teach how to create PBR maps.

However, once your PBR shader artists have created the appropriate maps, you can implement them within Edit-3d Edit. To implement this shader you will need:

  • The fx file: PBR_Spherical.fx (this should be placed in the GMData/CGPrograms/ folder of your project).
  • A 32bit per channel, HDR, spherical environment map (.hdr file extension).
  • A UV unwrapped 3D object with the following maps:
    • Albedo.
    • Combined ambient occlusion (ao), roughness and metallic map. This is explained in more detail below.
    • Tangent Space Normal.

Generating Environment Map

8bit Environment Map (for FR)

To generate a single exposure, real world spherical environment map, we recommend using the Ricoh Theta.

  • Use the device to capture a spherical map.
  • Resize the image to an aspect ratio of 2:1 (e.g., 2048px x 1024 px).
  • Use curves in Photoshop to brighten the highlights and severely darken the shadows and midtones.
  • If you’re going to use the Fresnel Reflection shader, consider blurring the environment (you may also want to create a blurred environment if you’re creating a skybox). In Photoshop.
    • Unlock and duplicate the background.
    • Offset the new layer by 50% horizontally.
    • Convert the new layer to a smart object.
    • Convert the old layer to a smart object.
    • Apply a gaussian blur to both layers (around 20 pixels).
    • Select the top layer and offset it back 50% horizontally.
    • You’ll see a bad seam. Drag a selection around it and feather it by 60 pixels or so.
    • Invert the selection a and apply it as a mask on the top layer.
    • You can play with the gaussian blur strength now, since both your layers are smart objects.
    • Flatten the image when you’re done.
  • Consider adding detail back into the blurred environment with an overlay.

Virtual 8bit Environment Map

If you are generating your environment map for a virtual set, you will need to generate the map using your 3D software package. This is often achieved by:

  • Creating a spherical camera and rendering your scene.
    • Render an image with a 2:1 ratio, e.g., 2048px x 1024px.
  • Creating a sphere with 100% reflection and “baking” the reflection to a file.
    • Bake the texture to an image with a 2:1 ratio, e.g., 2048px x 1024px.

Teaching how to create a spherical environment map specifically from a 3D package is beyond the scope of this tutorial.

32bit Environment Map (for PBR)

This only applies to Edit-3d 4.6.2 or later. If you are using an earlier version, you must use the 8bit method outlined above as HDR images are not fully supported until 4.6.2.

To generate a multiple exposure, real world spherical environment map, we recommend using the Ricoh Theta. You’ll need to create a HDR from 3 exposures.

  1. First take three exposures (-2, 0, +2) of the environment with a 360 degree camera.
  2. Next, take the -2 and +2 exposures and use Photoshop’s Image -> Adjustments -> Exposure to create a -4 and a +4 exposure.
  3. Within Photoshop, go to File -> Automate -> Merge to HDR Pro …
  4. Browse for your multiple exposures (including your new -4 / +4 ones) and hit OK.
  5. In the resulting dialog, change to exposure value mode (EV).
  1. Set the EV of each image according to the exposure value of the shot (cycle through exposures using the left and right arrows).
  2. Hit OK.
  3. Make sure the Mode is set to 32 bit.
  4. Remove the tick from “Complete Toning in Adobe Camera Raw.”
  5. Hit OK. Save the image as a Radiance file (hdr).

Virtual HDR Environment Map

Generating a 32bit VR environment map is much the same as an 8bit (see Virtual 8bit Environment Map above for suggestions). However, when you generate the image, you will need to output a Radiance file (*.hdr).

Cinema 4D

Rendering Geometry into the HDR

If you need to mix your geometry with a real world environment (when implementing AR), you can generate your HDR environment map within Cinema 4D. Here is a workflow for bringing virtual elements into a HDR:

http://lesterbanks.com/2012/09/create-hdris-from-your-own-cinema-4d-scenes/

  1. Add HDR image based lighting to your scene (add a Sky with a Luminance material with your HDR image).
  2. Create a sphere (which acts as as the 360 degree camera).
  3. Create a fully reflective material and assign it to the sphere.
  4. Add a Compositing tag to the sphere and uncheck cast shadows.
  5. Add a Bake Texture tag to the sphere. Set it to only use Reflection in the Options tab.
    1. In the tag settings, change Height to 2048 and the Width to 1024.
    2. Change the format to Radiance (HDR).
    3. Choose a filename for the output.
    4. Go to options, click Bake.

Now you have a new HDR map which merges your scene geometry into the original HDR.

Applying FR in Edit-3d

Time to apply a Fresnel Reflection shader.

  1. Name your images nicely before import. Be clear. Make sure they’re unique—try using a simple naming format like “graphic_mesh_map.ext”, e.g., “Formation_Plinth_Normal.png.”
    1. If you don’t have a specular map for some reason, create a png that’s pure white and call it “Generic_White.png”.
    2. If you don’t have a normal map, create a PNG that’s 128,128,255 and call it “Generic_Normal_Blank.png”.
  1. Import your diffuse, specular and normal maps.
  2. Import your environment map too!
  3. Add an Effect node above your object.
  4. Choose the FresnelShader from the dropdown within the Effect node.
  5. In the shader for the object, go to the ShaderNode tab and assign the diffuse shader that you just imported.
  6. Now go to the Shader tab:
    1. For Texture 0, it should already be pointing to your diffuse texture.
    2. For Texture 1, choose your specular texture in the dropdown.
    3. For Texture 2, choose your environment texture in the dropdown
    4. For Texture 3, choose your normal texture in the dropdown.

FR Settings

You can adjust the settings in the effect node:

  1. Fresnel Falloff controls how much of the surface reflects the environment. Set it to zero if you want chrome (yuck). Or around 1.5 for a snooker ball. Or around 3.0 for anything else.
  2. Fresnel Strength controls the intensity of the reflection. How bright do you want the reflections? Keep it at 1.0 most of the time.
  3. Normal Strength control the intensity of the normal map. You ought to make changes to the normal map outside of Edit-3d. But if you’re in a pickle, try adjusting it up to 2.0 or 3.0 to ramp up the bumpiness. Or scale it down to 0.0 for a totally smooth surface.
  4. Ambient Environment adds a bit of diffuse colour to the object, based on the colours in the environment. You can leave it off in most situations. Set it to around 0.2 if you have a very dark object that needs brightening up in the blacks.
  5. Env Rotation allows you to rotate the environment map to match the real environment around it. You ought to link this to a separate transform node, so you can affect multiple environments from one source.

Skybox

It can sometimes help to include a Skybox to see how your shader looks in relation to the environment.

  • Import the blurred environment map.
  • Create a sphere, scale it to 100,100,100. Assign the blurred environment map shader. Push it to the top of the Scene Graph, so it’s behind everything else in the scene.
  • In the shader State tab, turn off Lighting and Backface Culling.

Troubleshooting 1

The reflections are too strong

  • First, try blurring the environment map.
  • Second, try darkening the shadows and midtones of the environment map and just leaving the highlights.
  • Third, consider adjusting your spec map to dim the reflections in specific areas of the mesh.

The mesh looks black (or wrong)

If you are using an imported mesh (from an FBX), it’s possible that the mesh is missing some important information called tangents and bitangents (or binormals). These are normally defined during export but sometimes the exporting software doesn’t export them properly. However, there is a way to compute the tangents and bitangents within Edit-3d Edit.

  1. Click on the geometry in the scene graph.
  2. Click Compute TBN Matrix.
  3. Click on the Save icon in the Geometry pane.
  4. Enter the name of the mesh with the suffix “_TBN”, e.g., if the mesh was called Cube, save it as “Cube_TBN”.
  5. Save the project and close it.
  6. Reopen the project and the graphic.
  7. If this hasn’t fixed your problem, please email support@rtsw.co.uk with details of your problem (a screenshot, the project files and details of your version of Edit-3d).

Applying PBR in Edit-3d

A step by step guide to exporting and importing for physically based rendering (PBR).

Preparing the Images

Normally this process is handled by your PBR image creation software (Quixel Suite or Substance Painter). However, for artists without access to that software, here is how to prepare the images for Edit-3d:

  1. Name your images nicely before import. Be clear. Make sure they’re unique—try using a simple naming format like “Graphic_Mesh_Map.ext”, e.g., “Formation_Plinth_Normal.png.”
  2. If you don’t have a normal map, create a PNG that’s 128,128,255 and call it “Generic_Normal_Blank.png”.
  3. Combine your ambient occlusion (ao), roughness and metallic maps Edit-3dether:
    1. Create a new image. Call it “Graphic_Mesh_AOMetalRough”, e.g., “Formation_Plinth_AOMetalRough”.
    2. Go to the Channels window.
    3. Select the “Red” channel.
    4. Open your AO image, select all, copy it and paste it into the Red channel of your new image.
    5. Select the “Green” channel.
    6. Open your Metal image, select all, copy it and paste it into the Green channel of your new image.
    7. Select the “Blue” channel.
    8. Open your Roughness image, select all, copy it and paste it into the Blue channel of your new image.
    9. Select the RGB channel.
    10. Save the image.

Applying PBR in Edit-3d

  1. Import the images:
    1. Albedo (PNG)
    2. Environment (HDR)
    3. AO_Metal_Rough(PNG)
    4. Normal (PNG)
  1. In the Images tab, tick …
    1. Create Shader For Each Image Or TMV
    2. Shader Prefix (enter an appropriate prefix … this helps organise your shaders later).
    3. Hit Import.
  1. Add an FX node to the scene graph, above the model(s) that you wish to affect.
  2. Choose the PBR_Metal_Rough_Spherical from the dropdown list in the FX node.
  3. In the shader for the geometry, populate the texture slots as follows:
    1. tex0 – Albedo colour map.
    2. tex1 – HDR spherical Environment map.
    3. tex2 – AO_Metal_Roughness map.
    4. tex3 – Normal map.
  1. In tex1, HDR slot, click the edit texture button. Under the Filter tab change the Filter – Minification to Linear Mipmap Linear for the roughness to work correctly.
  2. While still editing tex1, go to the Format tab and check that Internal Format is set to rgb32f or rgba32f.
  3. If your mesh looks black, see Troubleshooting: The mesh looks black (or otherwise weird) in the FR section above.

PBR Settings

You can adjust the settings in the effect node:

  1. nbSamples [4-64]                  Should always be set to 4.
  2. Env Exposure [-10, 10]         Controls the exposure of the environment lighting. To                                 match Substance viewports, this value should either be 0                                 or near 0.
  3. Env Rotation                        Allows you to rotate the environment map to match the                                 real environment around it.
  4. Lod Offset [0, 5]                 Controls the mip mapping of the Environment map in                                  order to get rougher materials. This is helpful when using                                 large HDR maps e.g. 2048^2 and larger.
  5. Use Ambient Occlusion [0,1]          0 disables the ambient occlusion, useful when working                                 with Base Material Override, 1 enables it.
  6. Normal Strength[0, 5]         Multiplies the strength of the normal map so you can                                 increase or decrease its intensity, 1 is default, 0 removes                                 the normal map.
  7. Base Material Override[0,1]        When set to 1 enables the settings underneath to                                         override the textures in the shader.
  8. Base Colour                         Allows you to change the colour of the entire mesh when                                 the Base Material Override is set to 1.
  9. Metallic[0,1]                         Allows you to change the metallic property of the whole                                 mesh. Although this value can be any number in between                                 0 and 1 it’s important to remember that it’s incredibly                                 rare that a material is. Most materials are either metal,                                 or non-metal, therefore it’s normal for this map to either                                 be completely black or white.
  10. Roughness[0,1]                 Allows you to control the roughness of the whole mesh.                                 0 is glossy and 1 is rough.

Note: You can link the Env Rotation and Env Rotation to a null to control it scene-wide.

Substance Painter Export

If you are using Substance Painter, you can export the images as follows:

  1. In the TextureSet settings, click the + button beside Channels and add a new user0 Channel.
  2. Change the format to L8.
  3. Create a fill layer.
  4. Turn off all channels in the fill except for the User0 channel.
  5. In the Textures tab in the shelf, find the AO map. Drag this into the new fill layer’s user0 channel.
  6. Use Export all Channels from the File menu. Go to the configuration tab.
  7. Create a new configuration by hitting the + button in the configuration tab (see the image below).
    1. It will be called “new_export_Preset” in the Preset list on the left. Rename this now to “Edit-3d PBR”.
    2. Create an RGBA output (click RGB+A) and drag the BaseColor (on the right) into it the RGB. Select RGB Channels.
    3. Drag the BaseColor into the A and select A channel.
    4. Rename it from “RGB Alpha” to $mesh_$textureSet_Albedo.
    5. Now add an RGB output (click RGB) and drag the Normal OpenGL (on the right) into it the RGB. Select RGB Channels.
    6. Rename it from “RGB” to $mesh_$textureSet_Normal.
    7. Lastly add an RGB output (click R+G+B) and drag the User0 (on the right) into it the R. Select Gray Channel.
    8. Drag the Roughness (on the right) into it the G. Select Gray Channel.
    9. Drag the Metallic (on the right) into it the B. Select Gray Channel.
    10. Rename it from “R+G+B” to $mesh_$textureSet_AOMetalRough.
  1. Go back into the Export tab and change the output path to a suitable location.
  2. Also change the output format to png (16 bits max).
  3. Change the Config to your new “Edit-3d PBR”.
  4. Set the output size to 2048 x 2048 (or higher, if desired).
  5. Hit Export.

Extra

Custom Nodes in Substance Designer

Substance Designer allows you to set up a custom output which is useful for Edit-3d. I’ve made a Edit-3d node and start up template that allows you to quickly sort the textures into the correct channels. To Install, get the SubstanceLib folder from \bsaexchangeDarrell:

  1. Open Tools -> Preferences and switch to the Projects Tab
  2. Scroll down to “Substance Templates” and add the /SubstanceLib/Templates path
  3. Scroll down to “Library” and add the /SubstanceLib/CustomNodes path

Now when you create a new graph you will be given the choice to select the Edit-3d template. Inside of this template will be a custom node that will handle your channel shuffling for Edit-3d’s ao/metallic/roughness. There is also a series of output nodes in a frame titled “Preview” which is for the artists benefit to see the effects of their work in Designer while they’re working, these should not get exported.

More on Tangents and Bitangents

In Edit-3d Edit 4.6.2, it is possible to check for binormals and tangents in the viewer.

  • In the Preferences -> Annotation tab. Set the Normal Length to something like 10.
  • Enable normal/bitangent/tangent in the viewer (on the left, see image below) and look for red, green and blue lines.

If you don’t see green or blue lines, your model is missing important information (tangents and bitangents). This will limit the type of shader you can apply to your model.

N.B. At the time of writing, Cinema does not export bitangents and tangents.

If you don’t have tangents and bitangents, we’ll need to manually generate these within Edit-3d:

  1. Click on the geometry in the scene graph.
  2. Click Compute TBN Matrix.
  3. Click on the Save icon in the Geometry pane.
  4. Enter the name of the mesh with the suffix “_TBN”, e.g., if the mesh was called Cube, save it as “Cube_TBN”.
  5. Save the project and close it.
  6. Reopen the project and the graphic.
  7. If this hasn’t fixed your problem, please email support@rtsw.co.uk with details of your problem (a screenshot, the project files and details of your version of Edit-3d).

Troubleshooting 2

Links, Animations and Env Rotation in the PBR shader aren’t working.

Occasionally while working on a project the PBR shader will seem to get stuck. This can happen if you change a value that already has an animation applied for instance. This can simply be fixed by reloading the graphic, using the reload script button at the top of the interface, it is safe to save.