Simple Material Shading (2021)

Author's sample script, wroks, hints.
Post Reply
User avatar
3DfromNULL
Site Admin
Posts: 45
Joined: 2018-Jul-13 9:35

Simple Material Shading (2021)

Post by 3DfromNULL »

This sample script generate some scene objects with material.

Image
Fig. 1. Rendered image

Image
Fig. 2. How to get the rendered image (tS6 and Model side of tS7)

Image
Fig. 3. How to get the rendered image (tS5)

tS4's "Enable raytracing" switch is similar to tS5 (Right clicking "Render scene" or "Render object" button opens a small dialog. Find the button and turn it to on).

In order to write perfect code for material, it might be necessary to cut-and-try
for understanding the relation between some tSxAPI abstract objects (tsxMATERIAL, tsxSHADER, tsxSHINFO, tsxSHPARAMVAL, etc.) and shader internal name that is probably undocumented in SDK. The figure below shows the hierarchy that the author consider reasonable about the tS abstract objects and shader internal names.

Image
Fig. 4. Abstract hierarchy of a single layer material

All internal name of shaders can be listed using ShaderGetFirst(), ShaderGetNext(), and ShaderGetInternalName(). The sample script has a function "search_shader()" that lists all shader internal names of your trueSpace version when called with an empty string as its argument. The attached file "material1_1a_out.txt" is an example of its output for tS6 (Model side of tS7). The number of the internal name varies by tS version. User scripts can link a shader specified by its internal name to a material using a process below (please read "setmatebyshname()" function in the attached sample script for details).

Image
Fig. 5. How to link a shader to a material by internal name

To set parameter value of a shader (e.g. set 0.1 to ambient factor), we need to get the C++ pointer (i.e. address) to the value before call ParameterValueSetData(). Please read "getparap()" function in the sample script for details.

Image
Fig. 6. How to get a shader parameter address by name

We can now get/set a parameter value from/to the address. Please read "set1()" function in the sample script for details.

Image
Fig. 7. How to get or set from/to a shader parameter address




Image Image
Image Image Image Image Image
Attachments
material1_1a.py
script file
(23.2 KiB) Downloaded 1876 times
material1_1a_out.txt
console output (tS7)
(14.49 KiB) Downloaded 1905 times
Post Reply