-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tscn
301 lines (237 loc) · 9.43 KB
/
main.tscn
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
[gd_scene load_steps=19 format=2]
[ext_resource path="res://look_and_fly.gd" type="Script" id=1]
[ext_resource path="res://particles.gdshader" type="Shader" id=2]
[ext_resource path="res://default_env.tres" type="Environment" id=3]
[ext_resource path="res://particle.tres" type="Material" id=4]
[ext_resource path="res://smooth_follow.gd" type="Script" id=5]
[ext_resource path="res://resize_viewport.gd" type="Script" id=6]
[sub_resource type="ViewportTexture" id=25]
viewport_path = NodePath("Viewport")
[sub_resource type="ShaderMaterial" id=19]
resource_local_to_scene = true
render_priority = 2
shader = ExtResource( 2 )
shader_param/spray = 0.4
shader_param/bounciness = 0.5
shader_param/friction = 0.0
shader_param/start_velocity = null
shader_param/my_screen_pixel_size = null
shader_param/my_camera = null
shader_param/my_scuffed_projection = null
shader_param/tex = SubResource( 25 )
[sub_resource type="CubeMesh" id=24]
material = ExtResource( 4 )
size = Vector3( 0.005, 0.005, 0.005 )
[sub_resource type="GDScript" id=17]
script/source = "extends Particles
onready var last_pos = global_translation
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(dt):
#process_material.set_shader_param(\"tex\",get_viewport().get_texture())
process_material.set_shader_param(\"my_screen_pixel_size\",Vector2(1,1)/get_viewport().size)
var camera = get_viewport().get_camera()
process_material.set_shader_param(\"my_camera\",camera.get_camera_transform())
var aspect = get_viewport().size.x/get_viewport().size.y
process_material.set_shader_param(
\"my_scuffed_projection\",
ProjectionMatrix.createProjectionMatrix(camera.fov,aspect,camera.near,camera.far))
var velocity = (global_translation - last_pos)/dt
emitting = false
if Input.is_mouse_button_pressed(BUTTON_LEFT):
emitting = true
#velocity += -global_transform.basis[2]*4.0
process_material.set_shader_param(\"start_velocity\",velocity)
last_pos = global_translation
"
[sub_resource type="SpatialMaterial" id=23]
albedo_color = Color( 0.168627, 0.168627, 0.168627, 1 )
[sub_resource type="Shader" id=15]
code = "shader_type spatial;
render_mode unshaded;//depth_test_disable;
vec3 getWorldPos(vec2 screen, float depth, mat4 clipToView, mat4 viewToWorld){
vec3 ndc = vec3(screen, depth) * 2.0 - 1.0;
/*vec4 view = clipToView * vec4(ndc, 1.0);
view.xyz /= view.w;
float linear_depth = -view.z;*/
vec4 world = viewToWorld * clipToView * vec4(ndc, 1.0);
vec3 world_position = world.xyz / world.w;
return world_position;
}
void fragment(){
ALBEDO = vec3(.01);
//float depth = texture(DEPTH_TEXTURE,SCREEN_UV).x;
//ALBEDO = getWorldPos(SCREEN_UV,depth,inverse(PROJECTION_MATRIX),CAMERA_MATRIX);
}"
[sub_resource type="ShaderMaterial" id=16]
render_priority = -1
shader = SubResource( 15 )
[sub_resource type="Shader" id=8]
code = "shader_type spatial;
render_mode unshaded,depth_test_disable,blend_mul;
void fragment(){
ALBEDO = vec3(1);
ALPHA = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.).x;
}"
[sub_resource type="ShaderMaterial" id=1]
render_priority = 1
shader = SubResource( 8 )
[sub_resource type="Shader" id=6]
code = "shader_type canvas_item;
// colour space conversions taken from godot source code
// This expects 0-1 range input.
vec3 linear_to_srgb(vec3 color) {
//color = clamp(color, vec3(0.0), vec3(1.0));
//const vec3 a = vec3(0.055f);
//return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
// Approximation from http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
return max(vec3(1.055) * pow(color, vec3(0.416666667)) - vec3(0.055), vec3(0.0));
}
// This expects 0-1 range input, outside that range it behaves poorly.
vec3 srgb_to_linear(vec3 color) {
// Approximation from http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
return color * (color * (color * 0.305306011 + 0.682171111) + 0.012522878);
}
vec2 getUV(vec3 pos,mat4 viewToClip, mat4 worldToView){
vec4 p = viewToClip*worldToView*vec4(pos,1);
p.xyz /= p.w;
return p.xy*.5+.5;
}
vec3 getWorldPos(vec2 screen, float depth, mat4 clipToView, mat4 viewToWorld){
vec3 ndc = vec3(screen, depth) * 2.0 - 1.0;
/*vec4 view = clipToView * vec4(ndc, 1.0);
view.xyz /= view.w;
float linear_depth = -view.z;*/
vec4 world = viewToWorld * clipToView * vec4(ndc, 1.0);
vec3 world_position = world.xyz / world.w;
return world_position;
}
void fragment(){
vec4 T = textureLod(TEXTURE,UV,0.);
vec3 col = T.xyz;
float depth = T.w;
COLOR.xyz = linear_to_srgb(col.xyz); // approximately pow(T.xyz,vec3(1)/2.2)
/* // debugging
if(SCREEN_UV.y<.4){
COLOR.xyz = vec3(depth);
if(SCREEN_UV.x<.5){
mat4 aPROJECTION_MATRIX = mat4(1);
aPROJECTION_MATRIX[0][0] = scuffed_PROJECTION_MATRIX[0];
aPROJECTION_MATRIX[1][1] = scuffed_PROJECTION_MATRIX[1];
aPROJECTION_MATRIX[2][2] = scuffed_PROJECTION_MATRIX[2];
aPROJECTION_MATRIX[2][3] = -1.;
aPROJECTION_MATRIX[3][2] = scuffed_PROJECTION_MATRIX[3];
aPROJECTION_MATRIX[3][3] = 0.;
vec3 world_pos = getWorldPos(UV,depth,inverse(aPROJECTION_MATRIX),aCAMERA_MATRIX);
vec3 n = normalize( cross(dFdx(world_pos),dFdy(world_pos)) );
vec2 uv = getUV(world_pos,aPROJECTION_MATRIX,inverse(aCAMERA_MATRIX));
//COLOR.xyz = vec3(uv,0);
COLOR.xyz = n*.5+.5;
}
}*/
}"
[sub_resource type="ShaderMaterial" id=7]
shader = SubResource( 6 )
[sub_resource type="ViewportTexture" id=5]
viewport_path = NodePath("Viewport")
[node name="main" type="Spatial"]
[node name="Viewport" type="Viewport" parent="."]
size = Vector2( 1280, 720 )
transparent_bg = true
handle_input_locally = false
use_32_bpc_depth = true
keep_3d_linear = true
script = ExtResource( 6 )
[node name="Camera" type="Camera" parent="Viewport"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.116796, 0.91955 )
environment = ExtResource( 3 )
current = true
fov = 90.0
[node name="Particles" type="Particles" parent="Viewport/Camera"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0342143, -0.288255 )
emitting = false
amount = 65536
lifetime = 2.5
local_coords = false
process_material = SubResource( 19 )
draw_pass_1 = SubResource( 24 )
script = SubResource( 17 )
[node name="OmniLight" type="OmniLight" parent="Viewport"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.246725, -0.938569 )
[node name="CSGCombiner" type="CSGCombiner" parent="Viewport"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.371041, 0.220035, -0.274035 )
material_override = SubResource( 23 )
[node name="CSGBox" type="CSGBox" parent="Viewport/CSGCombiner"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.371041, -0.598761, 0.274035 )
height = 0.230547
[node name="CSGBox2" type="CSGBox" parent="Viewport/CSGCombiner"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.768323, 0.458627, 0.713085 )
width = 0.344364
height = 1.96502
depth = 0.579155
[node name="CSGBox3" type="CSGBox" parent="Viewport/CSGCombiner"]
width = 0.344364
height = 1.00463
depth = 0.579155
[node name="CSGTorus" type="CSGTorus" parent="Viewport/CSGCombiner"]
inner_radius = 0.357103
outer_radius = 0.601696
sides = 32
ring_sides = 16
[node name="CSGBox4" type="CSGBox" parent="Viewport/CSGCombiner"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.371041, -0.282762, 0.274035 )
operation = 2
width = 0.709821
height = 0.644568
depth = 0.935899
[node name="CSGTorus2" type="CSGTorus" parent="Viewport/CSGCombiner"]
transform = Transform( 0.400059, 0.0664517, 0, -0.0664517, 0.400059, 0, 0, 0, 0.40554, -0.0712516, -0.348644, 0.563301 )
operation = 2
inner_radius = 1.06863
outer_radius = 2.0468
sides = 16
ring_sides = 24
[node name="CSGTorus3" type="CSGTorus" parent="Viewport/CSGCombiner"]
transform = Transform( 0.397948, 0.0762852, 0.0167749, -0.0774975, 0.396491, 0.0353819, -0.00974504, -0.0379251, 0.403645, -0.0377086, -0.467865, 0.604132 )
operation = 2
inner_radius = 0.605324
outer_radius = 1.04092
sides = 16
ring_sides = 24
[node name="CSGSphere" type="CSGSphere" parent="Viewport/CSGCombiner"]
transform = Transform( 0.0544854, 0, 0, 0, 0.0544854, 0, 0, 0, 0.0544854, -0.574512, -0.29421, 0.0782153 )
radial_segments = 24
rings = 12
[node name="CSGSphere2" type="CSGSphere" parent="Viewport/CSGCombiner"]
transform = Transform( 0.0408215, 0, 0, 0, 0.0408215, 0, 0, 0, 0.0408215, -0.484836, -0.383124, 0.0798078 )
radial_segments = 24
rings = 12
[node name="CSGSphere3" type="CSGSphere" parent="Viewport/CSGCombiner"]
transform = Transform( 0.0408215, 0, 0, 0, 0.0408215, 0, 0, 0, 0.0408215, -0.695278, -0.43328, 0.114599 )
radial_segments = 24
rings = 12
[node name="sky" type="CSGBox" parent="Viewport"]
transform = Transform( 20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0 )
invert_faces = true
material = SubResource( 16 )
[node name="write_alpha" type="CSGBox" parent="Viewport"]
transform = Transform( 20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0 )
invert_faces = true
material = SubResource( 1 )
[node name="fly" type="Spatial" parent="."]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.116796, 0.91955 )
script = ExtResource( 1 )
speed = 0.02
look_sensitivity = 0.3
[node name="camera_pos" type="RemoteTransform" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.116796, 0.91955 )
remote_path = NodePath("../Viewport/Camera")
script = ExtResource( 5 )
target_path = NodePath("../fly")
weight = 0.25
[node name="TextureRect" type="TextureRect" parent="."]
material = SubResource( 7 )
anchor_right = 1.0
anchor_bottom = 1.0
texture = SubResource( 5 )
flip_v = true