use texture in piece shader

master
Fabien Freling 2019-11-27 13:55:08 +01:00
parent 6a1f831e1a
commit efcb9ca4ed
2 changed files with 80 additions and 20 deletions

View File

@ -12,3 +12,7 @@ func _ready() -> void:
$ColorRect.rect_size.x = size
$ColorRect.rect_size.y = size
$ColorRect/Label.text = str(number)
var shader = $ColorRect.material as ShaderMaterial
shader.set_shader_param("scale", Vector3(0.5, 0.5, 1.0))
shader.set_shader_param("offset", Vector3(0.8, 0.1, 0.0))

View File

@ -1,13 +1,35 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
[ext_resource path="res://assets/escher_lizards.jpg" type="Texture" id=2]
[sub_resource type="VisualShaderNodeColorConstant" id=1]
constant = Color( 0.73997, 0.960938, 0.446686, 1 )
[sub_resource type="VisualShaderNodeTexture" id=2]
output_port_for_preview = 0
texture = ExtResource( 2 )
[sub_resource type="VisualShader" id=2]
[sub_resource type="VisualShaderNodeInput" id=5]
output_port_for_preview = 0
input_name = "uv"
[sub_resource type="VisualShaderNodeVectorOp" id=6]
output_port_for_preview = 0
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.5, 0.5, 1 ) ]
operator = 2
[sub_resource type="VisualShaderNodeVectorOp" id=7]
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.8, 0.1, 0 ) ]
[sub_resource type="VisualShaderNodeVec3Uniform" id=8]
uniform_name = "scale"
[sub_resource type="VisualShaderNodeVec3Uniform" id=9]
uniform_name = "offset"
[sub_resource type="VisualShader" id=3]
code = "shader_type canvas_item;
uniform vec3 scale;
uniform vec3 offset;
uniform sampler2D tex_frg_3;
void vertex() {
@ -16,14 +38,35 @@ void vertex() {
}
void fragment() {
// Color:2
vec3 n_out2p0;
float n_out2p1;
n_out2p0 = vec3(0.739970,0.960938,0.446686);
n_out2p1 = 1.000000;
// Input:4
vec3 n_out4p0;
n_out4p0 = vec3(UV,0.0);
// VectorUniform:7
vec3 n_out7p0;
n_out7p0 = scale;
// VectorOp:5
vec3 n_out5p0;
n_out5p0 = n_out4p0 * n_out7p0;
// VectorUniform:8
vec3 n_out8p0;
n_out8p0 = offset;
// VectorOp:6
vec3 n_out6p0;
n_out6p0 = n_out5p0 + n_out8p0;
// Texture:3
vec3 n_out3p0;
float n_out3p1;
vec4 tex_frg_3_read = texture( tex_frg_3 , n_out6p0.xy );
n_out3p0 = tex_frg_3_read.rgb;
n_out3p1 = tex_frg_3_read.a;
// Output:0
COLOR.rgb = n_out2p0;
COLOR.rgb = n_out3p0;
}
@ -32,25 +75,38 @@ void light() {
}
"
graph_offset = Vector2( -175, -3.73047 )
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2( 380, 80 )
nodes/fragment/2/node = SubResource( 1 )
nodes/fragment/2/position = Vector2( 140, 80 )
nodes/fragment/connections = PoolIntArray( 2, 0, 0, 0 )
nodes/fragment/0/position = Vector2( 1080, 160 )
nodes/fragment/3/node = SubResource( 2 )
nodes/fragment/3/position = Vector2( 820, 120 )
nodes/fragment/4/node = SubResource( 5 )
nodes/fragment/4/position = Vector2( 140, 120 )
nodes/fragment/5/node = SubResource( 6 )
nodes/fragment/5/position = Vector2( 360, 100 )
nodes/fragment/6/node = SubResource( 7 )
nodes/fragment/6/position = Vector2( 620, 220 )
nodes/fragment/7/node = SubResource( 8 )
nodes/fragment/7/position = Vector2( 140, 320 )
nodes/fragment/8/node = SubResource( 9 )
nodes/fragment/8/position = Vector2( 420, 360 )
nodes/fragment/connections = PoolIntArray( 3, 0, 0, 0, 4, 0, 5, 0, 5, 0, 6, 0, 6, 0, 3, 0, 7, 0, 5, 1, 8, 0, 6, 1 )
[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 2 )
[sub_resource type="ShaderMaterial" id=4]
shader = SubResource( 3 )
shader_param/scale = null
shader_param/offset = null
[node name="Piece" type="Node2D"]
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource( 3 )
material = SubResource( 4 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 128.0
margin_bottom = 128.0
margin_right = 64.0
margin_bottom = 64.0
[node name="Label" type="Label" parent="ColorRect"]
margin_left = 10.0