Animating an hdr daylight environment sky

Forums: Animating an hdr daylight environment sky
Forum for OctaneRender Lua scripting examples, discussion and support.

Animating an hdr daylight environment sky

Postby MB » Sun Mar 12, 2017 6:52 pm

MB Sun Mar 12, 2017 6:52 pm
A while back I wrote an animation script for doing walkthroughs in octane that has been posted here. I would like to extend that script to include rotating an hdr sky texture in sync with the sun animation already included in that script.
Below is a segment of the code where I grab the daylight environment and copy it.

I can't find a call to determine if a sky texture hdr has been assigned to the skytexture pin, and going straight to the projection node on the hdr image doesn't work either.
Can someone point me in the right direction, I basically want to rotate the sky at a rate of 18deg per hour during a daylight sun animation by setting an animator the Y angle of a spherical projection. Alternatively what would be a different approach to achieve the same thing?

thx



local copyEnv = copyRt:getConnectedNode(octane.P_ENVIRONMENT)

copySunDir = nil

if not copyEnv then

showError("Walkthrough Error!", "A 'Daylight' or 'Texture' environment node must be connected to the render target", true)

else

-- Check if a daylight environment
if copyEnv:getProperties().type == octane.NT_ENV_DAYLIGHT then

-- Get the sun direction from the daylight environment
copySunDir = copyEnv:getConnectedNode(octane.P_SUN_DIR)

if not copySunDir or copySunDir:getProperties().type ~= octane.NT_SUN_DIRECTION then

showError("Walkthrough Error!", "No sun direction connected to the daylight environment", true)

end

THESE TWO DO NOT WORK
copySkyTex = copyEnv:getConnectedNode(octane.P_SKY_TEXTURE)
copySkyTex = copyEnv:getConnectedNode(octane.P_PROJECTION)
END THIS DOES NOT WORK

if not copySkyTex or copySkyTex:getProperties().type ~= octane.NT_PROJ_SPHERICAL then

showDebugInfo("copySkyColor","Not a Texture")

end



else
Windows 7 Enterprise, 2x Intel Xeon X5650 2.66 GHz, 24GB Ram, GTX 590, Quadro 5000, Quadro K4200
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 118
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Animating an hdr daylight environment sky

Postby bepeg4d » Mon Mar 13, 2017 3:05 pm

bepeg4d Mon Mar 13, 2017 3:05 pm
Hi,
in this way it should work:
Code: Select all
local rt    = nil


local copyEnv = copyRt:getConnectedNode(octane.P_ENVIRONMENT)

copySunDir = nil

if not copyEnv then

    showError("Walkthrough Error!", "A 'Daylight' or 'Texture' environment node must be connected to the render target", true)

else

    -- Check if a daylight environment
    if copyEnv:getProperties().type == octane.NT_ENV_DAYLIGHT then

        -- Get the sun direction from the daylight environment
        copySunDir = copyEnv:getConnectedNode(octane.P_SUN_DIR)
    end

    if not copySunDir or copySunDir:getProperties().type ~= octane.NT_SUN_DIRECTION then

        showError("Walkthrough Error!", "No sun direction connected to the daylight environment", true)

    end

    --The pin is P_TEXTURE, not P_SKY_TEXTURE
    copySkyTex = copyEnv:getConnectedNode(octane.P_TEXTURE)
    copyProjection = copySkyTex:getConnectedNode(octane.P_PROJECTION)
    --this is another node inside copySkyTex

    if not copySkyTex or copyProjection:getProperties().type ~= octane.NT_PROJ_SPHERICAL then

        showDebugInfo("copySkyColor","Not a Texture")

    end
end

ciao beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 6559
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Animating an hdr daylight environment sky

Postby MB » Tue Mar 14, 2017 4:08 am

MB Tue Mar 14, 2017 4:08 am
Many Thanks
Windows 7 Enterprise, 2x Intel Xeon X5650 2.66 GHz, 24GB Ram, GTX 590, Quadro 5000, Quadro K4200
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 118
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Animating an hdr daylight environment sky

Postby MB » Tue Mar 14, 2017 1:27 pm

MB Tue Mar 14, 2017 1:27 pm
bepeg4d,

Thankyou for your help,

unfortunately I'm still struggling, it is not obvious to me from the api documents, how I query and change the Y Angle property on a spherical projection node. Any tips would be greatly appreciated.

thx

Mark
Windows 7 Enterprise, 2x Intel Xeon X5650 2.66 GHz, 24GB Ram, GTX 590, Quadro 5000, Quadro K4200
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 118
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Animating an hdr daylight environment sky

Postby bepeg4d » Tue Mar 14, 2017 2:27 pm

bepeg4d Tue Mar 14, 2017 2:27 pm
Hi Mark,
did you know about this scripted graph by Paul?
http://poserphysics.blogspot.it/2015/04 ... xture.html
I guess that you should find what you need, if not, drop me a line.
Happy scripting,
ciao beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 6559
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Animating an hdr daylight environment sky

Postby MB » Tue Mar 14, 2017 11:54 pm

MB Tue Mar 14, 2017 11:54 pm
bepeg4d

Thanks once again,

I swapped out the North Offset for a Sun Direction Node in Paul's code and got something working, still have a little more to do unraveling the output from the sun direction node, the whole thing returns a single number that seems like a modified sine function that I need to turn back into the range of 0 - 360 deg.

best

Mark
Windows 7 Enterprise, 2x Intel Xeon X5650 2.66 GHz, 24GB Ram, GTX 590, Quadro 5000, Quadro K4200
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 118
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Animating an hdr daylight environment sky

Postby roeland » Thu Mar 23, 2017 1:58 am

roeland Thu Mar 23, 2017 1:58 am
The easiest way to get the sun direction is to query it via the input pin of the sun environment:
local v = environment:getPinValue("sundir")

Alternatively, given just the node, both the float node and the sun direction node will have a A_VALUE attribute which contains the direction:
local v = node:getAttribute("value")

By default the +Z is south, the rotation away from the +Z axis can be calculated as atan2(v.x, v.z): rotationY = math.atan2(v[1], v[3]). But you also have to take the sun position in your environment map into account.

I'm not sure how you want to animate this though. The sun also goes up and down, so you can only match the sun position in your environment map on two specific times of the day. At any other times the sun will be too low or too high compared to your environment map.

On a projection node you can similarly query and set the transform. You can use octane.matrix.makeRotY to make a rotation around the Y axis, and octane.matrix.split to get an approximate decomposition in rotation, translation and scale.
Code: Select all
-- there's a few ways to do this, but this way works regardless of what type of
-- node is connected to the transform pin
local M = projection:getPinValue("transform")
local rotation, scale, translation = octane.matrix.split(M, octane.matrix.rotationOrder.ROT_YXZ)
local rotationY = rotation[2]
...
-- set a new transform with a rotation:
M = octane.matrix.makeRotY(rotationY)
projection:setPinValue("transform", M)


--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1738
Joined: Wed Mar 09, 2011 10:09 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 1 guest

Wed Aug 21, 2019 2:36 am [ UTC ]