Setting your GitHub repository to recognize file languages

If your writing code in languages that are based on a common language but their files names have an uncommon extension, for example, the 3D shading languages OSL, and HLSL, which are written in C syntax but have .osl and .hlsl, or .fx as file name extensions,
GitHub wont automatically recognize that the code in these files is actually C language and present their syntax properly.

It’s very easy to fix this by adding a simple setting to your .gitattributes file, that tells GitHub’s linguist system to associate a specific file extension with the wanted language like this example:

# consider OSL as C language
* .osl linguist-language=C

 

Related:
Associate file type with languages in Notepad++
UE4 GitHub first steps.

Using OSL Shaders in Blender & Cycles

Software:
Blender 2.82 | Cycles

The Cycles render engine in Blender has a very convenient OSL Shader development and usage workflow.
Shaders can be both loaded from external files or written and compiled directly inside Blender.

Before you begin:
Make sure your Blender scene is set to use the Cycles render engine, in CPU rendering mode, and also check the option Open Shading Language:
Annotation 2020-05-28 165830

 

To write an OSL shader in Blender:

  1. Write your shader code in Blender‘s Text Editor:
    Annotation 2020-05-28 173405
  2. In your object’s material shader graph (Shader Editor view),
    Create a Script node:
    Annotation 2020-05-28 170331
  3. Set the Script node‘s mode to Internal,
    And select your shader’s text from the Script node‘s source drop-down:
    Annotation 2020-05-28 170711
  4. If the shader compiles successfully, the Script node will display its input and output parameters, and you can connect it’s output to an appropriate input in your shading graph.
    * If your shader is a material (color closure) connect it directly to the Material Output node’s Surface input, is it’s a volume to the Volume input, or if its a texture to other material inputs as needed.
    Annotation 2020-05-28 171419
  5. If the shader code contains errors, it will fail to compile, and you’l be able to read the error messages in Blender‘s System Console window:
    Annotation 2020-05-28 172423
  6. After fixing errors or updating the shader’s code, press the Script Noe Update button on the Script node to re-compile the shader:
    Annotation 2020-05-28 172735

 

Loading an external OSL shader into Cycles:

Exactly the same workflow described in the previous section, except setting the Script node‘s mode to External and either typing a path to the shader file in the Script node or pressing the little folder button to locate it using the file browser:Annotation 2020-05-28 173159

 

Related:

  1. OSL read-list
  2. What are OSL shaders?
  3. Using OSL shaders in Arnold for Maya
  4. Using OSL shaders in V-ray for 3ds max
  5. Writing a basic OSL color shader
  6. Blender 2.83 OSL bug & fix

Using OSL Shaders in V-Ray for 3ds max

Software:
3ds max 2020 | V-Ray next

V-Ray for 3ds max supports compiling and rendering OSL shaders,
And also offers some handy shaders for download on the V-Ray documentation website.
Note:
OSL shaders are supported only in V-Ray Advanced and not in V-Ray GPU.

 

To load an external OSL shader:

  1. For a material (color closure) shader, create a:
    Materials > V-Ray > VRayOSLMtl
    For a texture shader create a:
    Maps > V-Ray > VRayOSLTex
  2. In the VRayOSLMtl or VRayOSLTex‘s General properties,
    Click the Shader File slot-button to locate and load the *.osl file.
  3. Provided that the shader has loaded and compiled successfully,
    You will now be able to set it’s custom parameters in its Parameters section:
    Annotation 2020-05-25 200439
  4. If compile errors will be found you’l be able to read the error messages in the V-Ray messages window:
    Annotation 2020-05-25 200625

 

To write an OSL shader:

  1. To write a material shader (color closure) create a:
    Materials > V-Ray > VRayOSLMtl
    To write a texture shader create a:
    Maps > V-Ray > VRayOSLTex
  2. Expend the Quick Shader section of the node’s properties,
    And check the Enable option.
  3. Write you’r OSL code, and press Compile.
    Annotation 2020-05-25 204835
  4. Provided that the shader compiled successfully,
    You will now be able to set it’s custom parameters in its Parameters section:
    Annotation 2020-05-25 205225
  5. If compile errors will be found you’l be able to read the error messages in the V-Ray messages window.

 

Related:

  1. OSL read-list
  2. What are OSL shaders?
  3. Using OSL shaders in Arnold for maya 
  4. Using OSL shaders in Blender & Cycles
  5. Writing a basic OSL color shader

Using OSL Shaders in Arnold for Maya

Software:
Maya 2020 | Arnold 6

Autodesk Maya 2020 & Arnold 6 offer a flexible OSL development and usage workflow.
You can both load or write OSL shaders on the fly, compile, test, and render them,
And also define a shader folder path for shaders to be available as part of your library for all projects.
Steps for using OSL shaders in Maya & Arnold:

Writing an OSL shader or loading it for single use (just the current project):

  1. Create a new aiOslShader node:
    Annotation 2020-05-19 220416
  2. Select the new aiOslShader node and in its attributes either write new OSL code in the code OSL Code section, or press Import to Load an OSL shader file (*.osl):
    Annotation 2020-05-19 220454
  3. When new shader code is imported, it’s automatically compiled:
    Annotation 2020-05-19 220649
  4. I f you’ve written new code, or changed the code it will have to be re-compiled.
    In that case press Compile OSL Code:
    Annotation 2020-05-19 223632
  5. The code may contain errors, in that case you will see a red Compile Failure message:
    Annotation 2020-05-19 224342
    You can read the error message in the Maya output window, or in the Maya Script Editor, Correct the code and press Compile OSL Code again.
    Annotation 2020-05-19 224410
  6. After the OSL code is compiled successfully, the shader’s input parameters can be accessed in the OSL Attributes section below the code:
    Annotation 2020-05-19 224431
  7. Depending on the type of output the OSL shader generates, the aiOSLShader node should to be connected to an input in the object’s shader graph or Shading Group.
    * OSL shaders can be surface shaders, volume shaders, procedural textures, texture processors and more..
    To Apply the OSL shader to an object as a surface shader, disconnect the object’s current surface shader if it has one,
    And then drag and drop the aiOSLShader node from the Hypershade window onto the object.
    In the Connection Editor select outValue on the left side (node outputs) and surfaceShader in the right side (object inputs):
    Annotation 2020-05-19 220810

Note:
When compiling OSL shaders “on the fly” using the above steps, the shader’s input parameters don’t necessarily appear at their intended order that is  defined in the shader code.

 

Installing OSL shaders so they will always be available as custom nodes in the Hypershade library

  1. Create a folder for storing your OSL shaders, and place you OSL shader files (*.osl) in this folder.
    Annotation 2020-05-20 225134
  2. Locate Maya’s Maya.env file.
    This is an ascii text file containing environment variables that Maya loads at startup.
    The Maya.env will usually be located at:
    C:\Users\<your user>\Documents\maya\<maya version>
    Annotation 2020-05-20 225221
  3. Open Maya.env in a text editor and add the following line to it:
    ARNOLD_PLUGIN_PATH=<path to your OSL shaders folder>
    for example:
    ARNOLD_PLUGIN_PATH=D:\3DAssets\OSL_Shaders
    Annotation 2020-05-20 225400
  4. Restart Maya.
    When Maya loads, the MtoA (Maya to Arnold) plugin will automatically compile the shaders that are found in the folder, report about the compilations or found errors in the Maya output window, and create compiled *.oso files for each shader:
    Annotation 2020-05-20 230917
  5. The compiled shaders will now be available as custom nodes in the Hypershade Arnold library with the typical “ai” (Arnold Interface) prefix added to their names:
    Annotation 2020-05-20 231138
  6. The OSL shaders will be created as nodes with their editable attributes, that can be connected to an object’s shading network graph:
    * Connecting the node to the graph is the same as described in the previous part (7)
    Annotation 2020-05-20 231232

 

Related:

  1. OSL read-list
  2. What are OSL Shaders?
  3. Using OSL shaders in V-Ray for 3ds max
  4. Using OSL shaders in Blender & Cycles
  5. Writing a basic OSL color shader

What are OSL shaders?

OSL is an acronym for Open Shading Language.
Developed Originally at Sony Pictures Imageworks for the Arnold render engine, Open Shading language is a C like programming language with which custom material, textures and shading effects can be developed OSL shaders (*.osl files), that are supported many by popular render engines.

OSL allows development of complex texturing and shading effects using scene input parameters like the shading point’s world position vector, normal vector, UV coordinates etc., and optical ray-tracing  functions – BSDF*’s or “Color Closures” as they are called in OSL, like Diffuse, Glossy, Refraction light scattering etc. that can be combined with C  logic and math programming.

*.osl files are compiled to *.oso file for rendering.
Most render engines supporting OSL shaders ship with an OSL compiler.

 

Useful OSL shader libraries found on the web:

> OSL Shaders for download on the Chaos Group website:
https://docs.chaosgroup.com/display/OSLShaders/OSL+Shaders+Home

> OSL Shaders for download at the Autodesk Developer Network Github repository:
https://github.com/ADN-DevTech/3dsMax-OSL-Shaders
These are the OSL shaders that ship with 3ds max 2019 or newer, and are providing texture and pattern processing tools, but not materials.
* Material shaders or “Closures” as they are referred to in OSL are not supported by 3ds max’s native implementation of OSL.

> A library of OSL shaders collected by Shane Ambler:
https://github.com/sambler/osl-shaders

 

Notes:

  1. In general, OSL shaders are supported only in CPU Rendering, but not supported by GPU renderers. There are some attempts to develop OSL support for GPU renderers, But as far as I know they are limited.
  2. Some OSL shaders will work on one or more render engines, and not work as expected on other render engines. the reason being that each render engine has it’s own implementation of OSL.
    These differences may show in a different rendered result and also compile failure.

 

Basic example:
The following example renders show how a combination of two basic OSL shaders iv’e written, one of which is a dielectric material shader, and the other a color/angle blend procedural texture, produce fairly consistent results when rendered in different render engines.
* note the difference in specular glossy roughness interpretation for the same 0.1 value..

> You’r welcome to download these two basic OSL shaders here.

Arnold for Maya:
Annotation 2020-05-22 213609

V-Ray for 3ds max:
Annotation 2020-05-22 213629

Cycles for Blender:
Annotation 2020-05-22 213723

 

Related:

  1. OSL read-list
  2. Using OSL shaders in Arnold for Maya
  3. Using OSL shaders in V-Ray for 3ds max
  4. Using OSL shaders in Blender & Cycles
  5. Writing a basic OSL color shader

UE4 – HDRI Environment & Lighting

Software:
Unreal Engine 4.25

Annotation 2020-05-20 162811

Creating HDRI environment backgruond and lighting* in UE4:
Note:
Lighting using a panoramic HDRI background is also referred to as IBL – Image Based Lighting.

* The example HDRIs in this post are from www.hdrihaven.com

  1. Import HDRI environment file.
    Note:
    The file must be saved as a *.hdr file and not *.exr because AFAIK that’s the only way UE4 will recognize it as an HDRI environment and encode it as a Texture Cube (cube map)
  2. Enable the HDRIBackdrop plugin:
    Go to Edit > Plugins
    Type “HDRI” in the search field to locate HDRIBackdrop and enable it.
    * You’l have to restart the UE Editor before using the plugin
    Annotation 2020-05-20 153925
  3. Drag a Lights > HDRI Backdrop object to your level:
    Annotation 2020-05-20 154657
  4. In the HDRIBackdrop details, select the wanted Cubemap:
    Annotation 2020-05-20 155212
  5. > Set the HDRIBackdrop‘s Intensity (self explanatory..).
    > Rotate the HDRIBackdrop around its Z axis to set the environment’s direction.
    > Set the HDRIBackdrop‘s Size.
    * Make it larger than your whole scene,
    And if Use Camera Projection is unchecked make it also large enough so that noticeable objects in the HDRI image will be distant enough as to not move incorrectly when you strife.
    * When Use Camera Projection is activated the Size property has no effect.
    > If Use Camera Projection is unchecked, set the Projection Center Z value to define the background image height below which it is projected as a flat ground.
    > Lighting Distance Factor defines ground projection area that will appear to receive shadows from your scene objects.
    * Set this attribute to 0 in-order to turn off the ground projection shadow.
    > Use Camera Projection:
    Activate this option to get a traditional infinitely far background with no flat ground surface projection.Annotation 2020-05-20 160338

 

Related:

  1. Sun & Sky link
  2. UE4 Architectural Glazing
  3. 3ds max & V-Ray to UE4 Datasmith workflow
  4. Preparing an FPS project for archviz
  5. UE4 – Archviz Light calculaion tips

3ds max & V-Ray to UE4 – Datasmith workflow basics and tips

Software:
3ds max 2020 | V-Ray Next | Unreal Engine 4.25

This post details basic steps and tips for exporting models from 3ds max & V-Ray to Unreal Engine using the Datasmith plugin.
The Datasmith plugin from Epic Games is revolutionary in the relatively painless workflow it enables for exporting 3ds max & V-Ray architectural scenes into Unreal Engine.
Bear in mind however, that Datasmith‘s streamlined workflow can’t always free us from the need to meticulously prepare models as game assets by the book (UV unwrapping, texture baking, mesh and material unifying etc.) (especially if we need very high game performance).
That being said, the Datasmith plugin has definitely revolutionized the process of importing assets into Unreal, making it mush more convenient and accessible.

 

Preparation:
Download and Install the Datasmith exporter plugin compatible with your modeling software and Unreal Engine version:
https://www.unrealengine.com/en-US/datasmith/plugins

 

In 3ds max & V-Ray:

  1. Make sure all materials are VRayMtl type (these get interpreted relatively accurately by Datasmith)
  2. Make sure all material textures are properly located so the Datasmith exporter ill be able to export them properly.
  3. In Rendering > Exposure Control:
    Make sure Exposure control is disabled.
    Explanation:
    If the Exposure Control will be active it will be exported to the Datasmith file, and when imported to Your Unreal Level/Map a “Global_Exposure” actor will be created with the same exposure settings.
    Sounds good, right? So what’s the problem?
    The problem with this is that these exposure setting will usually be compatible with photo-metric light sources like a VRaySun for example, but when imported to Unreal, the VRaySun does not keep its photo-metric intensity. (in my tests it got 10lx intensity on import). the result is that the imported exposure settings cause the level to be displayed completely dark.
    Of-course you can simply delete the “Global_Exposure” actor after import, but honestly, I always forget its there, and start looking for a reason why would everything be black for no apparent reason…
    * If your familiar with photo-metric units, you can set the VRaySun to its correct intensity of about 100000lx, and also adjust other light sources intensity to be compatible with the exposure setting.
  4. Annotation 2020-05-12 192439
  5. Select all of the models objects intended for export,
    And File > Export > Export Selected:
    * If you choose File > Export > Export you’l still have an option to export only selected objects..
    Annotation 2020-05-12 192506
  6. In the File Export window,
    Select the export location, name the exported file,
    And in the File type drop-down select Unreal Datasmith:
    Annotation 2020-05-12 192550
  7. In the Datasmith Export Options dialog,
    Set export options, and click OK.
    * Here you select whether to export only selected object or all objects (again)
    Annotation 2020-05-12 192654
  8. Depending on the way you prepared your model,
    You may get warning messages after the export has finished:
    Explanation:
    Traditionally, models intended for use in a game engine should be very carefully prepared with completely unwrapped texture UV coordinates and no overlapping or redundant geometry UV space.
    Data-smith allows for a significantly forgiving and streamlined (and friendly) workflow but still warns for problem it locates.
    In many cases these warnings will not have an actual effect (especially if Lightmap UV’s are generated by Unreal on import), but take into account that if you do encounter material/lighting issues down the road, these warnings may be related.
    Annotation 2020-05-12 192730
  9. Note that the Datasmith exporter created both a Datasmith (*.udatasmith) file, and a corresponding folder containing assets.
    It’s important to keep both these items in their relative locations:
    Annotation 2020-05-12 204541

 

In Unreal Editor:

  1. Go to Edit > Plugins to open the Plugins Manager:
    Annotation 2020-05-12 192802
  2. In the Plugins Manager search field, type “Datasmith” to find the Datasmith Importer plugin in the list, and make sure Enabled checked for it.
    * Depending on the project template you started with, it may already be enabled.
    * If the plugin wasn’t enabled, the Unreal Editor will prompt you to restart it.
    Annotation 2020-05-12 192901
  3. In the Unreal project Content, create a folder to which the now assets will be imported:
    * You can also do this later in the import stage
    Annotation 2020-05-12 193030
  4. In the main toolbar, Click the Datasmith button to import your model:
    Annotation 2020-05-12 193043
  5. Locate the the *.udatasmith file you exported earlier, double click it or select it and press Open:
    Annotation 2020-05-12 193129
  6. In the Choose Location… dialog that opens,
    Select the folder to which you want to import the assets:
    * If you didn’t create a folder prior to this stage you can right click and create one now.
    Annotation 2020-05-12 193301
  7. The Datasmith Import Options dialog lets you set import options:
    * This can be a good time to raise the Lightmap resolution for the models if needed.
    Annotation 2020-05-12 193326
  8. Wait for the new imported shaders (materials) to compile..
    Annotation 2020-05-12 193408
  9. The new assets will automatically be placed into the active Map\Level in the Editor.
    All of the imported actors will be automatically parented to an empty actor names the same as the imported Datasmith file.
    In the Outliner window, locate the imported parent actor, and transform it in-order to transform all of the imported assets together:
    * If your map’s display turns completely dark or otherwise weird on import, locate the “Global_Exposure” actor that was imported and delete (you can of-course set new exposure setting or adjust the light settings to be compatible)
    Annotation 2020-05-12 193517

 

 

Related:

  1. Preparing an FPS project for archviz
  2. Unreal – Architectural glass material
  3. Unreal – Camera animation
  4. UE4 – Archviz Light calculaion tips

Python for 3ds max – Loading an image file and reading pixel values

Software:
3ds max 2020

An example of loading and displaying an image file using Python for 3ds max:
* The EXR image file is located in in the same directory with the 3ds max file in this case.
Annotation 2020-05-12 123229
from MaxPlus import BitmapManager
image_file_path = r'BG_park_A.exr'
bmp_storage = MaxPlus.Factory.CreateStorage(17)
bmp_info = bmp_storage.GetBitmapInfo()
bmp_info.SetName(image_file_path)
bmp = BitmapManager.Load(bmp_info)
bmp.Display()

Script explanation line by line:
1. Import the BitmapManager class needed to load image files.
2. Set a variable containing the path to the image file
3. Call the MaxPlus.Factory class’s CreateStorage method to initiate a BitmapStorage object.
This is embarrassing IMO..
And it may very well be that I simply didn’t find the correct way it should be done..
I couldn’t find any other way to independently initiate the BitmapInfo object needed for loading the image, other than Initiating a BitmapStorage object and getting referece to its BitmapInfo object. (the BitmapInfo class has no constructor..)
* If you know a better method to do this I’ll be very grateful if you take the time to comment.
Note:
that the 17 integer argument we supply sets the storage to be compatible with:
32-bit floating-point color depth format (without an alpha channel).
See list of other color format options in this example here:
https://help.autodesk.com/view/3DSMAX/2020/ENU/?guid=__developer_using_maxplus_creating_a_bitmap_html
* They wrote a class containing convenient named constants of the integer arguments (see example code below).
* In this example of creating the BitmapStorage just as a way to generate a BitmapInfo object the actual format you’l supply doesn’t matter, but you can’t use a format that can’t be written to like 8 for example (see list below)
4. Get a reference to the BitmapInfo object contained in the BitmapStorage object.
5. Setting the name property (full file path) of the BitmapInfo object.
6. Loading the image.
7. Displaying the image in 3ds max‘s image viewer window.

Example code for a BitmapStorage format constants container class:

* This example’s source is in the 3ds max help Python examples:
https://help.autodesk.com/view/3DSMAX/2020/ENU/?guid=__developer_using_maxplus_creating_a_bitmap_html
class BitmapTypes(object):
     BMM_NO_TYPE = 0 # Not allocated yet
     BMM_LINE_ART = 1 # 1-bit monochrome image
     BMM_PALETTED = 2 # 8-bit paletted image. Each pixel value is an index into the color table.
     BMM_GRAY_8 = 3 # 8-bit grayscale bitmap.
     BMM_GRAY_16 = 4 # 16-bit grayscale bitmap.
     BMM_TRUE_16 = 5 # 16-bit true color image.
     BMM_TRUE_32 = 6 # 32-bit color: 8 bits each for Red, Green, Blue, and Alpha.
     BMM_TRUE_64 = 7 # 64-bit color: 16 bits each for Red, Green, Blue, and Alpha.
     BMM_TRUE_24 = 8 # 24-bit color: 8 bits each for Red, Green, and Blue. Cannot be written to.
     BMM_TRUE_48 = 9 # 48-bit color: 16 bits each for Red, Green, and Blue. Cannot be written to.
     BMM_YUV_422 = 10 # This is the YUV format - CCIR 601. Cannot be written to.
     BMM_BMP_4 = 11 # Windows BMP 16-bit color bitmap. Cannot be written to.
     BMM_PAD_24 = 12 # Padded 24-bit (in a 32 bit register). Cannot be written to.
     BMM_LOGLUV_32 = 13 BMM_LOGLUV_24 = 14
     BMM_LOGLUV_24A = 15 BMM_REALPIX_32 = 16 # The 'Real Pixel' format.
     BMM_FLOAT_RGBA_32 = 17 # 32-bit floating-point per component (non-compressed),
     RGB with or without alpha
     BMM_FLOAT_GRAY_32 = 18 # 32-bit floating-point (non-compressed), monochrome/grayscale
     BMM_FLOAT_RGB_32 = 19
     BMM_FLOAT_A_32 = 20

Reading pixel values from the image:
Annotation 2020-05-12 143904
bmp_storage = bmp.GetStorage()
hdr_pixel = bmp_storage.GetHDRPixel(3000,200)
print(hdr_pixel)
1. Get reference to the Bitmap‘s BitmapStorage object.
* in this case, writing over the BitmapStorage object we created earlier just to get the BitmapInfo object..
2. Read the pixel value.

Note:

When copying and pasting a script from this example, the indentation may not be pasted correctly.

Related:

 

UE4 – Creating two sided material effects using the TwoSidedSign node

Software:
Unreal Engine 4.24

The TeoSidedSign node let’s the shader “know” if a rendered polygon is facing the camera or not by outputting a value of 1 for facing polys and -1 for back-facing polys.
This is useful for creating materials that have different properties when seen front-facing or back-facing.

Example 1:
Blending two different colors based on face direction:

  1. Check the Two Sided material attribute.
    * Needed so that the engine will render the polygons beck sides.
  2. In the material blueprint, create a blend of to colors using a Lerp (LinearInterpolate) node and connect it to the material’s Base Color input.
  3. Add a TwoSidedSign node to get polygon facing input (1,-1).
  4. Connect the TwoSidedSign node’s output to a Clamp node to clamp the values to (1,0).
  5. Connect the  Clamp node’s output to the Lerp node’s Alpha input so that the polygon’s facing direction will control the Lerp blend.

Note:
You can use this method to blend any other material attribute based on polygon facing direction.

Annotation 2020-05-11 133226

 

Example 2:
Create an “inwards facing” flipped normal material:

  1. Set the material’s Blend Mode to Masked.
    * Needed for being able to make areas parts of the mesh invisible.
  2. Check the Two Sided material attribute.
    * Needed so that the engine will render the polygons beck sides.
  3. Add a TwoSidedSign node to get polygon facing input (1,-1).
  4. Connect the TwoSidedSign node’s output to a Clamp node to clamp the values to (1,0).
  5. Connect the Clamp node’s output to a 1-X node to invert the facing input.
  6. Connect the 1-X node’s output to the material’s Opacity Mask input so that polygons facing the camera will be invisible.

Annotation 2020-05-11 130703

 

Related:

  1. Blending material using Paint
  2. Material Functions
  3. UE4 Bump Map

GitHub Desktop – Not launching UI – Problem & Fix

Software:
GitHub Desktop 2.4.3 | Windows 10

About 1 or 2 weeks ago GitHub Desktop stopped opening it’s window when lunched.
It would run in the background, you could see it in the Windows Task Manager, but its window would not open.
Looking into this on various web discussions, I found that deleting the folder named app-2.4.3 in its application data solves the problem:
Annotation 2020-05-09 200238
This is the path to GitHub Desktop‘s data:
C:\Users\<YOUR USER>\AppData\Local\GitHubDesktop
After deleting the folder and re-launching GitHub Desktop, I found it generated a new folder with the same name, so I guess settings for the latest update got corrupted, and the software generated new settings..

 

Related:
UE4 GitHub Setup