From fb97d172f42ae3682c03a743e28ab8297e674e81 Mon Sep 17 00:00:00 2001 From: Fabio Iotti Date: Sat, 10 Aug 2024 08:54:21 +0200 Subject: [PATCH] Nebula background --- main.tscn | 5 ++++- scenes/nebula/nebula.gdshader | 14 ++++++++++++++ scenes/nebula/nebula.tscn | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scenes/nebula/nebula.gdshader create mode 100644 scenes/nebula/nebula.tscn diff --git a/main.tscn b/main.tscn index bf068b3..a922d8c 100644 --- a/main.tscn +++ b/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://cdaf4bh0jaa45"] +[gd_scene load_steps=12 format=3 uid="uid://cdaf4bh0jaa45"] [ext_resource type="PackedScene" uid="uid://dq00mi6jwsa1f" path="res://scenes/planet/planet.tscn" id="1_0p552"] [ext_resource type="Script" path="res://scripts/game_logic.gd" id="1_kb05v"] @@ -8,6 +8,7 @@ [ext_resource type="Script" path="res://scenes/player/local_player.gd" id="4_7rlmh"] [ext_resource type="Texture2D" uid="uid://dx1wjviioa8u5" path="res://icons/chip.svg" id="4_pgo63"] [ext_resource type="Script" path="res://ui.gd" id="7_khbdl"] +[ext_resource type="PackedScene" uid="uid://dtlatmtuggp6x" path="res://scenes/nebula/nebula.tscn" id="7_sv4lv"] [ext_resource type="PackedScene" uid="uid://cpffyaoh8x5bp" path="res://scenes/ships_fleet/ships_fleet.tscn" id="9_be18b"] [ext_resource type="PackedScene" uid="uid://ckfk1xgxfk1c3" path="res://scenes/trail/trail.tscn" id="10_b5ql7"] @@ -37,6 +38,8 @@ script = ExtResource("2_plgh6") color = Color(0.835294, 0.160784, 0, 1) icon = ExtResource("4_pgo63") +[node name="Nebula" parent="." instance=ExtResource("7_sv4lv")] + [node name="Game" type="Node2D" parent="."] [node name="Planets" type="Node2D" parent="Game"] diff --git a/scenes/nebula/nebula.gdshader b/scenes/nebula/nebula.gdshader new file mode 100644 index 0000000..94c1be8 --- /dev/null +++ b/scenes/nebula/nebula.gdshader @@ -0,0 +1,14 @@ +shader_type canvas_item; + +uniform sampler2D noise: repeat_enable; + +float rand(vec2 co){ + return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); +} + +void fragment() { + vec3 nebula = vec3(texture(noise, FRAGCOORD.xy * .0005).r, texture(noise, FRAGCOORD.xy * .0005 + 0.1).r, texture(noise, FRAGCOORD.xy * .0005 + 0.2).r) * 0.05; + vec3 star = (rand(FRAGCOORD.xy * .01) < 0.1 && rand(FRAGCOORD.xy * .02) < .01) ? vec3(rand(FRAGCOORD.xy * .03)) : vec3(0.); + + COLOR = vec4(nebula + star, 1.); +} diff --git a/scenes/nebula/nebula.tscn b/scenes/nebula/nebula.tscn new file mode 100644 index 0000000..b48c073 --- /dev/null +++ b/scenes/nebula/nebula.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=5 format=3 uid="uid://dtlatmtuggp6x"] + +[ext_resource type="Shader" path="res://scenes/nebula/nebula.gdshader" id="1_nqp0c"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_8c2xm"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_cukca"] +width = 256 +height = 256 +seamless = true +noise = SubResource("FastNoiseLite_8c2xm") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_y72ex"] +shader = ExtResource("1_nqp0c") +shader_parameter/noise = SubResource("NoiseTexture2D_cukca") + +[node name="Nebula" type="ColorRect"] +material = SubResource("ShaderMaterial_y72ex") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2