Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Felis
52e3db3041 Using viewport texture instead of manual rect blending 2024-01-27 01:15:01 +01:00
Martin Felis
4501b19bc4 Basing world coloring works. 2024-01-27 00:05:04 +01:00
18 changed files with 377 additions and 51 deletions

View File

@ -7,5 +7,5 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
func _process(_delta):
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://vcebfpqo2ko7"
path="res://.godot/imported/player_bomb_mask.png-d9f1c068bea19451ba5b876c7e08dc0c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/player_bomb_mask.png"
dest_files=["res://.godot/imported/player_bomb_mask.png-d9f1c068bea19451ba5b876c7e08dc0c.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=false
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bnsrnuuq28p4d"
path="res://.godot/imported/player_draw_mask.png-642d7868cd4c60507b494afb6f8c473e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/player_draw_mask.png"
dest_files=["res://.godot/imported/player_draw_mask.png-642d7868cd4c60507b494afb6f8c473e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b2c7rc40v7wfl"
path.s3tc="res://.godot/imported/test_world_color_texture.png-02e59ccaa66632399d7c654ca92aca46.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://assets/textures/test_world_color_texture.png"
dest_files=["res://.godot/imported/test_world_color_texture.png-02e59ccaa66632399d7c654ca92aca46.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cek45oeqv3jvj"
path="res://.godot/imported/test_world_color_texture_viewport.png-16630f653b885f113d1eb3f3ecf4106a.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/test_world_color_texture_viewport.png"
dest_files=["res://.godot/imported/test_world_color_texture_viewport.png-16630f653b885f113d1eb3f3ecf4106a.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -1,13 +1,18 @@
extends CharacterBody3D
@export var color : Color = Color.DODGER_BLUE
@export var move_right_action := "move_right"
@export var move_left_action := "move_left"
@export var move_down_action := "move_down"
@export var move_up_action := "move_up"
@export var dash_action := "dash"
@export var bomb_action := "bomp"
@onready var geometry = $Geometry
signal bomb_triggered
var angle = 0
var is_dashing = false
var dash_time = 0
@ -28,6 +33,9 @@ func _physics_process(delta):
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed(bomb_action):
emit_signal("bomb_triggered", self)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
@ -41,6 +49,7 @@ func _physics_process(delta):
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
if Input.is_action_just_pressed("dash_p1"):
is_dashing = true;

View File

@ -3,25 +3,26 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://5xyjcnjoqxjm"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
path.s3tc="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.s3tc.ctex"]
[params]
compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -31,7 +32,7 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@ -0,0 +1,21 @@
[gd_resource type="StandardMaterial3D" load_steps=3 format=3 uid="uid://bg3dawo5kkosg"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_wonuc"]
noise_type = 0
frequency = 0.014
fractal_lacunarity = 3.0
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_iklfu"]
width = 32
height = 32
seamless = true
seamless_blend_skirt = 0.857
normalize = false
noise = SubResource("FastNoiseLite_wonuc")
[resource]
albedo_color = Color(0.113725, 0.431373, 0.266667, 0.933333)
albedo_texture = SubResource("NoiseTexture2D_iklfu")
uv1_scale = Vector3(20, 1, 20)
uv1_triplanar = true
texture_filter = 0

View File

@ -0,0 +1,9 @@
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://c60s78p4g17ye"]
[ext_resource type="Shader" path="res://materials/shader/WorldColoring.gdshader" id="1_ashe5"]
[ext_resource type="Texture2D" uid="uid://b2c7rc40v7wfl" path="res://assets/textures/test_world_color_texture.png" id="2_60odu"]
[resource]
render_priority = 1
shader = ExtResource("1_ashe5")
shader_parameter/world_color_texture = ExtResource("2_60odu")

View File

@ -0,0 +1,27 @@
shader_type spatial;
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform sampler2D world_color_texture : hint_default_black, repeat_disable;
void vertex() {
// Called for every vertex the material is visible on.
}
void fragment() {
vec4 projected_coords = INV_VIEW_MATRIX * vec4(VERTEX, 1.0);
vec4 currentColor = textureLod(screen_texture, SCREEN_UV, 0.0);
vec4 playerColorationColor = textureLod(world_color_texture, projected_coords.xz * 0.01 + vec2(0.5), 0.0);
vec3 colorToLuminance = vec3(0.2126, 0.7152, 0.0722);
vec3 desaturatedColor = vec3(dot(currentColor.rgb, colorToLuminance) * 0.4) + 0.1 * currentColor.rgb;
ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + currentColor.rgb * playerColorationColor.a;
ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + (playerColorationColor.rgb * 0.3 + currentColor.rgb * 0.7) * playerColorationColor.a;
}
//void light() {
// Called for every pixel for every light affecting the material.
// Uncomment to replace the default light processing function with this one.
//}

View File

@ -51,13 +51,20 @@ dash_p1={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":79,"key_label":0,"unicode":102,"echo":false,"script":null)
]
}
bomp_p1={
bomb_p1={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":80,"key_label":0,"unicode":113,"echo":false,"script":null)
]
}
[layer_names]
3d_physics/layer_1="World"
3d_physics/layer_2="Obstacles"
3d_physics/layer_3="Player"
3d_physics/layer_4="Collectibles"
[rendering]
renderer/rendering_method="gl_compatibility"

View File

@ -14,7 +14,6 @@ script = ExtResource("1_7jqda")
[node name="Viewport" type="SubViewport" parent="."]
own_world_3d = true
world_3d = SubResource("World3D_5g233")
size = Vector2i(256, 256)
[node name="World" parent="Viewport" instance=ExtResource("2_voimb")]

View File

@ -2,16 +2,57 @@ extends Node3D
@onready var player1: CharacterBody3D = $Player1
@onready var camera: Camera3D = $Camera3D
@onready var level: Node3D = $Level
@onready var world_coloring_viewport: SubViewport = $WorldColoringViewport
@onready var world_coloring_player1_texture_rect: TextureRect = $WorldColoringViewport/Player1TextureRect
@onready var world_coloring_player1_sprite: Sprite2D = $WorldColoringViewport/Player1Sprite
@onready var world_coloring_player1_bomb_sprite: Sprite2D = $WorldColoringViewport/Player1BombSprite
var camera_offset: Vector3;
var world_coloring_material: ShaderMaterial
# Called when the node enters the scene tree for the first time.
func _ready():
camera_offset = camera.global_position - player1.global_position
pass # Replace with function body.
world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres")
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
world_coloring_player1_sprite.modulate = player1.color
world_coloring_player1_bomb_sprite.modulate = player1.color
player1.connect("bomb_triggered", player_bomb_triggered)
apply_world_coloring_recursive(level)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
func _process(_delta):
camera.global_position = player1.global_position + camera_offset
pass
func _physics_process(_delta):
world_coloring_player1_sprite.global_position = player_position_to_world_coloring_position(player1.global_position)
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
func player_position_to_world_coloring_position(player_position: Vector3):
var result = Vector2 (player_position.x * 10 + 500, player_position.z * 10 + 500)
return result;
func apply_world_coloring_recursive (node):
for child in node.get_children():
var mesh_instance := child as MeshInstance3D
if mesh_instance:
assign_world_coloring_pass(mesh_instance)
apply_world_coloring_recursive(child)
func assign_world_coloring_pass(mesh_instance: MeshInstance3D) -> void:
var material = mesh_instance.get_active_material(0)
if not material:
return
material.next_pass = world_coloring_material
func player_bomb_triggered(player):
world_coloring_player1_bomb_sprite.global_position = player_position_to_world_coloring_position(player.global_position)
world_coloring_player1_bomb_sprite.visible = true

View File

@ -1,37 +1,11 @@
[gd_scene load_steps=11 format=3 uid="uid://b1nm5h3yccr16"]
[gd_scene load_steps=16 format=3 uid="uid://b1nm5h3yccr16"]
[ext_resource type="Script" path="res://entities/Player.gd" id="1_ca7jo"]
[ext_resource type="Script" path="res://scenes/World.gd" id="1_gtcjp"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_wonuc"]
noise_type = 0
frequency = 0.014
fractal_lacunarity = 3.0
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_iklfu"]
width = 32
height = 32
seamless = true
seamless_blend_skirt = 0.857
normalize = false
noise = SubResource("FastNoiseLite_wonuc")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_b5tqf"]
albedo_color = Color(0.113725, 0.431373, 0.266667, 0.933333)
albedo_texture = SubResource("NoiseTexture2D_iklfu")
uv1_triplanar = true
texture_filter = 0
[sub_resource type="CylinderMesh" id="CylinderMesh_a3rev"]
material = SubResource("StandardMaterial3D_b5tqf")
top_radius = 20.0
bottom_radius = 20.0
height = 0.2
radial_segments = 8
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ar5d4"]
height = 0.2
radius = 20.0
[ext_resource type="Texture2D" uid="uid://cek45oeqv3jvj" path="res://assets/textures/test_world_color_texture_viewport.png" id="3_bvxb7"]
[ext_resource type="Texture2D" uid="uid://bnsrnuuq28p4d" path="res://assets/textures/player_draw_mask.png" id="4_dipd5"]
[ext_resource type="Material" uid="uid://bg3dawo5kkosg" path="res://materials/GrassNoiseMaterial.tres" id="4_pseda"]
[ext_resource type="Texture2D" uid="uid://vcebfpqo2ko7" path="res://assets/textures/player_bomb_mask.png" id="5_17c1g"]
[sub_resource type="BoxMesh" id="BoxMesh_yle83"]
size = Vector3(0.24, 0.75, 0.24)
@ -45,23 +19,34 @@ ambient_light_source = 3
ambient_light_color = Color(0.521569, 0.521569, 0.521569, 1)
ambient_light_energy = 2.64
[sub_resource type="World3D" id="World3D_s7kgt"]
[sub_resource type="BoxShape3D" id="BoxShape3D_p0rqu"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mr6ph"]
albedo_color = Color(1, 0.137255, 1, 1)
[sub_resource type="BoxMesh" id="BoxMesh_237xr"]
material = SubResource("StandardMaterial3D_mr6ph")
[sub_resource type="BoxMesh" id="BoxMesh_bwn4a"]
material = ExtResource("4_pseda")
[sub_resource type="BoxShape3D" id="BoxShape3D_mneaf"]
size = Vector3(100, 2, 100)
[node name="World" type="Node3D"]
script = ExtResource("1_gtcjp")
[node name="Platform" type="StaticBody3D" parent="."]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Platform"]
mesh = SubResource("CylinderMesh_a3rev")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Platform"]
shape = SubResource("CylinderShape3D_ar5d4")
[node name="Player1" type="CharacterBody3D" parent="."]
collision_mask = 3
script = ExtResource("1_ca7jo")
move_right_action = "move_right_p1"
move_left_action = "move_left_p1"
move_down_action = "move_down_p1"
move_up_action = "move_up_p1"
dash_action = "dash_p1"
bomb_action = "bomb_p1"
[node name="Geometry" type="MeshInstance3D" parent="Player1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0)
@ -79,4 +64,94 @@ transform = Transform3D(-4.37114e-08, -0.528438, 0.848972, 0, 0.848972, 0.528438
shadow_enabled = true
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.305147, 0.952305, 0, -0.952305, 0.305147, -4.26326e-13, 4.70264, 1.09419)
transform = Transform3D(1, 0, 0, 0, 0.305147, 0.952305, 0, -0.952305, 0.305147, 0, 10, 3.10854)
[node name="Sprite3D" type="Sprite3D" parent="."]
transform = Transform3D(20, 0, 0, 0, -8.74228e-07, 50, 0, -20, -2.18557e-06, 0, 0, 0)
modulate = Color(1, 1, 1, 0.32549)
[node name="WorldColoringViewport" type="SubViewport" parent="."]
own_world_3d = true
world_3d = SubResource("World3D_s7kgt")
transparent_bg = true
handle_input_locally = false
size = Vector2i(1000, 1000)
render_target_clear_mode = 1
render_target_update_mode = 4
[node name="TextureRect" type="TextureRect" parent="WorldColoringViewport"]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_bvxb7")
[node name="Player1TextureRect" type="TextureRect" parent="WorldColoringViewport"]
visible = false
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture = ExtResource("4_dipd5")
[node name="Player1Sprite" type="Sprite2D" parent="WorldColoringViewport"]
texture = ExtResource("4_dipd5")
[node name="Player1BombSprite" type="Sprite2D" parent="WorldColoringViewport"]
texture = ExtResource("5_17c1g")
[node name="Level" type="Node3D" parent="."]
[node name="Box" type="StaticBody3D" parent="Level"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.38367, 0, 2.83298)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/Box"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_p0rqu")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/Box"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr")
[node name="Platform2" type="StaticBody3D" parent="Level"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/Platform2"]
transform = Transform3D(101, 0, 0, 0, 2, 0, 0, 0, 101, 0, -1, 0)
mesh = SubResource("BoxMesh_bwn4a")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/Platform2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
shape = SubResource("BoxShape3D_mneaf")
[node name="BoxNorthEast" type="StaticBody3D" parent="Level"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -50, 0, -50)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/BoxNorthEast"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_p0rqu")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/BoxNorthEast"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr")
[node name="BoxSouthWest" type="StaticBody3D" parent="Level"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50, 0, 50)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/BoxSouthWest"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_p0rqu")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/BoxSouthWest"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_237xr")