HDRI Sun Aligner v1.6

Can it be sychnronised with real sun position on the sky?
Like in sun position plugin?

Thanks

Currently only the features described in the OP and on the GitHub readme.

Version 1.3 is up on GitHub with the following fixes and improvements:

  • Fix problem with processing large HDRI’s (8k, 16k)
  • Implemented driver that can be added to any object to align z-rotation with HDRI mapping node z-rotation (see previous discussion)

Can it be used in lower versions. Not planning to shift to 2.8 soon.

1 Like

Hi, I’m only maintaining a version for Blender 2.8 (this is my first addon and I focused on learning the API for Blender 2.8).

My sun came in at my world origin and was pointing west. I moved the sun to the south side of the house pointing north to shine into a south kitchen window. I then adjusted the longitude to 90 to hopefully turn the hdri 90 degrees clockwise. I then set latitude to 10 for a sun low in the horizon. Am I doing things right or all wrong? Thanks

Hi, some comments from my side:

  1. A new sun is created at origo; you can move it to any position but note that the light is not affected by position, only rotation (only applies for light source of type sun).

  2. The latitude and longitude means “sun position in the sky”. Latitude goes from -90 (south pole, light directly from below), 0 at the equator and +90 (north pole, light shining straight down). The longitude goes from -180 to 180. E.g. using +45 for latitude will correspond to the sun half way between the horizon and zenith. Then you can adjust the longitude for the direction (i.e. from “Southwest”). Using a latitude of +10 should give you a low sun.

  3. Regarding rotation, by using the “Add rotation driver”, the sun position (longitude) will be driven by the rotation of the HDRI if a mapping node is used in the world setup. This allows to HDRI to be rotated and keeping the correct sun position.

Please let me know if something is unclear or if you have any further questions.

Thank you akej74 for your generous reply. I will see if I can figure it out.

I’ve been using Blenderguru’s Pro Lighting pack, with which this addon does not work. But I’m very happy to discover that it works well with Easy HDRI (which essentially as good as Pro Lighting Skies minues the HDRI pack), so thanks for this plugin! I am going to include in an upcoming video for addons for architecture

I am just wondering if there is a way to improve the usability by not having to open an image editor window to align the sky?

Also it would somehow be great if the work from HDRI sun aligner and Easy HDRI could be combined

Hi, thanks for the feedback, I like to make the addon more user friendly. The preview of the sun position that is displayed in the image editor is not required, I will look into making this a separate function, e.g. a new button “Display sun position preview” or similar. This will allow for the sun position to be calculated without having a image editor open.

What I would like to have is a similar preview as in “Easy HDRI”, that shows the preview with sun position as a small image in the panel. I haven’t been able to figure out how to do this with an internal image, only using images in disk (as it’s done in Easy HDRI). My sun position preview image is created internally and not stored on disk. Of course, it would be possible to save it as a temp-file on disk, but I would like to avoid that if possible.

Maybe someone in the community can help me with some ideas on how to show an internal image in a preview window (or similar)…? The only way I have found to show the image is using the image editor, but that requires a manual step by the user in case no image editor is open.

New version (1.4) is up on GitHub with the following changes:

  • Added a new “Preview” operator that opens a new window to display the preview of the sun position
  • Sun position can be calculated without having an Image Editor open

Please let me know how this new version works for you.

7 Likes

hello i hope you add support for 2.81
the mapping node was changed and rotation driver doesn’t work unfortunately
or

is there a workaround a line text change at HDRI sun aligner to make it work for 2.81

2 Likes

Thanks for the bug report, it’s now fixed and I have published version 1.5 on GitHub, please have a look. This new version works for both 2.80 and 2.81.

I had to change the code as follows (in operators.py), as the mapping node attributes has changed in 2.81.

if mapping_node:
    # Check for mapping node attributes in Blender 2.80
    if hasattr(world_nodes[mapping_node], 'rotation'):
        # Path to HDRI mapping node z-rotation value
        data_path = f'node_tree.nodes["{mapping_node}"].rotation[2]'            
            
    # If not, assume Blender 2.81 mapping node attributes
    else:
        # Path to HDRI mapping node z-rotation value
        data_path = f'node_tree.nodes["{mapping_node}"].inputs[2].default_value[2]'
2 Likes

Hi akej74,
many thanks for your great add on, really useful and well done!
I have a couple of question (I am using now Blender 2.82 on PC) :
1 - What exactly is the “Rotate active object” command for? I mean, why should the active object be aligned with the sun position? For what reason or function?
2 - Why if you change the Latitude or Longitude values doesn’t change in the preview and in the scene? In your short guide in GitHub you wrote: “…Updated “Longitude and Latitude” values are displayed in the panel (can be changed manually)”.

Thank you for a glad replay and again, great job!
Sincerely

Hi Duca, I added the “Rotate active object” more for testing the rotation function when developing the addon, but then decided that it may be useful if you like to align e.g. a spotlight with the sun direction. Or, if you are modelling a solar panel, you can align it with the sun automatically :slight_smile:

The preview is currently only displaying the original sun position, not the updated position if you change long/lat manually (I could add that in a future update). But if you have changed the long/lat values, the new position will be used for the “Add new sun” and “Rotate active object” functions.

1 Like

hallo akej74,
i notice an issue.
If I use an HDRI and your addon, the position of the Added “virtual sun” created the same shadows.

But if in insert the correct long/lat of the sun of the HDRI ( got from the original location, date, and hour) the Virtual sun is not more aligned with the original sun of the HDRI.
Do you have an idea why this is happening?

You can see/try it if you download an HDRI from HDRI Heaven because they have all the long/lat positions values.

P.S. any news about the update of this great addon? I mean above all to change the sun long/lat position manually?

Hi @Duca, I’m calculating the coordinates as follows:

  1. Find the sun position on the image (x-y pixel coordinate), example:

  2. Convert pixel coordinates to latitude and longitude based on the following linear mapping, i.e. upper left corner = (+90 -180), lower right corner = (-90 +180):
    image

  3. The latitude and longitude is then converted to a vector for rotation as follows:

# Calculate a vector pointing from the longitude and latitude to origo
# See https://vvvv.org/blog/polar-spherical-and-geographic-coordinates 
x = cos(latitude) * cos(longitude)
y = cos(latitude) * sin(longitude)
z = sin(latitude)

# Define euler rotation according to the vector
vector = mathutils.Vector([x, -y, z]) # "-y" to match Blender coordinate system
up_axis = mathutils.Vector([0.0, 0.0, 1.0])
angle = vector.angle(up_axis, 0)
axis = up_axis.cross(vector)
euler = mathutils.Matrix.Rotation(angle, 4, axis).to_euler()

These calculations is based on various sources I have found online, not sure why it doesn’t match the info provided by HDRI haven… Maybe someone can add some insights?

Edit: Let me look into the possibility of changing the position manually as well.

1 Like

I really have no idea… I am just a creative.
Anyway, maybe it could be something about the incorrect position of the HDRI related the 3D scene or vice versa.
The real sun position is an important parameter above all for the color temperature of the sun and the real lat /long gives these infos, so that, after the sun creation you can change the color temperature with the real one.

Hi. I are interested in this addon… let me make a look in the code.
Cheers…

A pull request on GitHub is always welcome if you find any improvement areas :slight_smile: