convertRoughness¶
snippets/convertRoughness.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# Functions for converting material roughness values between 2023 and 2024 mapping.
4
5from math import sqrt, pow
6
7def toNewRoughness(legacyRoughness):
8 """ Converts legacy roughness value from VRED 2023 to new roughness value in 2024. """
9 return sqrt(sqrt(legacyRoughness / 40.0))
10
11def toLegacyRoughness(newRoughness):
12 """ Converts new roughness value from VRED 2024 to legacy roughness value in 2023."""
13 return pow(newRoughness, 4.0) * 40.0
14
15
16# Create a plastic material
17mat = vrMaterialService.createMaterial("plastic material", vrMaterialTypes.Plastic)
18
19# In VRED 2024, to set a legacy roughness value (e.g. 2.0) you need to convert it to the 2024 value
20mat.setRoughness(toNewRoughness(2.0))