Sky transitions


I wrote four lines of code to do some basic interpolation.
Goes something like this,

#l = "line" or distance from a to b; p = current point between the two
def iLerp(a, b, l, p):
    abs_diff = abs(a - b)
    real_diff = abs_diff/l
    dirn = 1 if a < b else -1
    return a + real_diff*(p*dirn)

Then I figured out this can be used to transition from one color to another, which would be neat for a simple day night cycle. I had a timer class already written, so I took it out for a spin.
Given two color vectors a and b, the time of day and start/end point, we get something like,

#60*0.0168 = 1.008~
#use this to approx time as a float so e.g. 17:55 = 17.924
timeco = ( worldTime.hour + (worldTime.min*0.0168) )

#we want to start at zero, so substract start hour of transition
p = (timeco - 12) if 24 > timeco >= 12 else timeco

#now define length of transition (hours between a and b)
#for simplicity's sake of this example, we go from 0 to 12 and 12 to 0 (24)
l = 12

color = [0,0,0]
color[0] = iLerp(a[0], b[0], l, p)
color[1] = iLerp(a[1], b[1], l, p)
color[2] = iLerp(a[2], b[2], l, p)

Anyhoo, my time to float approximations are off by a few decimals, but this works good enough at making transitions smooth; the new color never “pops” in. The basic principle for having other numerical values interpolate over time is the same, you just pass in integers or floats individually rather than build a color vector; useful if you want to increase or decrease fog intensity or depth at cetain times of day.

Adding a few more steps to the transition, I got this

Phew. With all of that out of the way, with more or less the same code we could transition from one texture to another – just a matter of writing another function to do the image buffer mambo. I can take care of that no problem, but how in blazes does one grab a sky texture through python? I could just slap a regular texture on a background scene dome and manipulate that, sure, but it bugs me that I can’t figure this one out. How do you folks do it?

Exaclty like how you said it, i slap on a background scene, put a dome in it and use that for my stars and or clouds, then i alter the background color during runtime, so it nicely fades out/in including the colors.

Here is what i made a year ago using the above

I don’t work with grabbing textures, but can’t you just grab the material and then the slot the texture is in? and do with it what you want?

WELP, I wanted to work with the world node panel and take textures directly from there – made sense to do it all in that place since it has it’s own compositor tab and all – but nevermind, it’s a pain to use. I’ll go with the dome instead and do the texture mixing on that material.

from mathutils import Vector

colorFrom = Vector((0, 0, 0))
colorTo = Vector((1, 0, 1))

factor = .1

lerped = colorFrom.lerp(colorTo, factor)


Oh, thank you. I should pay closer attention when reading through the docs :B

Anyhoo, I’m settling on domes on background scene being the way to go. With a combination of color transitions, rotating a plane around to fake the sun, musgrave for clouds and a noise texture to make stars, I got something kinda pretty.

1 Like