Using viewport texture instead of manual rect blending
This commit is contained in:
+16
-24
@@ -5,26 +5,23 @@ extends Node3D
|
||||
@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
|
||||
var world_coloring_texture: ImageTexture
|
||||
var world_coloring_image: Image
|
||||
|
||||
const player_mask_texture: = preload("res://assets/textures/player_draw_mask.png")
|
||||
var player_mask_image: ImageTexture;
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
camera_offset = camera.global_position - player1.global_position
|
||||
|
||||
world_coloring_material = load("res://materials/WorldColoringMaterialPass.tres")
|
||||
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_texture)
|
||||
world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture())
|
||||
|
||||
world_coloring_image = Image.create(1000, 1000, 0, Image.FORMAT_RGBA8);
|
||||
world_coloring_image.fill(Color(1, 0, 1, 1))
|
||||
world_coloring_texture = ImageTexture.create_from_image(world_coloring_image)
|
||||
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)
|
||||
|
||||
@@ -34,18 +31,11 @@ func _process(_delta):
|
||||
pass
|
||||
|
||||
func _physics_process(_delta):
|
||||
#var player_world_color_coordinate : Vector2 = player1.global_position
|
||||
var world_coloring_player1_rect : Rect2
|
||||
world_coloring_player1_rect.position = player_position_to_world_coloring_position(player1.global_position)
|
||||
world_coloring_player1_rect.size = Vector2(10, 10)
|
||||
|
||||
world_coloring_image.fill_rect(world_coloring_player1_rect, player1.color)
|
||||
world_coloring_texture = ImageTexture.create_from_image(world_coloring_image)
|
||||
|
||||
apply_world_coloring_recursive(level)
|
||||
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(position: Vector3):
|
||||
var result = Vector2 (position.x * 10 + 495, position.z * 10 + 495)
|
||||
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):
|
||||
@@ -60,7 +50,9 @@ 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
|
||||
|
||||
var world_coloring_pass :ShaderMaterial = material.next_pass as ShaderMaterial
|
||||
world_coloring_pass.set_shader_parameter("world_color_texture", world_coloring_texture)
|
||||
|
||||
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
|
||||
|
||||
+33
-8
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=14 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"]
|
||||
[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)
|
||||
@@ -22,7 +23,11 @@ ambient_light_energy = 2.64
|
||||
|
||||
[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")
|
||||
@@ -36,12 +41,12 @@ script = ExtResource("1_gtcjp")
|
||||
[node name="Player1" type="CharacterBody3D" parent="."]
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_ca7jo")
|
||||
color = null
|
||||
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 = null
|
||||
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)
|
||||
@@ -59,7 +64,7 @@ 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, 0, 10, 1.966)
|
||||
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)
|
||||
@@ -69,11 +74,13 @@ modulate = Color(1, 1, 1, 0.32549)
|
||||
own_world_3d = true
|
||||
world_3d = SubResource("World3D_s7kgt")
|
||||
transparent_bg = true
|
||||
size = Vector2i(1001, 1001)
|
||||
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
|
||||
@@ -82,14 +89,32 @@ grow_vertical = 2
|
||||
texture = ExtResource("3_bvxb7")
|
||||
|
||||
[node name="Player1TextureRect" type="TextureRect" parent="WorldColoringViewport"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
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, 0, 0, 1)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user