PhysicalAddons / physical-starlight-and-atmosphere

issue tracker
16 stars 2 forks source link

[TEMPORARY SOLUTION] Physical Starlight does not update keyframes and renders incorrectly #93

Open FRYMEAT opened 1 year ago

FRYMEAT commented 1 year ago

Physical Starlight And Atmosphere does not update keyframes and parameters during rendering, that is, if any property (in my case, Artisiic Controls- Falloff) is animated, then if I switch the frame and open the viewport, everything will look fine there, but as soon as I start rendering, the result is very different because the intensity of the parameter does not correspond to the validity, but if I select or re-touch any parameter on the addon panel and re-apply it and then run rendering, the result looks exactly like in the cycle view window.

General information

To Reproduce In the description

Workaround Since I understood for sure that in order for all frames to be rendered correctly when rendering my animation, I just need to update or change absolutely any parameter of the addon before rendering each frame, thereby provoking it to update the values of the animated properties and all other parameters as well.

To begin with, I opened the Info menu in the blender and manually changed any parameter addon to the one that is already installed to see the string of the bpy operator, which is responsible for this parameter, I changed the horizontal rotation of the sun to 180 degrees and had seen in the info of the operator bpy.data.objects["Starlight Sun"].rotation_euler[2] = 3.14159 then I tried to enter the same value, but only by running the script through the blender text editor

import bpy
bpy.data.objects["Starlight Sun"].rotation_euler[2] = 3.14159

and it worked, but only when I entered it and manually launched the script from the text editor, when I tried to automate this script using the event handler for changing the keyframe or starting frame rendering, I failed, the parameter has not been updated if the horizontal rotation of the sun was already set to 180 (3.14159), the event handler did the same command bpy.data.objects["Starlight Sun"].rotation_euler[2] = 3.14159, but it didn't work, but if I manually applied the script before rendering, it worked, in general, it is very strange))

As a result, the conclusion was that script automation did not lead to success when I tried to do it with a value that was already set (equal), but it worked if I changed it, as a result we get to a successful workaround. I chose any paremeter of the addon that absolutely did not affect the visual display of my sky , this parameter in my case was Ground-Ground OFF- Ground offcet, I pulled the Ground offcet to the value 80 and got bpy.context.scene.oprerator.world.psa_atmosphere_settings.ground_offset = 80 in the info and I just automated before rendering each frame so that this parameter, which does not visually affect my scene in any way, just randomly changed to values from -90 to 90) Here is a working script that you need to run in the blender text editor (in case you don't care about this parameter, you can change the script and enter any other addon parameter operator you don't need)

import bpy
import random

def randomize_ground_offset(scene):
    min_offset = -90.0
    max_offset = 90.0
    current_offset = bpy.context.scene.world.psa_atmosphere_settings.ground_offset

    # Generating a random value in the specified range
    new_offset = random.uniform(min_offset, max_offset)

    # We check that the new value differs from the current one
    while abs(new_offset - current_offset) < 1e-6:
        new_offset = random.uniform(min_offset, max_offset)

bpy.context.scene.world.psa_atmosphere_settings.ground_offset = new_offset

# Registering the function as a handler before starting frame rendering
bpy.app.handlers.render_pre.append(randomize_ground_offset)

As a result, we get a script that automatically changes the unnecessary parameter of the add-on to a random value before the start of rendering the frame, so it updates all the parameters, including the one that is animated, I hope the developers will figure out this problem, since I tested different versions of the add-on and it persists))

UPDATE

I added an updated script that updates an unimportant add-on parameter directly when changing the frame, and not before starting rendering, in my case it works stably and plus it's easier to make sure whether the script works by simply changing the frame in the viewing window and watching change instead of rendering the frame to make sure the script is executed

AND ANOTHER IMPORTANT ADDITION Do not use the blender interface lock parameter during rendering, because it completely breaks the add-on and after one rendering with this function, even my script or manual updating of the add-on parameters will not help you, only restarting the blender so that the add-on will update the value again before rendering

If you want to save memory during the final rendering in order to avoid errors, then save your code in the text editor parameters and enable registration in the text menu, which will call you to activate the script immediately when you start the project, save the project and run rendering from the Windows command console, there are a lot of videos on the Internet how to do it, good luck)

import bpy
import random

# Variable for storing the previous frame
prev_frame = None

def randomize_ground_offset(scene):
    global prev_frame

    # Getting the current frame
    current_frame = scene.frame_current

   # Check if the personnel has changed
    if current_frame != prev_frame:
        min_offset = -90.0
        max_offset = 90.0
        current_offset = bpy.context.scene.world.psa_atmosphere_settings.ground_offset

        new_offset = random.uniform(min_offset, max_offset)

        while abs(new_offset - current_offset) < 1e-6:
            new_offset = random.uniform(min_offset, max_offset)

        bpy.context.scene.world.psa_atmosphere_settings.ground_offset = new_offset

        # Updating the value of the previous frame
        prev_frame = current_frame

# Registering the function as a handler before changing the frame
bpy.app.handlers.frame_change_pre.append(randomize_ground_offset)