How to integrate a sky shader in a project?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi Guys, I’ve stumbled upon this cool looking sky shader and proceeded to download it from github. How does one go about integrating a sky shader like this in a project?

:bust_in_silhouette: Reply From: njamster

The github-repository contains an example project, you just need to import it and take a look… In any other project you will need to create a new ShaderMaterial and copy the shader code.

ok but which node do you apply the shader material to? in the environment node somewhere? or the camera?

Macryc | 2020-03-20 14:17

You can apply a shader to anything bearing a material-property. Both Environment- and Camera-nodes don’t. Where it makes sense and where not depends on what the shader is doing. So again, why aren’t you simply looking at the provided example project to figure things out? There the sky shader is the material of the Sprite-node. For the reflections there are separate shaders, set as materials for all mesh instances.

njamster | 2020-03-20 14:44

I’m trying to just replicate the clouds shader, not interested in the reflectivity. I’ve replicated the tree, node naming, and parameters (went side by side). I can’t get this to work. Yes I can see the clouds, in a way, but they are not mapped to the sky (rather, they seem to be mapped to a completely random plane). Also once the first batch of clouds move, they just fade out…

see here

Macryc | 2020-03-20 18:26

I’m trying to just replicate the clouds shader, not interested in the reflectivity.

Then you can delete everything from the example project’s main scene except those:

- scene
  - Sky
    - Sprite
  - scene_cam

I’ve replicated the tree, node naming, and parameters (went side by side).

Including the attached scripts? They’re important as well! Here’s a very reduced example (with all the movement code stripped away, it will just a render moving clouds from a static point of view):

scene.gd (attached to the root-node)

extends Spatial

var iTime = 0.0
var iFrame = 0

func _process(delta):
	iTime += delta
	iFrame += 1

Sky.gd (attached to the sprite)

extends Sprite

onready var global_v = get_tree().get_root().get_node("scene")

func _process(delta):
	self.material.set("shader_param/iTime", global_v.iTime)
	self.material.set("shader_param/iFrame", global_v.iFrame)

scene_cam.gd (attached to the camera)

extends Camera

onready var sky_b = get_tree().get_root().get_node("scene/Sky")

func _ready():
	var iChannel = sky_b.get_viewport().get_texture()
	self.environment = load("res://default_env.tres") as Environment
	self.environment.background_sky.set_panorama(iChannel)

Does this work for you? If not, you probably missed some important node properties.

njamster | 2020-03-21 11:03

Of course I attached the scripts. I’m not new to Godot, just new to this shader. I’m trying to replicate it in a separate project, the idea being that if I can get it to work in a new project I can also ‘import’ it in my game. All properties for the viewport, sprite, camera etc are identical to the source project (i went one by one, side by side). I am missing something somewhere and , for the life of me, i can’t find it.

Macryc | 2020-03-21 11:26

Of course I attached the scripts

There’s no way for me to know this.

I’m not new to Godot

There’s no way for me to know this.

I am missing something somewhere and , for the life of me, i can’t find it.

Neither can I, as you haven’t provided any project nor asked a specific question.

njamster | 2020-03-21 11:56

I know:(. I was hoping for someone who has successfully integrated this shader to look at the screen shot of my problem and guide me.

Macryc | 2020-03-21 13:48

Here’s the project file, btw

Macryc | 2020-03-21 17:16

  1. Select the “noise.png”-file in the “FileSystem”-Tab. Then click on the “Import”-Tab (next to the “Scene”-Tab, above the scene tree). Set compress/mode to “Video RAM” and flags/repeat to “Enabled”, then click “Reimport”.

  2. Select the “Sprite”-node in the tree and uncheck the centered-property.

  3. Select the “scene_cam”-node in the tree and reset the transform-property to the default, i.e. ((1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0))

After those three steps, it should work.

njamster | 2020-03-21 21:28

OK, so after posting the project files I did steps 1 and 2. Didn’t occur to me to reset the camera, which I’ve just done now. The viewport seems to be working fine now (ie, the shader fills the screen etc) however the clouds are not generating. There are some clouds right after starting the scene but they’re not mapped correctly (seem very elongated). They quickly fly away and top gets filled with plain grey sky with no new clouds moving across. Is that the same for you?

Macryc | 2020-03-21 22:02

Is that the same for you?

No. I downloaded the project you provided, only changed what I mentioned above and after that it looked like in the video. No idea why it would look different for you. :frowning:

njamster | 2020-03-21 23:03

OK I’ve got this to work (one other setting was incorrect on import). I realised however that it isn’t possible to just import this into an existing project (happy to be corrected). The shader renders in viewport and therefore affects all materials. You can see what I mean if you place any mesh in front of the camera and give it a spatial material. The sky looks fine but all my other materials have become purple and transparency on png textures does not work. Presumably, I’d have to turn them all into shader materials to get this to work.

Macryc | 2020-03-22 08:14

Still trying to survive through this bug, can you be more specific sir archelot?

Okan Ozdemir | 2020-03-29 07:21

Still trying to survive through this bug, can you be more specific sir archelot?

User njamster - Godot Engine - Q&A has helped you alot and you cant say spesificly what was the third error, just say “happy to be corrected” Please utter them Sir! User Macryc - Godot Engine - Q&A

Okan Ozdemir | 2020-03-29 08:40