[gd_resource type="ShaderMaterial" load_steps=3 format=2]

[ext_resource path="res://Bullshit/THIS SHOULD FIX IThoefully.tres" type="Texture" id=1]

[sub_resource type="Shader" id=1]
code = "shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,skip_vertex_transform;


uniform mat3 canvas_transform;
uniform sampler2D table : hint_albedo;


vec4 indx(int i) {
	//return vec4(1.0, 1.0, 0.0, 1.0);
	return textureLod(table, vec2(float(i) * 0.125 + 0.0625), 0);
}

void vertex() {
	vec4 row0;
	vec4 row1;
	vec4 row2;
	vec4 row3;
	
	if (VERTEX.z <= 0.0) {
		row0 = vec4(indx(0).x, indx(0).y, indx(0).z, indx(0).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);
		row3 = vec4(indx(3).x, indx(3).y, indx(3).z, indx(3).w);
	}
	else {
		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);
		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);
	}
	mat4 crank_matrix = mat4(row0, row1, row2, row3);
	
	
	vec4 pre = vec4(VERTEX, 1.0) * crank_matrix;
	vec3 transformed_xy = vec3(pre.xy / pre.w, 1.0) * transpose(canvas_transform);
	vec4 post = vec4(transformed_xy.x, transformed_xy.y, pre.z, 1.0);
	POSITION = post;
	VERTEX = post.xyz;
	COLOR = vec4(post.w, post.w - 1.0, post.w * 0.2, 1.0);
	
//	vec3 tran = vec3(VERTEX.xy, 1.0) * transpose(canvas_transform);
//	vec4 pos_t = vec4(tran.x, tran.y, VERTEX.z, 1.0);
//	POSITION = pos_t;
//	VERTEX = (pos_t / pos_t.w).xyz;
}

void fragment() {
	//ALBEDO = vec3(0.33, 0.81, 0.95);
	ALBEDO = texture(table, UV).rgb;
}"

[resource]
shader = SubResource( 1 )
shader_param/canvas_transform = Basis( 0.622756, 0.051744, -0.187155, 0.0954389, -1.14864, 0.015115, 0, 0, 1 )
shader_param/table = ExtResource( 1 )
