Jump to content

Day and Night Cycle shader

Recommended Posts

Wasn't sure where to put this since I can't get it to work in the workshop since it needs a big controlscript.




Anyway here it is :



  • Preetham skymodel is used (look up on wikipedia)
  • UnCharted2 tonemap
  • Procedural stars at night
  • Procedural Clouds.
  • Alot of adjustables


  • Download at bottom of page here
  • Unzip straight into the projects root folder


  • Drag the Sun prefab from the prefab folder
  • You can adjust all sorts of stuff in the script tab of the Sun object
  • It will adjust to the rotation of the Sun (which is a directionallight) when you run (F5/6)
  • Works very well with bloomsettings : luminance=0.11 midgray=0.158 whitecutoff=0.298
  • Added one small example map as well in the maps folder.

Update :

  • Fixed the ATI issue, thanks TattieBoJangle
  • Fixed the cloudscale issue, thanks HaydenMango
  • Skydome now follows the camera (if found)
  • Skydome resizes to the camera's drawdistance (if found)
  • Added adjustable bloom settings (if workshop the bloom is added the scene)

Edit: soon inthe workshop.

Link to post

Really great job, shad (and, klepto too, i think?)! smile.png!!


There's still room for improvement, but what you have already done, is really awesome!!


Some godrays coming through the clouds would really be great! *HINT* *HINT* wink.png

Link to post

Well, either way (havent tested), but in theory you can:


1. store your world objects in an array or list when loaded from the map : http://www.leadwerks.com/werkspace/topic/6386-c-finding-entities-in-a-scene/page__hl__map or http://www.leadwerks.com/werkspace/topic/6887-communicating-from-lua-to-c/


2. check if entity->GetClassName=="DirectionalLight" && entity->GetColor().x <=0 then it's night.

Link to post

I finally got around to adding this to my project. It looks sooo amazing. You are the best Shadmar thank you!!!


Here is a little preview of what it looks like in game. It is speed up to be 5 times faster so the video wouldn't be super long.


  • Like 1
Link to post

Tip for adding fast bloom (good looking) to the sky:


1. Add bloom from the workshop to your scene tab : http://steamcommunity.com/sharedfiles/filedetails/?id=256268930&searchtext=

2. Add a pivot to your map and connect this bloom control script :


function Script:UpdateWorld()

if self.camera==nil then

local world=World:GetCurrent()

for i=0,world:CountEntities()-1 do

if world:GetEntity(i):GetClass()==Object.CameraClass then














Edit: Correction, WhiteCutoff 0.298

Link to post

Hey shad just wanted to ask if

self.shader:SetFloat("cloudscale",self.cloudheight) -- lesser is bigger

is supposed to be

self.shader:SetFloat("cloudscale",self.cloudscale) -- lesser is bigger

in the UpdateWorld() function.

Link to post

Looks GREAT! I get Failed to compile fragment shader any ideas?



Fragment shader failed to compile with the following errors:

ERROR: 0:317: error(#160) Cannot convert from: "3-component vector of vec3" to: "highp float"

ERROR: error(#273) 1 compilation errors. No code generated

Failed to compile fragment shader.

Error: Failed to compile fragment shader.

Link to post

Do you run of an intel integrated card?, they often complains when vecs are converted.


Anyhow change line 317 to :


float cmix=cloud.x*cloudmix;

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...