AlwarrenSidh / ArmAToolbox

Arma Toolbox for Blender
GNU General Public License v3.0
86 stars 38 forks source link

Procedural texture color in Arma Toolbox Material Settings incorrect when exported #27

Open pmckeon opened 4 years ago

pmckeon commented 4 years ago

Blender uses the linear RGB color space whereas Arma is using gamma-corrected sRGB color space, this results in an incorrect color being exported for procedural textures.

I propose two possible solutions to fix this, the first is to change the color picker to use gamma corrected values

properties.py, line 188 change subtype to COLOR_GAMMA

class ArmaToolboxMaterialProperties(bpy.types.PropertyGroup):
    texture : bpy.props.StringProperty(
        name="Face Texture", 
        description="ARMA texture", 
        subtype="FILE_PATH", 
        default="")
    rvMat : bpy.props.StringProperty(
        name="RVMat Material", 
        description="RVMat associated with this materiaL", 
        subtype="FILE_PATH",
        default="")
    texType : bpy.props.EnumProperty(
        name="Color Map Type",
        description="The type/source of the color for this surface",
        items=textureClass)
    colorValue : bpy.props.FloatVectorProperty(
        name= "Color",
        description= "Color for procedural texture",
        subtype= 'COLOR_GAMMA',
        min= 0.0,
        max= 1.0,
        soft_min= 0.0,
        soft_max= 1.0,
        default= (1.0,1.0,1.0))
    colorType : bpy.props.EnumProperty(
        name="Color Type",
        description="The Type of color, corresponding to the suffix of a texture name",
        items = textureTypes)
    colorString : bpy.props.StringProperty (
        name = "Resulting String", 
        description = "Resulting value for the procedural texture")

the second possible solution is to do the linear to sRGB space conversion on export

MDLexporter.py, in function getMaterialInfo

def lineartosRGB(c):
    if c < 0.0031308:
        srgb = 0.0 if c < 0.0 else c * 12.92
    else:
        srgb = 1.055 * math.pow(c, 1.0 / 2.4) - 0.055

    return srgb

def getMaterialInfo(face, obj):
    textureName = ""
    materialName = ""

    if face.material_index >= 0 and face.material_index < len(obj.material_slots):
        material = obj.material_slots[face.material_index].material
        texType = material.armaMatProps.texType;

        if texType == 'Texture':
            textureName = material.armaMatProps.texture;
            textureName = stripAddonPath(textureName);
        elif texType == 'Custom':
            textureName = material.armaMatProps.colorString;
        elif texType == 'Color':
            textureName = "#(argb,8,8,3)color({0:.3f},{1:.3f},{2:.3f},1.0,{3})".format( 
                lineartosRGB(material.armaMatProps.colorValue.r), 
                lineartosRGB(material.armaMatProps.colorValue.g), 
                lineartosRGB(material.armaMatProps.colorValue.b), 
                material.armaMatProps.colorType)

        materialName = stripAddonPath(material.armaMatProps.rvMat)

    return (materialName, textureName)