This project adds a dynamic sky shader to your project. It is based on https://github.com/danilw/godot-utils-and-other.
For GODOT 4: https://github.com/Lexpartizan/Godot_4_sky_shader
Complete feature list
- day-night-cycle
- Sun
- Moon
- Stars
- Clouds
- God Rays (via God Rays Plugin by @SIsilicon)
- the combination of both has a noticable performance impact *this videotutor explain how_to setup godrays plugin for this sky scene in editor. (https://www.youtube.com/watch?v=kAn39VPiNjY) I highly recommend downloading the addon folder from https://github.com/SIsilicon/Godot-God-Rays-Plugin but just in case i put version 1.01 in addons.zip
The Third Person Controller used in the demo scene uses the code from https://github.com/NIK0666/GodotThirdPersonController, as featured in the following video: https://youtu.be/jxtUtUo4aEI
The shader and demo scenes target Godot 3.2.
There is a "version_for_Godot_3_1_2.zip" file which contains a subset of this project's content and works in Godot 3.1. Godrays dont support for Godot 3.1.2.
Attention! After change texture resolution reload scene with sky! Now we have two scenes:
- Old scene sky_with_simple_colors, where i get sky color from mix simple colors.
- New scene sky_with_scaterring, where i get sky color from fake scaterring shader, based on https://www.shadertoy.com/view/Ml2cWG But with scaterring dificult setup colors for sunset and day sky, so we have two scenes.
The demo scene Sky.tscn showcases some of the abilities of this dynamic sky.
Download the project (explained in the next chapter) and open it via Godot Editor.
Parameters in the Sky scene:
- Moon Phase: Covers the moon with a shadow from top-left of the moon to the bottom-right (and vice-verca)
- Coverage: Specifies how much the sky is covered by clouds
- Height: How close the clouds are to the viewer
- Quality Steps: If the steps are < 20, the 3D clouds are exchanged with 2D clouds
- Wind Strength: Speed of cloud movement
- Lightning Strike: brightens the sky for less than a second
Additional changes can be made which are not currently exposed in the GUI of the demo scene, such as
- traversal route (axis of rotation and start position) of sun and Moon [] First Vector3(0.0,-1.0,0.0), in the highlighted lines of code, this is start position. You can change this to distance the Sun from the zenith. Second Vector3(1.0,0.0,0.0) this is axis of rotation.
Same information for Moon.
- wind direction, ie. direction the clouds move set variable wind_dir (Vector2) from your code and call function _wind(value), where value is wind power.
Downloading for Godot 3.2
- Download the project using a) Git via command line or b) via the projects Code webpage on Github using the "Clone or download" button and then "Download ZIP"
- Copy folder "shaders" and files "Sky.tsn" and "default_env.tres" to your project.
- Add Sky.tscn on tree.
- Add addon GodRays if you need (see video).
Downloading for Godot 3.1
- Download the zip called "Godot_sky_shader-3.1.2.zip" by clicking on it on the projects Code webpage
- After the download, navigate in your File Manager to the downloaded zip file and extract the zip file to get all the project files you need
Preparation
- Open your Godot project files using your file manager
- move the files Sky.tscn as well as the complete folder called "shaders" into your project via the file manager
- when selecting the Godot Editor again (or when opening your project with the Godot Editor), the files will be imported automatically
Using as it is
- you can use the Sky.tscn scene itself: It has a GDscript attached, which gives you controls to adjust the settings. When you are satisfied, you can hide the node called
Control
(it contains the GUI elements for adjusting your settings for the dynamic sky shader) - you need to keep the same file structure as on Github, if you want to use the Sky.tscn scene
- your environment file (when creating a new project, the Godot Editor creates a new
default_env.tres
file for you) needs to have in its Background section the valueSky
forMode
(this is currently the default setting) and you need to create a newPanoramaSky
in the dropdown menu next toSky
- this is a bit confusing, because Mode has the value Sky and Sky has the value PanoramaSky. But it should look like this in your Inspector
Background
Mode: Sky
Sky: PanoramaSky
- this is a bit confusing, because Mode has the value Sky and Sky has the value PanoramaSky. But it should look like this in your Inspector
- you need to press on the button for "Play Scene" in the Godot Editor, as this scene is not your main scene!
required File structure in your project (so that the file Sky.tscn can find its dependencies):
/shaders (folder with shaders)
/Clouds.shader
/Sky.shader
/noise.png
/noise.png.import
Sky.tscn
default_env.tres
icon.png
The other files are for demonstration purposes.
Changing the file structure will break the dependencies for the file Sky.tscn! You will have to fix this yourself, then.
Example on how to set up the shaders in your project if you don't want to use the given Sky.tscn
file:
- You need a scene where you want to use the dynamic sky shaders
- add a WorldEnvironment node to your root node, if you don't already have one
- select this node and set the reference to the
Environment
field: This should be yourdefault_env.tres
file (or however you renamed it) - click on the *.tres file you just referenced and do the following changes to your settings in the
Background
section:- set
Mode
toSky
via the dropdown menu - for the field below
Mode
calledSky
, create a new toPanoramaSky
via the dropdown menu
- set
- select this node and set the reference to the
- add a light node to your root node, if you don't already have one, e.g. a directional light
- add one Viewport node to your root node, and add a Sprite node as a child to this Viewport -> This setup is for the sky
- select the Sprite node you just created
- navigate to the CanvasItem section
- in the Material submenu you need to create a new ShaderMaterial
- open the newly created ShaderMaterial, click on the dropdown menu next to the field called
Shader
and load the CloudlessSky.shader file
- add another Viewport node to your root node, and add a Sprite node as a child to this Viewport -> This setup is for the clouds
- select the Sprite node you just created
- navigate to the CanvasItem section
- in the Material submenu you need to create a new ShaderMaterial
- open the newly created ShaderMaterial, click on the dropdown menu next to the field called
Shader
and load the Clouds.shader file
- Take the GDScript code from the
Sky.tscn
file and create a new script for your root node - testing: either press the button for "Play Scene" in the Godot Editor, or set this scene as as your main scene!
- Stretched sun and moon (see issue #5) (becouse this panorama, but for the moon, you could come up with a solution by projecting it onto the camera screen. But I can't do it :-( )
- Flickering on the cloud edges (these are noise features that can be significantly reduced by increasing the number of quality_steps, but this affects performance.)
- A vertical seam on the sphere of the PanoramaSky is visible when the clouds move over it (see issue #2)
- it often throws an error to the console, but it doesn't interfere with the scene work. ERROR: create_from_image: Condition "p_image.is_null()" is true. At: scene/resources/texture.cpp:199 Help wanted.
- Currently only support GLES3. If your project is in GLES2, you will see
drivers/gles2/shader_gles2.cpp:130 - CanvasShaderGLES2: Fragment shader compilation failed:
0(600) : error C1101: ambiguous overloaded function reference "min(int, int)"
Change to GLES3 to fix.