Page MenuHome

Cycles: Add option to sky texture to specify the sun direction by another object
Needs ReviewPublic

Authored by Lukas Stockner (lukasstockner97) on May 8 2016, 7:56 PM.

Details

Summary

This patch adds an option to the Cycles Sky Texture node that allows the user to
select a lamp to specify the sun direction of the sky. If a lamp is selected, the
manually specified direction is hidden and ignored.

The only remaining problem is that rotating the lamp while being in viewport
render mode doesn't trigger an update - I'm not sure how to implement that,
hints would be appreciated ;)

Diff Detail

Repository
rB Blender
Branch
sky-sunlamp
Build Status
Buildable 730
Build 730: arc lint + arc unit

Event Timeline

Lukas Stockner (lukasstockner97) retitled this revision from to Cycles: Add option to sky texture to specify the sun direction by another object.

You can use has_object_dependency() on that node to make sure viewport update is correct.

However, in this case i'm not sure having it a node option is the way to go, more flexible would be to have it as a socket. And then most of the time you wouldn't even need to worry about having an extra object (for which you'll need to keep track about visibility, or if it's an Empty then i'm not sure Cycles will really update it's matrix) you can use Normal node to define direction straight from the shader. Or you'll be able to do some nifty tricks like distorting the direction for some artistic choise.

Forgot to mention.. We can also consider adding Other Object Info node, to query direction/transform of another object. Not sure it's really that needed tho.

I think having another object around is not a problem, because the Cycles sky texture does not include a sun component. So if you want the sun you need to add a sun lamp anyway, and then you might as well use that sun lamp to control the sky texture.

Maybe there's a better way to solve it, this sun/sky is a feature that doesn't really fit cleanly in the world or sun lamp settings. But unless we come up with a better solution I think this patch is a step in the right direction. Controlling the direction in the viewport seems easier than doing it from a shader.

Added the dependency, the viewport updates correctly now.

The Sun-Sky thing is tricky indeed - I've been playing around with adding the Sun component of the Hosek-Wilkie model a while ago, and while it works quite well, I don't know how to integrate it properly - since the sun is so tiny, having it as part of the Sky node makes it necessary to use World MIS with a huge resolution for something that could easily be sampled analytically, but having it as a Node that would connect to a Sunlamp shader is not really better...

People are used to Sun Position or Geographical Sun addons for architectural renders to see shadows and enlightened areas.
It is really rare to see the sun inside render frame except for a beauty render with reflections where an HDRI sky will be used instead of sky texture.

It is cool to have Sun represented inside sky texture. But it should have a size. BI sky model have a size for Sun. Currently, Eevee adds a bloom effect directly on sunlight reflection.

Yes, people will still use Sun lamp Size to have wanted shadows instead of a huge World MIS resolution.
IMO, it makes more sense to have Sun size as Sky Texture option as long as none lamp is used by it.
When a Sun lamp is used as reference, it should be logical to use its size parameter from lamp data as well as its direction.
If object used is not a lamp but an empty, it could be its scale.

But I see no reason to create a node for Sun Lamp shader.

Thanks for your efforts. From several years I use this script named Link_Sky_to_Sun_Lamp.py by Oscurart and Greg Zaal: https://www.dropbox.com/s/wap2jimkud5dntv/link_sky_with_sun.py

It works very well and could be of inspiration to you. This is the discussion where I got it: https://blenderartists.org/forum/archive/index.php/t-297721.html