Added view_transform for spatial space.
This commit is contained in:
parent
274b605b05
commit
68d8e00922
49
Main.tscn
49
Main.tscn
@ -1,10 +1,11 @@
|
|||||||
[gd_scene load_steps=17 format=2]
|
[gd_scene load_steps=20 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://TryingOutSomethingNew.gd" type="Script" id=1]
|
[ext_resource path="res://TryingOutSomethingNew.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Node2D.gd" type="Script" id=2]
|
[ext_resource path="res://Node2D.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://icon.png" type="Texture" id=3]
|
[ext_resource path="res://icon.png" type="Texture" id=3]
|
||||||
[ext_resource path="res://addons/summer_day/interface/display.gd" type="Script" id=4]
|
[ext_resource path="res://addons/summer_day/interface/display.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://Bullshit/Main.gd" type="Script" id=5]
|
[ext_resource path="res://Bullshit/Main.gd" type="Script" id=5]
|
||||||
|
[ext_resource path="res://addons/summer_day/tool/canvas/rendering/space_camera.gd" type="Script" id=6]
|
||||||
|
|
||||||
[sub_resource type="Shader" id=1]
|
[sub_resource type="Shader" id=1]
|
||||||
code = "shader_type spatial;
|
code = "shader_type spatial;
|
||||||
@ -37,7 +38,7 @@ shader = SubResource( 1 )
|
|||||||
shader_param/albedo = Color( 0.768627, 0.231373, 0.231373, 1 )
|
shader_param/albedo = Color( 0.768627, 0.231373, 0.231373, 1 )
|
||||||
shader_param/ha = null
|
shader_param/ha = null
|
||||||
|
|
||||||
[sub_resource type="Image" id=15]
|
[sub_resource type="Image" id=20]
|
||||||
data = {
|
data = {
|
||||||
"data": PoolByteArray( 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63 ),
|
"data": PoolByteArray( 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63 ),
|
||||||
"format": "RGBAFloat",
|
"format": "RGBAFloat",
|
||||||
@ -49,7 +50,7 @@ data = {
|
|||||||
[sub_resource type="ImageTexture" id=16]
|
[sub_resource type="ImageTexture" id=16]
|
||||||
flags = 0
|
flags = 0
|
||||||
flags = 0
|
flags = 0
|
||||||
image = SubResource( 15 )
|
image = SubResource( 20 )
|
||||||
size = Vector2( 8, 1 )
|
size = Vector2( 8, 1 )
|
||||||
|
|
||||||
[sub_resource type="CapsuleMesh" id=5]
|
[sub_resource type="CapsuleMesh" id=5]
|
||||||
@ -63,6 +64,7 @@ code = "shader_type spatial;
|
|||||||
render_mode blend_mix,depth_draw_opaque,cull_disabled,skip_vertex_transform;
|
render_mode blend_mix,depth_draw_opaque,cull_disabled,skip_vertex_transform;
|
||||||
|
|
||||||
|
|
||||||
|
uniform mat3 canvas_transform;
|
||||||
uniform sampler2D table : hint_albedo;
|
uniform sampler2D table : hint_albedo;
|
||||||
|
|
||||||
|
|
||||||
@ -82,34 +84,46 @@ void vertex() {
|
|||||||
row1 = vec4(indx(1).x, indx(1).y, indx(1).z, indx(1).w);
|
row1 = vec4(indx(1).x, indx(1).y, indx(1).z, indx(1).w);
|
||||||
row2 = vec4(indx(2).x, indx(2).y, indx(2).z, indx(2).w);
|
row2 = vec4(indx(2).x, indx(2).y, indx(2).z, indx(2).w);
|
||||||
row3 = vec4(indx(3).x, indx(3).y, indx(3).z, indx(3).w);
|
row3 = vec4(indx(3).x, indx(3).y, indx(3).z, indx(3).w);
|
||||||
// row0 = vec4(0.1, 0.0, 0.0, 0.0);
|
|
||||||
// row1 = vec4(0.0, 0.1, 0.0, 0.0);
|
|
||||||
// row2 = vec4(0.0, 0.0, 0.1, 0.0);
|
|
||||||
// row3 = vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
row0 = vec4(indx(4).x, indx(4).y, indx(4).z, indx(4).w);
|
row0 = vec4(indx(4).x, indx(4).y, indx(4).z, indx(4).w);
|
||||||
row1 = vec4(indx(5).x, indx(5).y, indx(5).z, indx(5).w);
|
row1 = vec4(indx(5).x, indx(5).y, indx(5).z, indx(5).w);
|
||||||
row2 = vec4(indx(6).x, indx(6).y, indx(6).z, indx(6).w);
|
row2 = vec4(indx(6).x, indx(6).y, indx(6).z, indx(6).w);
|
||||||
row3 = vec4(indx(7).x, indx(7).y, indx(7).z, indx(7).w);
|
row3 = vec4(indx(7).x, indx(7).y, indx(7).z, indx(7).w);
|
||||||
// row0 = vec4(0.1, 0.0, 0.0, 0.0);
|
|
||||||
// row1 = vec4(0.0, 0.1, 0.0, 0.0);
|
|
||||||
// row2 = vec4(0.0, 0.0, 0.1, 0.0);
|
|
||||||
// row3 = vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
}
|
||||||
mat4 crank_matrix = mat4(row0, row1, row2, row3);
|
mat4 crank_matrix = mat4(row0, row1, row2, row3);
|
||||||
|
|
||||||
|
|
||||||
vec4 pre = vec4(VERTEX, 1.0) * crank_matrix;
|
vec4 pre = vec4(VERTEX, 1.0) * crank_matrix;
|
||||||
POSITION = pre;
|
vec3 transformed_xy = vec3(pre.xy, 1.0) * transpose(canvas_transform);
|
||||||
VERTEX = (pre / pre.w).xyz;
|
vec4 post = vec4(transformed_xy.x, transformed_xy.y, pre.z, pre.w);
|
||||||
|
POSITION = post;
|
||||||
|
VERTEX = (post / post.w).xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
ALBEDO = texture(table, UV).rgb;
|
ALBEDO = texture(table, UV).rgb;
|
||||||
}"
|
}"
|
||||||
|
|
||||||
|
[sub_resource type="Image" id=21]
|
||||||
|
data = {
|
||||||
|
"data": PoolByteArray( 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 62, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 128, 62, 0, 0, 0, 0, 154, 153, 25, 190, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63 ),
|
||||||
|
"format": "RGBAFloat",
|
||||||
|
"height": 1,
|
||||||
|
"mipmaps": false,
|
||||||
|
"width": 8
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="ImageTexture" id=19]
|
||||||
|
flags = 0
|
||||||
|
flags = 0
|
||||||
|
image = SubResource( 21 )
|
||||||
|
size = Vector2( 8, 1 )
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=7]
|
[sub_resource type="ShaderMaterial" id=7]
|
||||||
shader = SubResource( 6 )
|
shader = SubResource( 6 )
|
||||||
shader_param/table = SubResource( 16 )
|
shader_param/canvas_transform = Basis( 0.0194222, -0.293236, -1.35872, -0.545418, -0.0361252, 0.406385, 0, 0, 1 )
|
||||||
|
shader_param/table = SubResource( 19 )
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id=8]
|
[sub_resource type="QuadMesh" id=8]
|
||||||
|
|
||||||
@ -159,10 +173,8 @@ script = ExtResource( 1 )
|
|||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -25.8122, 0, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -25.8122, 0, 0 )
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="."]
|
[node name="Camera" type="Camera" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 32.985 )
|
|
||||||
projection = 1
|
|
||||||
current = true
|
|
||||||
size = 2.0
|
size = 2.0
|
||||||
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite" parent="."]
|
[node name="Sprite" type="Sprite" parent="."]
|
||||||
position = Vector2( 619.786, 73.103 )
|
position = Vector2( 619.786, 73.103 )
|
||||||
@ -174,7 +186,8 @@ visible = false
|
|||||||
opacity = 0.15
|
opacity = 0.15
|
||||||
texture = ExtResource( 3 )
|
texture = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="CSGBox" type="CSGMesh" parent="."]
|
[node name="CSGBox" type="CSGMesh" parent="." groups=["ListenForTransformUpdate"]]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.401247, 0.829002, -0.735263 )
|
||||||
mesh = SubResource( 5 )
|
mesh = SubResource( 5 )
|
||||||
material = SubResource( 7 )
|
material = SubResource( 7 )
|
||||||
|
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
|
tool
|
||||||
extends Control
|
extends Control
|
||||||
class_name SummerDayMainScreen
|
class_name SummerDayMainScreen
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print(get_path())
|
||||||
|
@ -13,13 +13,15 @@ func _ready():
|
|||||||
tool_context.canvas_state = canvas_state
|
tool_context.canvas_state = canvas_state
|
||||||
canvas_state.connect("view_transform_changed",
|
canvas_state.connect("view_transform_changed",
|
||||||
$Render/BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
$Render/BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
||||||
|
canvas_state.connect("clip_space_view_transform_changed",
|
||||||
|
self, "_on_clip_space_view_transform_changed")
|
||||||
|
|
||||||
|
|
||||||
func _gui_input(event):
|
func _gui_input(event):
|
||||||
tool_pool.run_most_prior(event, tool_context)
|
tool_pool.run_most_prior(event, tool_context)
|
||||||
|
|
||||||
|
|
||||||
# _gui_input() cannot receive released event so we do this here.
|
# _gui_input() cannot receive screen touch released event so we do this here.
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event is InputEventScreenTouch and !event.is_pressed():
|
if event is InputEventScreenTouch and !event.is_pressed():
|
||||||
tool_pool.run_most_prior(event, tool_context)
|
tool_pool.run_most_prior(event, tool_context)
|
||||||
@ -37,9 +39,24 @@ func _on_SummerDay_scene_changed(new_scene):
|
|||||||
|
|
||||||
func _on_Canvas_resized():
|
func _on_Canvas_resized():
|
||||||
canvas_state.rect_size = rect_size
|
canvas_state.rect_size = rect_size
|
||||||
|
canvas_state.update_canvas_to_clip_space()
|
||||||
canvas_state.update_fill_transform(scene)
|
canvas_state.update_fill_transform(scene)
|
||||||
|
|
||||||
|
|
||||||
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
||||||
$Render/BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
$Render/BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
||||||
canvas_state.update_fill_transform(scene)
|
canvas_state.update_fill_transform(scene)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_clip_space_view_transform_changed(new_transform):
|
||||||
|
var listeners = get_tree().get_nodes_in_group("ListenForTransformUpdate")
|
||||||
|
for i in listeners:
|
||||||
|
var basis = Basis(
|
||||||
|
Vector3(new_transform.x.x, new_transform.x.y, 0.0),
|
||||||
|
Vector3(new_transform.y.x, new_transform.y.y, 0.0),
|
||||||
|
Vector3(new_transform.origin.x, new_transform.origin.y, 1.0)
|
||||||
|
)
|
||||||
|
i.get_material().set_shader_param("canvas_transform", basis)
|
||||||
|
#print(i.get_material().get_shader_param("canvas_transform"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,12 +4,16 @@ class_name SummerDayCanvasState
|
|||||||
signal fill_transform_changed(fill_transform)
|
signal fill_transform_changed(fill_transform)
|
||||||
signal canvas_transform_changed(canvas_transform)
|
signal canvas_transform_changed(canvas_transform)
|
||||||
signal view_transform_changed(view_transform)
|
signal view_transform_changed(view_transform)
|
||||||
|
signal clip_space_view_transform_changed(view_transform)
|
||||||
|
|
||||||
var rect_size: Vector2
|
var rect_size: Vector2
|
||||||
|
|
||||||
var fill_transform := Transform2D.IDENTITY
|
var fill_transform := Transform2D.IDENTITY
|
||||||
var canvas_transform := Transform2D.IDENTITY setget _set_canvas_transform
|
var canvas_transform := Transform2D.IDENTITY setget _set_canvas_transform
|
||||||
var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
var view_transform := Transform2D.IDENTITY # canvas_transform * fill_transform
|
||||||
|
|
||||||
|
var clip_space_view_transform := Transform2D.IDENTITY
|
||||||
|
var canvas_to_clip_space := Transform2D.IDENTITY
|
||||||
|
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
@ -44,8 +48,23 @@ func update_fill_transform(scene):
|
|||||||
emit_signal("fill_transform_changed", fill_transform)
|
emit_signal("fill_transform_changed", fill_transform)
|
||||||
|
|
||||||
|
|
||||||
|
func update_canvas_to_clip_space():
|
||||||
|
canvas_to_clip_space = Transform2D(
|
||||||
|
Vector2(2.0 / rect_size.x, 0.0),
|
||||||
|
Vector2(0.0, -2.0 / rect_size.y),
|
||||||
|
Vector2(-1.0, 1.0)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func _update_view_transformation(transform):
|
func _update_view_transformation(transform):
|
||||||
view_transform = canvas_transform * fill_transform
|
view_transform = canvas_transform * fill_transform
|
||||||
|
# var off_view_transform = view_transform
|
||||||
|
# var offset = off_view_transform.origin
|
||||||
|
# off_view_transform.origin = Vector2.ZERO
|
||||||
|
clip_space_view_transform = canvas_to_clip_space * view_transform
|
||||||
|
# clip_space_view_transform.origin = offset
|
||||||
|
|
||||||
|
emit_signal("clip_space_view_transform_changed", clip_space_view_transform)
|
||||||
emit_signal("view_transform_changed", view_transform)
|
emit_signal("view_transform_changed", view_transform)
|
||||||
|
|
||||||
|
|
||||||
|
25
addons/summer_day/tool/canvas/rendering/space_camera.gd
Normal file
25
addons/summer_day/tool/canvas/rendering/space_camera.gd
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
tool
|
||||||
|
extends Camera
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print("HowAboutNow?")
|
||||||
|
_on_view_transform_changed(Transform.IDENTITY)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_view_transform_changed(new_transform: Transform2D):
|
||||||
|
var tran = Transform.IDENTITY
|
||||||
|
tran.origin.y = 0.5
|
||||||
|
tran = tran.scaled(Vector3(0.2, 0.8, 1.0))
|
||||||
|
print(tran)
|
||||||
|
var rid = VisualServer.camera_create()
|
||||||
|
var basis_scale = tran.basis.get_scale()
|
||||||
|
var scale = lerp(basis_scale.x, basis_scale.y, 0.5)
|
||||||
|
VisualServer.camera_set_orthogonal(rid, 1.0 / scale, 0.0, 500.0)
|
||||||
|
VisualServer.camera_set_transform(rid, tran)#Transform(new_transform))
|
||||||
|
VisualServer.viewport_attach_camera(get_viewport().get_viewport_rid(), rid)
|
||||||
|
|
||||||
|
# var tran = Transform2D.IDENTITY
|
||||||
|
# tran.y.y = -2.0
|
||||||
|
# get_viewport().global_canvas_transform = tran
|
||||||
|
pass
|
@ -1,7 +1,6 @@
|
|||||||
extends Reference
|
extends Reference
|
||||||
class_name SummerDayTool
|
class_name SummerDayTool
|
||||||
|
|
||||||
|
|
||||||
var priority = 0
|
var priority = 0
|
||||||
var modifier_layer = 0
|
var modifier_layer = 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user