Skip to content

Instantly share code, notes, and snippets.

@etherealxx
Created September 6, 2024 08:18
Show Gist options
  • Save etherealxx/72c8afd4fe8d45c2dfabadf7b39ec4fc to your computer and use it in GitHub Desktop.
Save etherealxx/72c8afd4fe8d45c2dfabadf7b39ec4fc to your computer and use it in GitHub Desktop.
pretty Godot 3D WorldEnvirontment template, just instantiate it as a child to your 3d scene tree that hasn't had a WorldEnvironment node yet
; Compiled by me into a single instantiable Godot 4 scene
; MIT No Attribution License
; https://opensource.org/license/MIT-0
; Copyright (c) 2024 Etherealxx
;
; Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
;
; THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
; Original GDQuest 3d Third Person Controller Godot project:
; The MIT License
; Copyright (c) 2022 GDQuest
; https://github.com/gdquest-demos/godot-4-3d-third-person-controller
[gd_scene load_steps=7 format=3 uid="uid://dgr6e2hsbumgl"]
[sub_resource type="Shader" id="Shader_l14px"]
code = "shader_type sky;
uniform sampler2D clouds_sampler : filter_linear_mipmap;
uniform vec3 top_color : source_color = vec3(1.0);
uniform vec3 bottom_color : source_color = vec3(1.0);
const float sun_radius = 0.08;
uniform vec3 sun_scatter : source_color = vec3(1.0);
uniform float star_stength : hint_range(0.0, 5.0, 0.1) = 0.0;
// Voronoi method credit:
// The MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/ldl3Dl
vec3 hash( vec3 x ){
x = vec3( dot(x,vec3(127.1,311.7, 74.7)),
dot(x,vec3(269.5,183.3,246.1)),
dot(x,vec3(113.5,271.9,124.6)));
return fract(sin(x)*43758.5453123);
}
vec3 voronoi( in vec3 x ){
vec3 p = floor( x );
vec3 f = fract( x );
float id = 0.0;
vec2 res = vec2( 100.0 );
for( int k=-1; k<=1; k++ )
for( int j=-1; j<=1; j++ )
for( int i=-1; i<=1; i++ ) {
vec3 b = vec3( float(i), float(j), float(k) );
vec3 r = vec3( b ) - f + hash( p + b );
float d = dot( r, r );
if( d < res.x ) {
id = dot( p+b, vec3(1.0,57.0,113.0 ) );
res = vec2( d, res.x );
} else if( d < res.y ) {
res.y = d;
}
}
return vec3( sqrt( res ), abs(id) );
}
void sky() {
float clamped_light_y = clamp(LIGHT0_DIRECTION.y, 0.0, 1.0);
vec3 sky_gradient = mix(bottom_color.rgb, top_color.rgb, clamp(EYEDIR.y, 0.0, 1.0));
float sun_position = distance(EYEDIR.xyz, LIGHT0_DIRECTION);
float sun_mask_edge = smoothstep(sun_radius, sun_radius * 0.9, sun_position) * 0.2;
float sun_mask = smoothstep(sun_radius * 0.7, sun_radius * 0.65, sun_position) * 0.8;
float sun_color = (sun_mask_edge + sun_mask) * LIGHT0_ENERGY;
float horizon_mask = abs(EYEDIR.y * 1.0);
vec3 sunset_color = sun_scatter * (1.0 - horizon_mask);
COLOR = sky_gradient + sunset_color + (sun_color * clamp(EYEDIR.y * 4.0, 0.0, 1.0));
// Stars
if(star_stength > 0.0){
vec2 stars = voronoi(EYEDIR * 25.0).xz;
COLOR.rgb += smoothstep(0.025 + ((1.0 + sin(TIME + stars.y)) / 2.0) * 0.05, 0.0, stars.x) * star_stength;
}
// Clouds
vec2 cloud_uv = EYEDIR.xz / EYEDIR.y;
float cloud_mask = texture(clouds_sampler, cloud_uv * 0.05 + TIME * 0.001).x;
cloud_mask *= step(SKY_COORDS.y, 0.5);
COLOR.rgb = mix(
COLOR.rgb,
vec3(1.0),
smoothstep(0.75, 0.85, cloud_mask)
);
}
"
[sub_resource type="FastNoiseLite" id="FastNoiseLite_5d6vm"]
noise_type = 0
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_kwpsx"]
seamless = true
noise = SubResource("FastNoiseLite_5d6vm")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_17x6g"]
shader = SubResource("Shader_l14px")
shader_parameter/top_color = Color(0.164706, 0.541176, 0.823529, 1)
shader_parameter/bottom_color = Color(0.215686, 0.109804, 0.0196078, 1)
shader_parameter/sun_scatter = Color(0.529412, 0.8, 1, 1)
shader_parameter/star_stength = 0.0
shader_parameter/clouds_sampler = SubResource("NoiseTexture2D_kwpsx")
[sub_resource type="Sky" id="Sky_5jfho"]
sky_material = SubResource("ShaderMaterial_17x6g")
[sub_resource type="Environment" id="Environment_r0re1"]
background_mode = 2
background_color = Color(0.8, 0.913725, 1, 1)
sky = SubResource("Sky_5jfho")
ambient_light_source = 3
reflected_light_source = 2
tonemap_mode = 2
tonemap_exposure = 0.9
tonemap_white = 1.2
ssao_enabled = true
sdfgi_use_occlusion = true
glow_enabled = true
volumetric_fog_enabled = true
volumetric_fog_density = 0.005
volumetric_fog_emission = Color(1, 1, 1, 1)
[node name="WorldEnvironment" type="WorldEnvironment"]
environment = SubResource("Environment_r0re1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment