FAForever / FAForeverMapEditor

A community-made map editor for the game Supreme Commander Forged Alliance
MIT License
3 stars 2 forks source link

Add button to set shadowcolor to 0 #36

Open BlackYps opened 3 months ago

BlackYps commented 3 months ago

Add functionality to set shadowcolor to 0 by computing the necessary sun and ambient color. In the UI this should be a simple button in the light settings.

Here is a snippet of a python script I once wrote for this.


def change_light_multiplier(folder_path, newLightMultiplier=1.0):
    """
    We transform the light values so that we set the shadowFill to 0
    and the lightMultiplier to a given value, without changing the
    visual appearance. Setting shadowFill to 0 makes it easier to
    reason about the lighting, because now we have a physically
    correct light setup.
    The multiplier of 2.2 enables exponential water absorption in
    the mesh shader
    """
    lightsettings_path = os.path.join(folder_path, 'Light.scmlighting')
    pi = 3.14159

    if os.path.exists(lightsettings_path):
        # Read values from lightsettings.json
        with open(lightsettings_path, 'r+') as lightsettings_file:
            lightsettings_data = json.load(lightsettings_file)
            sunColor = lightsettings_data['sunColor']
            sunAmbience = lightsettings_data['sunAmbience']
            lightMultiplier = lightsettings_data['lightingMultiplier']
            shadowFill = lightsettings_data['shadowFillColor']

            lightsettings_data['sunColor'] = {
                'x': round(sunColor['x'] * (lightMultiplier - shadowFill['x']) / newLightMultiplier, 2),
                'y': round(sunColor['y'] * (lightMultiplier - shadowFill['y']) / newLightMultiplier, 2),
                'z': round(sunColor['z'] * (lightMultiplier - shadowFill['z']) / newLightMultiplier, 2)
            }
            lightsettings_data['sunAmbience'] = {
                'x': round((sunAmbience['x'] * (lightMultiplier - shadowFill['x']) + shadowFill['x']) / newLightMultiplier, 2),
                'y': round((sunAmbience['y'] * (lightMultiplier - shadowFill['y']) + shadowFill['y']) / newLightMultiplier, 2),
                'z': round((sunAmbience['z'] * (lightMultiplier - shadowFill['z']) + shadowFill['z']) / newLightMultiplier, 2)
            }
            lightsettings_data['lightingMultiplier'] = newLightMultiplier
            lightsettings_data['shadowFillColor'] = {
                'x': 0.0,
                'y': 0.0,
                'z': 0.0
            }