summaryrefslogtreecommitdiff
path: root/godot/scenes/environment/Water.tscn
blob: 04410b1de75e327245a392cfa7f5eb8900b1adf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
[gd_scene load_steps=7 format=2]

[ext_resource path="res://textures/WaterC.jpg" type="Texture" id=1]
[ext_resource path="res://textures/WaterA.jpg" type="Texture" id=2]

[sub_resource type="QuadMesh" id=1]
size = Vector2( 2, 2 )

[sub_resource type="Shader" id=2]
code = "shader_type spatial;
render_mode world_vertex_coords, cull_disabled;

uniform int ShaderID = 4;

uniform vec4 Color : hint_color;
uniform vec4 BackgroundColor : hint_color;
uniform sampler2D Texture : hint_albedo;
uniform sampler2D BackgroundTexture : hint_albedo;
varying vec3 TriplanarPosistion;
varying vec3 PowerNormal;
uniform vec3 UVScale = vec3(1);
uniform vec3 UVOffset;
uniform float Transparent = 1.0;
uniform float Power = 0.0;
uniform vec4 EmissionColor : hint_color;

void vertex()
{
	vec2 Pos = vec2(0);
	Pos.x += TIME * 0.05;
	TANGENT = vec3(0.0, 0.0, -1.0) * abs(NORMAL.x);
	TANGENT += vec3(1.0, 0.0, 0.0) * abs(NORMAL.y);
	TANGENT += vec3(1.0, 0.0, 0.0) * abs(NORMAL.z);
	TANGENT = normalize(TANGENT);
	BINORMAL = vec3(0.0, -1.0, 0.0) * abs(NORMAL.x);
	BINORMAL += vec3(0.0, 0.0, 1.0) * abs(NORMAL.y);
	BINORMAL += vec3(0.0, -1.0, 0.0) * abs(NORMAL.z);
	BINORMAL = normalize(BINORMAL);
	PowerNormal = pow(abs(NORMAL), vec3(1.0));
	PowerNormal /= dot(PowerNormal, vec3(1.0));
	TriplanarPosistion = VERTEX * UVScale + UVOffset;// + vec3(Pos.x, Pos.y, 0);
	TriplanarPosistion *= vec3(1.0, -1.0, 1.0);
}


vec4 TriplanarTexture(sampler2D TSampler,vec3 TWeights,vec3 TTriplanarPosition)
{
	vec4 Sampler = vec4(0.0);
	Sampler += texture(TSampler, TTriplanarPosition.xy) * TWeights.z;
	Sampler += texture(TSampler, TTriplanarPosition.xz) * TWeights.y;
	Sampler += texture(TSampler, TTriplanarPosition.zy * vec2(-1.0, 1.0)) * TWeights.x;
	return Sampler;
}



void fragment()
{
	vec3 NewOffset = vec3(0);
	NewOffset.x = cos(TIME + TriplanarPosistion.x * 2.0) * 0.05;
	NewOffset.z = cos(TIME + TriplanarPosistion.z) * 0.05;
	
	ALBEDO = TriplanarTexture(BackgroundTexture, PowerNormal, TriplanarPosistion + NewOffset).rgb * BackgroundColor.rgb;
	ALBEDO += TriplanarTexture(Texture, PowerNormal, TriplanarPosistion + NewOffset * 5.1).rgb * Color.rgb;
	EMISSION = ALBEDO * Power;
	
	float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r;
	depth = depth*2.0 - 1.0;
	depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]);
	depth = depth + VERTEX.z;
	depth = exp(-depth*0.05);
	//depth *= 0.01;
	ALPHA = clamp(1.0-depth, Transparent, 1.0);
}




"

[sub_resource type="ShaderMaterial" id=3]
render_priority = -100
shader = SubResource( 2 )
shader_param/ShaderID = 4
shader_param/Color = Color( 0.270588, 0.372549, 0.423529, 0.490196 )
shader_param/BackgroundColor = Color( 0.560784, 0.560784, 0.560784, 1 )
shader_param/UVScale = Vector3( 0.05, 0.05, 0.05 )
shader_param/UVOffset = null
shader_param/Transparent = 0.4
shader_param/Power = 0.2
shader_param/EmissionColor = null
shader_param/Texture = ExtResource( 2 )
shader_param/BackgroundTexture = ExtResource( 1 )

[sub_resource type="BoxShape" id=4]

[node name="Water" type="Spatial"]

[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0 )
mesh = SubResource( 1 )
material/0 = SubResource( 3 )

[node name="WaterArea" type="Area" parent="."]
collision_layer = 4

[node name="CollisionShape" type="CollisionShape" parent="WaterArea"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 4 )