Day/Night cycle setup. No shaders needed.

This is my solution for a Day/Night cycle setup. The trick is to control the Energy and Color of lights with a simple Python script.

Blend1: http://www.mediafire.com/?4c2212v1c2mp2b1
Blend2: http://www.mediafire.com/download/rpdes6s3x6xwnz1/daylight_setup2.blend


And here you have the same system demonstrated in the Unlimited Planar Reflections scene. (This setup is not as pretty as the clean example above)

Blend: http://www.mediafire.com/download/qm1jvihx5s8dd5c/daylight_099.blend


Thanks I learned much from your setup.

For improvement the bending in the background should be smooth gradient while sun rises also when mouse is tilted on the Z axis or upward toward sky…

This may be a blender internal problem because sometimes in my world settings I see bending and no smooth gradient that blends the sky when rendering.

Example below.



Ahh ok! Interesting, well I do not know how to fix it, but it might be possible to get an answer in the support forum. My greatest problem right now is that the reflections in the water is of the backfaces, so the lighting is wrong. However, it might be worth to put this issue forward to Martin Upitis in the thream i mentioned above, maybe he has some solution for it!

I discovered that there was an error in the LightSetup python script. The sun only goes up to 50% brightness.

I make the corrections in the file.

The more correct code is:


from bge import logic as g
import math


scene = g.getCurrentScene()
sun = scene.objects['Sun']
Skyl = scene.objects['SkyLight']
Sdiff = scene.objects['SunDiffuse']

uniT = scene.objects['UnitVector']
Pi = 3.14159

#cZ = ((uniT.worldPosition.z-4.75)/10)
cX = ((uniT.worldPosition.z-4.85)/5)

#if cX<0: uZ = 0
#if cZ>0: uZ = (0.5*(math.log10(cZ)+2))

uZ = cX

cont = g.getCurrentController()
own = cont.owner

Skyl.energy = 0.15*uZ
Sdiff.energy = 0.1*uZ
sun.energy = 1.5*uZ
sun.color = (1,0.5+0.6*uZ,0.3+0.8*uZ)

Getting errors with daylight_099:


Read new prefs: C:\Users\User\AppData\Roaming\Blender Foundation\Blender\2.69\co
nfig\userpref.blend
found bundled python: C:\Users\User\Desktop\blender\2.69\python
drop file C:\Users\User\Desktop\Party\daylight_099.blend
read blend: C:\Users\User\Desktop\Party\daylight_099.blend
Detected GL_ARB_texture_env_combine
Detected GL_ARB_texture_cube_map
Detected GL_ARB_multitexture
Detected GL_ARB_shader_objects
Detected GL_ARB_vertex_shader
Detected GL_ARB_fragment_shader
Detected GL_ARB_vertex_program
Detected GL_ARB_depth_texture
Detected GL_EXT_separate_specular_color

Blender Game Engine Started
---- Vertex Shader Error ----
ERROR: 0:40: 'assign' :  l-value required "sunApos" (can't modify a uniform)


---- Vertex shader failed to compile ----
---- Vertex Shader Error ----
No errors.

---- Fragment Shader Error ----
WARNING: 0:122: 'assigning' : implict conversion between types allowed from GLSL
 1.20
WARNING: 0:123: 'assigning' : implict conversion between types allowed from GLSL
 1.20

No errors.

---- GLSL Program ----
No errors.

---- Vertex Shader Error ----
No errors.

---- Fragment Shader Error ----
WARNING: 0:14: 'assigning' : implict conversion between types allowed from GLSL
1.20

No errors.

---- GLSL Program ----
No errors.

Python script error - object 'lens', controller 'Python1':
Traceback (most recent call last):
  File "texrender.py", line 16, in <module>
KeyError: "CList[key]: ''flare1'' key not in list"
Python script error - object 'blur', controller 'Python':
Traceback (most recent call last):
  File "blur.py", line 8, in <module>
KeyError: "CList[key]: ''Lamp'' key not in list"
[...]

I changed the file so download again, I think the problem was log(negative number), so the change in the code is the following


cZ = (uniT.worldPosition.z/1000+0.05)

#option 1
#if cZ<0: uZ = 0
#if cZ>0: uZ = 0.5*(math.log10(cZ)+2)

#option 2
uZ = cZ


Really nice!
But for somehow blender crashes when changing the shadow type to variance.

I have always had that problem, I can never use variance :confused:

Umm… “always” ? Actually it works but not in this blend.

That is sweet love the water effect on camera “water dripping”

Ah yes, it seems to work on a new scene. Well, that is one thing to bug hunt for :confused:

Out of all the day/night cycles I’ve seen for blender, this one is the best looking! However, when I downloaded it to try and implement it into my game, it’s really confusing. How exactly does it work? I don’t see how the “sun” is next to the models, and then when you run the game engine it’s against the sky.

Is it really as simple as copying the objects into my scene and copying the scripts?

I don’t even see where the logic blocks/scripting is for the Z and X to make the time go forward and backward.

on the first demo (daylight_setup) check out the SunAxis empty, it has the Z and X controls.