Ajout du shader de ciel/nuages.

This commit is contained in:
osquallo 2019-10-08 15:44:51 +02:00
parent a1e12e2b5b
commit a317139785
7 changed files with 281 additions and 25 deletions

View file

@ -15,13 +15,19 @@ export(float) var camera_smoothness = 0.5
export(float) var camera_speed = 1.0
export(float) var camera_accel = 10.0
var iTime=0.0
var iFrame=0
func _ready():
self._current_camera_speed = self.camera_speed
$settings.show()
func _process( delta ):
iTime+=delta
iFrame+=1
if Input.is_action_pressed("move_up"):
$dummy/camera_stand.translate( Vector3( 0.0, self._current_camera_speed*delta, 0.0 ) )
elif Input.is_action_pressed("move_down"):

View file

@ -1,27 +1,49 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=21 format=2]
[ext_resource path="res://previewer/previewer.gd" type="Script" id=1]
[ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=2]
[ext_resource path="res://textures/tilables/basic_texture_1024.png" type="Texture" id=3]
[ext_resource path="res://meshes/decors/rocks/cliff_001.tscn" type="PackedScene" id=4]
[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=5]
[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=6]
[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=7]
[ext_resource path="res://meshes/props/fountain_suzanha/Fountain_suzanha.tscn" type="PackedScene" id=8]
[ext_resource path="res://previewer/settings.tscn" type="PackedScene" id=9]
[ext_resource path="res://shaders/sky.shader" type="Shader" id=2]
[ext_resource path="res://textures/sky/sky_noise.png" type="Texture" id=3]
[ext_resource path="res://previewer/sky.gd" type="Script" id=4]
[ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=5]
[ext_resource path="res://textures/tilables/basic_texture_1024.png" type="Texture" id=6]
[ext_resource path="res://meshes/decors/rocks/cliff_001.tscn" type="PackedScene" id=7]
[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=8]
[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=9]
[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=10]
[ext_resource path="res://meshes/props/fountain_suzanha/Fountain_suzanha.tscn" type="PackedScene" id=11]
[ext_resource path="res://previewer/settings.tscn" type="PackedScene" id=12]
[sub_resource type="ProceduralSky" id=1]
[sub_resource type="ShaderMaterial" id=6]
shader = ExtResource( 2 )
shader_param/iTime = null
shader_param/iFrame = null
shader_param/COVERAGE = 0.5
shader_param/THICKNESS = 25.0
shader_param/ABSORPTION = 1.031
shader_param/STEPS = 25
shader_param/iChannel0 = ExtResource( 3 )
[sub_resource type="ImageTexture" id=7]
size = Vector2( 1280, 720 )
[sub_resource type="ViewportTexture" id=10]
viewport_path = NodePath("sky/viewport")
[sub_resource type="PanoramaSky" id=9]
resource_local_to_scene = true
panorama = SubResource( 10 )
[sub_resource type="Environment" id=2]
resource_local_to_scene = true
background_mode = 2
background_sky = SubResource( 1 )
background_sky = SubResource( 9 )
background_energy = 0.1
ambient_light_energy = 3.82
[sub_resource type="SpatialMaterial" id=3]
flags_unshaded = true
flags_world_triplanar = true
albedo_texture = ExtResource( 3 )
albedo_texture = ExtResource( 6 )
uv1_scale = Vector3( 122, 122, 122 )
[sub_resource type="PlaneMesh" id=4]
@ -40,10 +62,22 @@ propagation = 0.7
[node name="previewer" type="Spatial"]
script = ExtResource( 1 )
[node name="sky" type="Spatial" parent="."]
[node name="viewport" type="Viewport" parent="sky"]
size = Vector2( 1280, 720 )
render_target_update_mode = 3
[node name="sky" type="Sprite" parent="sky/viewport"]
material = SubResource( 6 )
texture = SubResource( 7 )
centered = false
script = ExtResource( 4 )
[node name="world_environment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )
[node name="dummy" parent="." instance=ExtResource( 2 )]
[node name="dummy" parent="." instance=ExtResource( 5 )]
[node name="terrain" type="Spatial" parent="."]
@ -51,39 +85,38 @@ environment = SubResource( 2 )
transform = Transform( 60.964, 0, 0, 0, 1.21928, 0, 0, 0, 60.964, 0, 0, 0 )
mesh = SubResource( 4 )
[node name="cliff" parent="terrain" instance=ExtResource( 4 )]
[node name="cliff" parent="terrain" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -48.2121 )
moss_height = 15.0
moss_fade = 2.5
[node name="props" type="Spatial" parent="."]
[node name="pendo_teddy" parent="props" instance=ExtResource( 5 )]
[node name="pendo_teddy" parent="props" instance=ExtResource( 8 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3 )
[node name="container" parent="props" instance=ExtResource( 6 )]
[node name="container" parent="props" instance=ExtResource( 9 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
color = Color( 0.145098, 0.0980392, 0.713726, 1 )
lid_angle = 45.0
[node name="container_2" parent="props" instance=ExtResource( 6 )]
[node name="container_2" parent="props" instance=ExtResource( 9 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.24144, 0, -5 )
color = Color( 0.491686, 0.159256, 0.832031, 1 )
lid_angle = 90.0
[node name="container_3" parent="props" instance=ExtResource( 6 )]
[node name="container_3" parent="props" instance=ExtResource( 9 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.6614, 0, -5 )
color = Color( 0.360784, 1, 0, 1 )
lid_angle = 12.0
[node name="container_4" parent="props" instance=ExtResource( 6 )]
[node name="container_4" parent="props" instance=ExtResource( 9 )]
transform = Transform( 0.457191, 0, 0.889369, 0, 1, 0, -0.889369, 0, 0.457191, -3.94754, 4.76837e-007, -4.27729 )
color = Color( 0.972549, 0.196078, 0.0431373, 1 )
lid_angle = 0.0
[node name="reference_box" parent="props" instance=ExtResource( 7 )]
[node name="reference_box" parent="props" instance=ExtResource( 10 )]
[node name="Fountain_suzanha" parent="props" instance=ExtResource( 8 )]
[node name="Fountain_suzanha" parent="props" instance=ExtResource( 11 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0.472, -5 )
[node name="light_system" type="Spatial" parent="."]
@ -98,7 +131,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 21.7307, 0 )
extents = Vector3( 63.192, 25, 76.323 )
data = SubResource( 5 )
[node name="settings" parent="." instance=ExtResource( 9 )]
[node name="settings" parent="." instance=ExtResource( 12 )]
margin_left = -475.0
margin_top = -243.0
margin_right = -219.0

View file

@ -14,4 +14,5 @@ func _ready():
func _on_color_picker_button_color_changed(color):
get_parent().get_node( "world_environment" ).environment.background_sky.sky_top_color = color
pass
# get_parent().get_node( "world_environment" ).environment.background_sky.sky_top_color = color

22
previewer/sky.gd Normal file
View file

@ -0,0 +1,22 @@
extends Sprite
onready var global_v=get_tree().get_root().get_node("previewer")
func _ready():
pass
func _process(delta):
self.material.set("shader_param/iTime",global_v.iTime)
self.material.set("shader_param/iFrame",global_v.iFrame)
func cov_scb(value):
self.material.set("shader_param/COVERAGE",float(value)/100)
func absb_scb(value):
self.material.set("shader_param/ABSORPTION",float(value)/10)
func thick_scb(value):
self.material.set("shader_param/THICKNESS",value)
func step_scb(value):
self.material.set("shader_param/STEPS",value)

194
shaders/sky.shader Normal file
View file

@ -0,0 +1,194 @@
shader_type canvas_item;
// USING https://www.shadertoy.com/view/XtBXDw (base on it)
uniform float iTime;
uniform int iFrame;
uniform sampler2D iChannel0;
uniform float COVERAGE :hint_range(0,1); //0.5
uniform float THICKNESS :hint_range(0,100); //25.
uniform float ABSORPTION :hint_range(0,10); //1.030725
uniform int STEPS :hint_range(0,100); //25
float noise( in vec3 x )
{
x*=0.01;
float z = x.z*256.0;
vec2 offz = vec2(0.317,0.123);
vec2 uv1 = x.xy + offz*floor(z);
vec2 uv2 = uv1 + offz;
return mix(textureLod( iChannel0, uv1 ,0.0).x,textureLod( iChannel0, uv2 ,0.0).x,fract(z));
}
float fbm(vec3 pos,float lacunarity){
vec3 p = pos;
float
t = 0.51749673 * noise(p); p *= lacunarity;
t += 0.25584929 * noise(p); p *= lacunarity;
t += 0.12527603 * noise(p); p *= lacunarity;
t += 0.06255931 * noise(p);
return t;
}
float get_noise(vec3 x)
{
float FBM_FREQ=2.76434;
return fbm(x, FBM_FREQ);
}
vec3 render_sky_color(vec3 rd){
vec3 sun_color = vec3(1., .7, .55);
vec3 SUN_DIR = normalize(vec3(0, abs(sin( .3)), -1));
float sun_amount = max(dot(rd, SUN_DIR), 0.0);
vec3 sky = mix(vec3(.0, .1, .4), vec3(.3, .6, .8), 1.0 - rd.y);
sky = sky + sun_color * min(pow(sun_amount, 1500.0) * 5.0, 1.0);
sky = sky + sun_color * min(pow(sun_amount, 10.0) * .6, 1.0);
return sky;
}
bool SphereIntersect(vec3 SpPos, float SpRad, vec3 ro, vec3 rd, out float t, out vec3 norm) {
ro -= SpPos;
float A = dot(rd, rd);
float B = 2.0*dot(ro, rd);
float C = dot(ro, ro)-SpRad*SpRad;
float D = B*B-4.0*A*C;
if (D < 0.0) return false;
D = sqrt(D);
A *= 2.0;
float t1 = (-B+D)/A;
float t2 = (-B-D)/A;
if (t1 < 0.0) t1 = t2;
if (t2 < 0.0) t2 = t1;
t1 = min(t1, t2);
if (t1 < 0.0) return false;
norm = ro+t1*rd;
t = t1;
//norm = normalize(norm);
return true;
}
float density(vec3 pos,vec3 offset,float t){
vec3 p = pos * .0212242 + offset;
float dens = get_noise(p);
float cov = 1. - COVERAGE;
dens *= smoothstep (cov, cov + .05, dens);
return clamp(dens, 0., 1.);
}
vec4 render_clouds(vec3 ro,vec3 rd){
vec3 apos=vec3(0, -450, 0);
float arad=500.;
vec3 WIND=vec3(0, 0, -iTime * .2);
vec3 C = vec3(0, 0, 0);
float alpha = 0.;
vec3 n;
float tt;
if(SphereIntersect(apos,arad,ro,rd,tt,n)){
float thickness = THICKNESS;
int steps = STEPS;
float march_step = thickness / float(steps);
vec3 dir_step = rd / rd.y * march_step;
vec3 pos =n;
float T = 1.;
for (int i = 0; i < steps; i++) {
float h = float(i) / float(steps);
float dens = density (pos, WIND, h);
float T_i = exp(-ABSORPTION * dens * march_step);
T *= T_i;
if (T < .01) break;
C += T * (exp(h) / 1.75) *dens * march_step;
alpha += (1. - T_i) * (1. - alpha);
pos += dir_step;
if (length(pos) > 1e3) break;
}
return vec4(C, alpha);
}
return vec4(C, alpha);
}
float fbm2(in vec3 p)
{
float f = 0.;
f += .50000 * noise(.5 * (p+vec3(0.,0.,-iTime*0.275)));
f += .25000 * noise(1. * (p+vec3(0.,0.,-iTime*0.275)));
f += .12500 * noise(2. * (p+vec3(0.,0.,-iTime*0.275)));
f += .06250 * noise(4. * (p+vec3(0.,0.,-iTime*0.275)));
return f;
}
vec3 cube_bot(vec3 d, vec3 c1, vec3 c2)
{
return fbm2(d) * mix(c1, c2, d * .5 + .5);
}
vec3 rotate_y(vec3 v, float angle)
{
float ca = cos(angle); float sa = sin(angle);
return v*mat3(
vec3(+ca, +.0, -sa),
vec3(+.0,+1.0, +.0),
vec3(+sa, +.0, +ca));
}
vec3 rotate_x(vec3 v, float angle)
{
float ca = cos(angle); float sa = sin(angle);
return v*mat3(
vec3(+1.0, +.0, +.0),
vec3(+.0, +ca, -sa),
vec3(+.0, +sa, +ca));
}
void panorama_uv(vec2 fragCoord, out vec3 ro,out vec3 rd, in vec2 iResolution){
float M_PI = 3.1415926535;
float ymul = 2.0; float ydiff = -1.0;
vec2 uv = fragCoord.xy / iResolution.xy;
uv.x = 2.0 * uv.x - 1.0;
uv.y = ymul * uv.y + ydiff;
ro = vec3(0., 5., 0.);
rd = normalize(rotate_y(rotate_x(vec3(0.0, 0.0, 1.0),-uv.y*M_PI/2.0),-uv.x*M_PI));
}
void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution)
{
vec3 ro = vec3 (0.,0.,0.);
vec3 rd = vec3(0.);
vec3 col=vec3(0.);
panorama_uv(fragCoord,ro,rd,iResolution);
vec3 sky = render_sky_color(rd);
vec4 cld = vec4(0.);
float skyPow = dot(rd, vec3(0.0, -1.0, 0.0));
float horizonPow =1.-pow(1.0-abs(skyPow), 5.0);
if(rd.y>0.)
{cld=render_clouds(ro,rd);
cld=clamp(cld,vec4(0.),vec4(1.));
cld.rgb+=0.04*cld.rgb*horizonPow;
cld*=clamp(( 1.0 - exp(-2.3 * pow(max((0.0), horizonPow), (2.6)))),0.,1.);
}
else{
cld.rgb = cube_bot(rd,vec3(1.5,1.49,1.71), vec3(1.1,1.15,1.5));
cld*=cld;
//cld=clamp(cld,vec4(0.),vec4(1.));
cld.a=1.;
cld*=clamp(( 1.0 - exp(-1.3 * pow(max((0.0), horizonPow), (2.6)))),0.,1.);
}
col=mix(sky, cld.rgb/(0.0001+cld.a), cld.a);
//col*=col;
fragColor = vec4(col,1.0);
}
void fragment(){
vec2 iResolution=1./TEXTURE_PIXEL_SIZE;
mainImage(COLOR,UV*iResolution,iResolution);
}

BIN
textures/sky/sky_noise.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB