volumetric_fog.tscn 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. [gd_scene load_steps=26 format=3 uid="uid://d1d6jy84lcpg7"]
  2. [ext_resource type="Script" path="res://camera.gd" id="1_mfjvp"]
  3. [ext_resource type="CompressedTexture3D" uid="uid://bpvy0e34otmhk" path="res://icon_outlined.png" id="2_8fjmj"]
  4. [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_fefkn"]
  5. sky_top_color = Color(0.568627, 0.698039, 0.807843, 1)
  6. sky_horizon_color = Color(0.672549, 0.704902, 0.734314, 1)
  7. ground_bottom_color = Color(0.121569, 0.121569, 0.129412, 1)
  8. ground_horizon_color = Color(0.672549, 0.704902, 0.734314, 1)
  9. [sub_resource type="Sky" id="Sky_5gwha"]
  10. sky_material = SubResource("ProceduralSkyMaterial_fefkn")
  11. [sub_resource type="Environment" id="Environment_gsgar"]
  12. background_mode = 2
  13. sky = SubResource("Sky_5gwha")
  14. tonemap_mode = 2
  15. glow_enabled = true
  16. volumetric_fog_enabled = true
  17. [sub_resource type="Gradient" id="Gradient_cqs75"]
  18. offsets = PackedFloat32Array(0, 0.313433, 1)
  19. colors = PackedColorArray(0, 0, 0, 1, 0.473976, 0.473976, 0.473976, 1, 1, 1, 1, 1)
  20. [sub_resource type="FastNoiseLite" id="FastNoiseLite_cjmew"]
  21. frequency = 0.005
  22. fractal_type = 2
  23. fractal_octaves = 4
  24. fractal_lacunarity = 3.0
  25. fractal_gain = 2.0
  26. fractal_weighted_strength = 0.4
  27. domain_warp_enabled = true
  28. [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_6pkhb"]
  29. seamless = true
  30. as_normal_map = true
  31. bump_strength = 0.5
  32. color_ramp = SubResource("Gradient_cqs75")
  33. noise = SubResource("FastNoiseLite_cjmew")
  34. [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_8w53i"]
  35. seamless = true
  36. color_ramp = SubResource("Gradient_cqs75")
  37. noise = SubResource("FastNoiseLite_cjmew")
  38. [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qrpkj"]
  39. albedo_color = Color(0, 0, 0, 1)
  40. roughness_texture = SubResource("NoiseTexture2D_8w53i")
  41. normal_enabled = true
  42. normal_texture = SubResource("NoiseTexture2D_6pkhb")
  43. uv1_scale = Vector3(0.25, 0.25, 0.25)
  44. uv1_triplanar = true
  45. texture_filter = 5
  46. [sub_resource type="FogMaterial" id="FogMaterial_sfd8y"]
  47. density = -1.6842
  48. [sub_resource type="FogMaterial" id="FogMaterial_v1f5u"]
  49. density = 0.2
  50. emission = Color(0, 1, 0.501961, 1)
  51. edge_fade = 2.2779e-05
  52. [sub_resource type="FogMaterial" id="FogMaterial_16tep"]
  53. density = 0.2
  54. emission = Color(0.980392, 0.164706, 1, 1)
  55. edge_fade = 2.2779e-05
  56. [sub_resource type="FogMaterial" id="FogMaterial_blauf"]
  57. density = 0.2
  58. emission = Color(0, 1, 0.501961, 1)
  59. height_falloff = 1e+06
  60. edge_fade = 2.2779e-05
  61. [sub_resource type="FogMaterial" id="FogMaterial_yvnd5"]
  62. density = 0.3
  63. emission = Color(1, 0.290196, 0.419608, 1)
  64. [sub_resource type="FogMaterial" id="FogMaterial_gcgmm"]
  65. density = 0.3
  66. emission = Color(1, 0.290196, 0.419608, 1)
  67. height_falloff = 1e+06
  68. [sub_resource type="FogMaterial" id="FogMaterial_8xcc6"]
  69. density = 0.1
  70. albedo = Color(1, 15, 10, 1)
  71. [sub_resource type="Animation" id="Animation_jg7qq"]
  72. length = 0.001
  73. tracks/0/type = "value"
  74. tracks/0/imported = false
  75. tracks/0/enabled = true
  76. tracks/0/path = NodePath("MovingBox:position")
  77. tracks/0/interp = 1
  78. tracks/0/loop_wrap = true
  79. tracks/0/keys = {
  80. "times": PackedFloat32Array(0),
  81. "transitions": PackedFloat32Array(1),
  82. "update": 0,
  83. "values": [Vector3(0, 2, 10)]
  84. }
  85. tracks/1/type = "value"
  86. tracks/1/imported = false
  87. tracks/1/enabled = true
  88. tracks/1/path = NodePath("MovingBox:rotation")
  89. tracks/1/interp = 1
  90. tracks/1/loop_wrap = true
  91. tracks/1/keys = {
  92. "times": PackedFloat32Array(0),
  93. "transitions": PackedFloat32Array(1),
  94. "update": 0,
  95. "values": [Vector3(0, 0, 0)]
  96. }
  97. tracks/2/type = "value"
  98. tracks/2/imported = false
  99. tracks/2/enabled = true
  100. tracks/2/path = NodePath("MovingBox:scale")
  101. tracks/2/interp = 1
  102. tracks/2/loop_wrap = true
  103. tracks/2/keys = {
  104. "times": PackedFloat32Array(0),
  105. "transitions": PackedFloat32Array(1),
  106. "update": 0,
  107. "values": [Vector3(1, 1, 1)]
  108. }
  109. [sub_resource type="Animation" id="Animation_axnf8"]
  110. resource_name = "move_fog_volume"
  111. length = 10.0
  112. loop_mode = 1
  113. tracks/0/type = "value"
  114. tracks/0/imported = false
  115. tracks/0/enabled = true
  116. tracks/0/path = NodePath("MovingBox:position")
  117. tracks/0/interp = 1
  118. tracks/0/loop_wrap = true
  119. tracks/0/keys = {
  120. "times": PackedFloat32Array(0, 3, 6),
  121. "transitions": PackedFloat32Array(-2, -2, -2),
  122. "update": 0,
  123. "values": [Vector3(0, 2, 10), Vector3(-5.20189, 2, 12.7464), Vector3(-0.764091, 6.11944, 20.2665)]
  124. }
  125. tracks/1/type = "value"
  126. tracks/1/imported = false
  127. tracks/1/enabled = true
  128. tracks/1/path = NodePath("MovingBox:rotation")
  129. tracks/1/interp = 1
  130. tracks/1/loop_wrap = true
  131. tracks/1/keys = {
  132. "times": PackedFloat32Array(0, 3, 6),
  133. "transitions": PackedFloat32Array(-2, -2, -2),
  134. "update": 0,
  135. "values": [Vector3(0, 0, 0), Vector3(0, 0.784368, 0), Vector3(-0.33128, 0.307663, 0.797063)]
  136. }
  137. tracks/2/type = "value"
  138. tracks/2/imported = false
  139. tracks/2/enabled = true
  140. tracks/2/path = NodePath("MovingBox:scale")
  141. tracks/2/interp = 1
  142. tracks/2/loop_wrap = true
  143. tracks/2/keys = {
  144. "times": PackedFloat32Array(0, 3, 6),
  145. "transitions": PackedFloat32Array(-2, -2, -2),
  146. "update": 0,
  147. "values": [Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(3, 3, 3)]
  148. }
  149. [sub_resource type="AnimationLibrary" id="AnimationLibrary_avffy"]
  150. _data = {
  151. "RESET": SubResource("Animation_jg7qq"),
  152. "move_fog_volume": SubResource("Animation_axnf8")
  153. }
  154. [sub_resource type="BoxMesh" id="BoxMesh_fi43t"]
  155. [sub_resource type="FogMaterial" id="FogMaterial_ktn3i"]
  156. albedo = Color(0, 0, 4, 1)
  157. edge_fade = 0.0
  158. [sub_resource type="FogMaterial" id="FogMaterial_yomn8"]
  159. density = 2.0
  160. emission = Color(0, 0.501961, 1, 1)
  161. edge_fade = 0.0
  162. density_texture = ExtResource("2_8fjmj")
  163. [sub_resource type="Shader" id="Shader_1xpcs"]
  164. code = "shader_type fog;
  165. /* main fog shader */
  166. uniform float base_density: hint_range(0, 1) = 0.8;
  167. uniform vec3 base_color: source_color;
  168. uniform float fade_out_height = 2.0;
  169. uniform float fade_out_distance = 1.5;
  170. uniform vec3 noise_amounts = vec3(0.4, 0.35, 0.25); // should add up to 1
  171. uniform vec3 noise_scales = vec3(1.0, 2.0, 4.0);
  172. uniform vec3 noise_velocity1 = vec3(0.5, 0.0, 0.0);
  173. uniform vec3 noise_velocity2 = vec3(1, 0.0, -1);
  174. uniform vec3 noise_velocity3 = vec3(0.0, 0.6, 0.3);
  175. /* gradient_noise_3d.gdshaderinc */
  176. // The MIT License
  177. // Copyright © 2013 Inigo Quilez
  178. // 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, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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.
  179. // All noise functions here:
  180. //
  181. // https://www.shadertoy.com/playlist/fXlXzf&from=0&num=12
  182. vec3 hash(vec3 p) {
  183. p = vec3(dot(p,vec3(127.1,311.7, 74.7)),
  184. dot(p,vec3(269.5,183.3,246.1)),
  185. dot(p,vec3(113.5,271.9,124.6)));
  186. return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
  187. }
  188. // 3D gradient noise function
  189. float noise(vec3 p) {
  190. vec3 i = floor(p);
  191. vec3 f = fract(p);
  192. vec3 u = f*f*(3.0-2.0*f);
  193. return mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ),
  194. dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),
  195. mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ),
  196. dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),
  197. mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ),
  198. dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),
  199. mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ),
  200. dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z );
  201. }
  202. void fog() {
  203. vec3 base_pos = WORLD_POSITION * vec3(0.1, 0.5, 0.1);
  204. DENSITY = base_density;
  205. float noise1 = noise(base_pos * noise_scales.x + TIME * noise_velocity1) * noise_amounts.x;
  206. float noise2 = noise(base_pos * noise_scales.y + TIME * noise_velocity2) * noise_amounts.y;
  207. float noise3 = noise(base_pos * noise_scales.z + TIME * noise_velocity3) * noise_amounts.z;
  208. DENSITY *= smoothstep(-0.1, 0.0, noise1 + noise2 + noise3);
  209. DENSITY *= 1.0 - smoothstep(fade_out_height, fade_out_height + fade_out_distance, WORLD_POSITION.y);
  210. ALBEDO = base_color;
  211. }"
  212. [sub_resource type="ShaderMaterial" id="ShaderMaterial_481nw"]
  213. shader = SubResource("Shader_1xpcs")
  214. shader_parameter/base_density = 1.0
  215. shader_parameter/base_color = Color(1, 0, 0, 1)
  216. shader_parameter/fade_out_height = 0.0
  217. shader_parameter/fade_out_distance = 8.0
  218. shader_parameter/noise_amounts = Vector3(0.4, 0.35, 0.25)
  219. shader_parameter/noise_scales = Vector3(1, 2, 4)
  220. shader_parameter/noise_velocity1 = Vector3(0.5, 0, 0)
  221. shader_parameter/noise_velocity2 = Vector3(1, 0, -1)
  222. shader_parameter/noise_velocity3 = Vector3(0, 0.6, 0.3)
  223. [node name="Node3D" type="Node3D"]
  224. [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
  225. environment = SubResource("Environment_gsgar")
  226. [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
  227. transform = Transform3D(-0.592126, -0.697883, 0.402923, -1.19487e-09, 0.5, 0.866026, -0.805846, 0.512796, -0.296063, 0, 0, 0)
  228. shadow_enabled = true
  229. shadow_bias = 0.04
  230. shadow_blur = 1.5
  231. directional_shadow_max_distance = 60.0
  232. [node name="Camera3D" type="Camera3D" parent="."]
  233. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8, 6, 18)
  234. fov = 74.0
  235. script = ExtResource("1_mfjvp")
  236. [node name="Label" type="Label" parent="Camera3D"]
  237. offset_left = 16.0
  238. offset_top = 16.0
  239. offset_right = 812.0
  240. offset_bottom = 299.0
  241. theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
  242. theme_override_constants/outline_size = 4
  243. text = "Fog density: 0.05
  244. Temporal reprojection: Disabled
  245. Volumetric fog quality: 64×64×64"
  246. [node name="HelpLabel" type="Label" parent="Camera3D"]
  247. anchors_preset = 2
  248. anchor_top = 1.0
  249. anchor_bottom = 1.0
  250. offset_left = 16.0
  251. offset_top = -120.0
  252. offset_right = 909.0
  253. offset_bottom = -16.0
  254. grow_vertical = 0
  255. theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
  256. theme_override_constants/outline_size = 4
  257. text = "W/A/S/D/Mouse: Move
  258. Left/Right arrows: Adjust global fog density
  259. Space: Toggle temporal reprojection
  260. Up/Down arrows or mouse wheel: Adjust temporal reprojection intensity
  261. Page Up/Down: Adjust volumetric fog quality"
  262. [node name="Ground" type="CSGBox3D" parent="."]
  263. size = Vector3(1024, 1.99, 1024)
  264. material = SubResource("StandardMaterial3D_qrpkj")
  265. [node name="Ground2" type="CSGBox3D" parent="Ground"]
  266. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.282, 0, 5.62229)
  267. operation = 2
  268. size = Vector3(3, 2, 4)
  269. material = SubResource("StandardMaterial3D_qrpkj")
  270. [node name="Ground3" type="CSGBox3D" parent="Ground"]
  271. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.87312, 0, 2.69763)
  272. operation = 2
  273. size = Vector3(3, 2, 4)
  274. material = SubResource("StandardMaterial3D_qrpkj")
  275. [node name="CSGBox3D" type="CSGBox3D" parent="."]
  276. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0)
  277. size = Vector3(8, 8, 8)
  278. material = SubResource("StandardMaterial3D_qrpkj")
  279. [node name="CSGBox3D" type="CSGBox3D" parent="CSGBox3D"]
  280. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.4)
  281. operation = 2
  282. size = Vector3(7.5, 7.5, 7.5)
  283. material = SubResource("StandardMaterial3D_qrpkj")
  284. [node name="FogVolumeNegativeDensity" type="FogVolume" parent="."]
  285. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0)
  286. size = Vector3(8, 8, 8)
  287. material = SubResource("FogMaterial_sfd8y")
  288. [node name="FogVolumeEllipsoid" type="FogVolume" parent="."]
  289. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13, 6, 6)
  290. size = Vector3(4, 4, 4)
  291. shape = 0
  292. material = SubResource("FogMaterial_v1f5u")
  293. [node name="FogVolumeCone" type="FogVolume" parent="."]
  294. transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, -12, 2, 12)
  295. size = Vector3(4, 4, 4)
  296. shape = 1
  297. material = SubResource("FogMaterial_16tep")
  298. [node name="FogVolumeCylinder" type="FogVolume" parent="."]
  299. transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, -12, 3, 17)
  300. size = Vector3(4, 4, 4)
  301. shape = 2
  302. material = SubResource("FogMaterial_16tep")
  303. [node name="FogVolumeEllipsoidHeightFalloff" type="FogVolume" parent="."]
  304. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13, 6, 2)
  305. size = Vector3(4, 4, 4)
  306. shape = 0
  307. material = SubResource("FogMaterial_blauf")
  308. [node name="FogVolumeBox" type="FogVolume" parent="."]
  309. transform = Transform3D(0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -7.5189, 4.42465, -2.97368)
  310. size = Vector3(4, 4, 4)
  311. material = SubResource("FogMaterial_yvnd5")
  312. [node name="FogVolumeBoxHeightFalloff" type="FogVolume" parent="."]
  313. transform = Transform3D(0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -7.5189, 4.42465, -7.97368)
  314. size = Vector3(4, 4, 4)
  315. material = SubResource("FogMaterial_gcgmm")
  316. [node name="OmniLight3D" type="OmniLight3D" parent="."]
  317. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.823152, 1.836, 4.31818)
  318. light_color = Color(1, 0.929412, 0, 1)
  319. light_energy = 2.0
  320. omni_range = 6.0
  321. [node name="OmniLight3DHighVolumetricEnergy" type="OmniLight3D" parent="."]
  322. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.67463, 1.836, -4.89264)
  323. light_color = Color(1, 0.337255, 0, 1)
  324. light_energy = 0.1
  325. light_volumetric_fog_energy = 500.0
  326. light_specular = 0.0
  327. omni_range = 3.0
  328. [node name="OmniLight3DShadow" type="OmniLight3D" parent="."]
  329. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.82315, 1.836, 4.31818)
  330. light_color = Color(1, 0.929412, 0, 1)
  331. light_energy = 2.0
  332. shadow_enabled = true
  333. omni_range = 6.0
  334. [node name="SpotLight3D" type="SpotLight3D" parent="."]
  335. transform = Transform3D(0.966384, -0.226045, -0.1225, 0, 0.476461, -0.879196, 0.257105, 0.84964, 0.460444, -9.82684, -3.7099, 4.88511)
  336. light_color = Color(0, 0.439216, 1, 1)
  337. light_energy = 4.0
  338. light_volumetric_fog_energy = 25.0
  339. spot_angle = 35.0
  340. [node name="FogVolumeAlbedoTweak" type="FogVolume" parent="."]
  341. transform = Transform3D(-0.89393, -0.0897075, -0.439138, 0, 0.979766, -0.200148, 0.448207, -0.178918, -0.875842, -15.8913, -15.118, 8.26876)
  342. size = Vector3(8, 8, 8)
  343. material = SubResource("FogMaterial_8xcc6")
  344. [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
  345. libraries = {
  346. "": SubResource("AnimationLibrary_avffy")
  347. }
  348. autoplay = "move_fog_volume"
  349. [node name="MovingBox" type="MeshInstance3D" parent="."]
  350. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 10)
  351. mesh = SubResource("BoxMesh_fi43t")
  352. [node name="FogVolumeBlue" type="FogVolume" parent="MovingBox"]
  353. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
  354. material = SubResource("FogMaterial_ktn3i")
  355. [node name="FogVolumeTexture3D" type="FogVolume" parent="."]
  356. transform = Transform3D(-2.98023e-08, 4.82913e-08, -1, -4.2222e-08, -1, -4.82913e-08, -1, 4.2222e-08, -1.49012e-08, 17, 17, 12)
  357. size = Vector3(32, 32, 4)
  358. material = SubResource("FogMaterial_yomn8")
  359. [node name="FogVolumeShader" type="FogVolume" parent="."]
  360. transform = Transform3D(-2.98023e-08, 4.82913e-08, -1, -4.2222e-08, -1, -4.82913e-08, -1, 4.2222e-08, -1.49012e-08, -34.4124, 5, 12)
  361. size = Vector3(32, 8, 32)
  362. material = SubResource("ShaderMaterial_481nw")