Godot Version
4.2.2
Question
When going from a level scene back to the main menu scene, it gives me the error: material_free parameter "material" is null
in regards to the WorldEnvironment’s sky box shader material. This only occurs with the shadermaterial, and not any other sky material. Below is the script for my shader if necessary.
shader_type sky;
#include "res://addons/ShaderLib/Artistic/Adjustment/Hue.gdshaderinc"
#include "res://addons/ShaderLib/UV/RotateUV.gdshaderinc"
uniform float star_height = 5.;
uniform float star_blend : hint_range(0.0, 1.0, 0.01) = .1;
uniform float depth_blend : hint_range(0.0, 1.0, 0.01) = .1;
uniform float flare_ratio : hint_range(0.0, 1.0, 0.01) = .1;
uniform float star_size = 5;
uniform float twinkle_speed = 5.;
uniform int star_layers = 3;
uniform bool colored = true;
vec2 RandomVec2(vec2 seed) {
seed = fract(seed * vec2(172.45, 784.29));
seed += dot(seed, seed + 573.34);
float x = fract(seed.x * 177.32);
float y = fract(seed.y * 277.21);
return vec2(x, y) - .5; // from -.5 to .5
}
float Star(vec2 uv, float flare) {
float star = .005 / length(uv);
float rays = max(0, 1. - abs(uv.x * uv.y) * 1000.) * star / 2.;
star += rays * flare;
return pow(star, 3);
}
vec3 StarLayer(vec2 uv) {
vec2 grid_uv = fract(uv) - .5;
vec2 grid_id = floor(uv);
vec3 stars = vec3(0);
for (float y = -1.; y <= 1.; y++) {
for (float x = -1.; x <= 1.; x++) {
vec2 offset = vec2(x, y);
vec2 rv = RandomVec2(grid_id + offset);
float size = (rv.x + .5) * star_size;
float animated_size = (sin(TIME * rv.x * twinkle_speed) *.4 + .6) * size;
float flare = smoothstep(star_size * (6. - flare_ratio), star_size, size);
vec3 star_color = hue(vec3(1, 0, 0), rv.y * 2., 1);
star_color *= vec3(1, .2, 1. * size);
if (colored) {
stars += Star(grid_uv - offset - rv, flare) * animated_size * star_color;
} else {
stars += Star(grid_uv - offset - rv, flare) * animated_size;
}
}
}
return stars;
}
void sky() {
float blend = smoothstep(star_blend, 1, 1.0 - abs(EYEDIR.y));
float depth_curve = pow(abs(EYEDIR.y), depth_blend);
for (float i = 1.; i <= float(star_layers); i++) {
vec2 uv = EYEDIR.xz / depth_curve * star_height * i;
uv += RandomVec2(vec2(i, i + 22.)) * i * 3.3;
if (EYEDIR.y < 0.) {
uv = rotate_uv(uv, vec2(0), 160, true);
}
uv *= mix(1.0, 0.5, smoothstep(-1., 1., abs(EYEDIR.y)));
COLOR += StarLayer(uv) * blend;
}
}