rcg-pipeline/rcg_pipeline/utils/shininess_to_roughness.py

42 lines
1.3 KiB
Python

# ***** BEGIN GPL LICENSE BLOCK *****
#
# original alg from https://github.com/assimp/assimp/issues/4573
# Copyright (C) 2024 Ilia Kurochkin <brothermechanic@yandex.com>
#
# Created by Ilia Kurochkin (brothermechanic)
# contact: brothermechanic@yandex.com
#
# This is free software;
# you can redistribute it and/or modify
# it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
# ***** END GPL LICENSE BLOCK *****
#
# coding: utf-8
'''
DESCRIPTION.
Math function.
'''
__version__ = '0.1'
import math
def shiny_to_rough(shininess):
''' convert shiny to roughness '''
a, b = -1.0, 2.0
c = (shininess / 100.0) - 1.0
D = math.pow(b, 2) - (4 * a * c)
roughness = (-b + math.sqrt(D)) / (2 * a)
return max(roughness, 0)