Fixed texture issue on slide trails.

Still needs to be layered correctly and destroyed after use.
This commit is contained in:
Luke Hubmayer-Werner 2019-11-13 10:56:31 +10:30
parent 8e5f51cce9
commit 27964ab955
2 changed files with 16 additions and 9 deletions

View File

@ -115,6 +115,7 @@ func make_slide_trail_mesh(note: Dictionary) -> ArrayMesh:
var vertices := PoolVector2Array() var vertices := PoolVector2Array()
var uvs := PoolVector2Array() var uvs := PoolVector2Array()
var colors := PoolColorArray() var colors := PoolColorArray()
var size := theme.sprite_size2*SQRT2
# First we need to determine how many arrows to leave. # First we need to determine how many arrows to leave.
# Chord length is 2r*sin(theta/2) # Chord length is 2r*sin(theta/2)
# Arc length is r*theta (in rads) # Arc length is r*theta (in rads)
@ -145,9 +146,9 @@ func make_slide_trail_mesh(note: Dictionary) -> ArrayMesh:
var angle : float = RADIAL_UNIT_VECTORS[note.column].angle_to_point(RADIAL_UNIT_VECTORS[note.column_release]) var angle : float = RADIAL_UNIT_VECTORS[note.column].angle_to_point(RADIAL_UNIT_VECTORS[note.column_release])
var start : Vector2 = RADIAL_UNIT_VECTORS[note.column] * theme.receptor_ring_radius var start : Vector2 = RADIAL_UNIT_VECTORS[note.column] * theme.receptor_ring_radius
var end : Vector2 = RADIAL_UNIT_VECTORS[note.column_release] * theme.receptor_ring_radius var end : Vector2 = RADIAL_UNIT_VECTORS[note.column_release] * theme.receptor_ring_radius
var uv1o : Vector2 = polar2cartesian(theme.sprite_size2, angle) var uv1o : Vector2 = polar2cartesian(size, angle)
var uv2o : Vector2 = polar2cartesian(theme.sprite_size2, angle+PI/2.0) var uv2o : Vector2 = polar2cartesian(size, angle+PI/2.0)
var uv3o : Vector2 = polar2cartesian(theme.sprite_size2, angle-PI/2.0) var uv3o : Vector2 = polar2cartesian(size, angle-PI/2.0)
for i in trail_length: for i in trail_length:
var offset : Vector2 = lerp(start, end, (i+1)/float(trail_length)) var offset : Vector2 = lerp(start, end, (i+1)/float(trail_length))
vertices[i*3] = offset + uv1o vertices[i*3] = offset + uv1o
@ -162,9 +163,9 @@ func make_slide_trail_mesh(note: Dictionary) -> ArrayMesh:
var circle_angle : float = lerp(start_a, end_a, (i+1)/float(trail_length)) var circle_angle : float = lerp(start_a, end_a, (i+1)/float(trail_length))
var angle : float = circle_angle + PI/2.0 var angle : float = circle_angle + PI/2.0
var offset : Vector2 = polar2cartesian(theme.receptor_ring_radius, circle_angle) var offset : Vector2 = polar2cartesian(theme.receptor_ring_radius, circle_angle)
vertices[i*3] = offset + polar2cartesian(theme.sprite_size2, angle) vertices[i*3] = offset + polar2cartesian(size, angle)
vertices[i*3+1] = offset + polar2cartesian(theme.sprite_size2, angle+PI/2.0) vertices[i*3+1] = offset + polar2cartesian(size, angle+PI/2.0)
vertices[i*3+2] = offset + polar2cartesian(theme.sprite_size2, angle-PI/2.0) vertices[i*3+2] = offset + polar2cartesian(size, angle-PI/2.0)
Note.SlideType.ARC_ACW: Note.SlideType.ARC_ACW:
var start_a : float = RADIAL_COL_ANGLES[note.column] var start_a : float = RADIAL_COL_ANGLES[note.column]
var end_a : float = RADIAL_COL_ANGLES[note.column_release] var end_a : float = RADIAL_COL_ANGLES[note.column_release]
@ -174,9 +175,9 @@ func make_slide_trail_mesh(note: Dictionary) -> ArrayMesh:
var circle_angle : float = lerp(start_a, end_a, (i+1)/float(trail_length)) var circle_angle : float = lerp(start_a, end_a, (i+1)/float(trail_length))
var angle : float = circle_angle - PI/2.0 var angle : float = circle_angle - PI/2.0
var offset : Vector2 = polar2cartesian(theme.receptor_ring_radius, circle_angle) var offset : Vector2 = polar2cartesian(theme.receptor_ring_radius, circle_angle)
vertices[i*3] = offset + polar2cartesian(theme.sprite_size2, angle) vertices[i*3] = offset + polar2cartesian(size, angle)
vertices[i*3+1] = offset + polar2cartesian(theme.sprite_size2, angle+PI/2.0) vertices[i*3+1] = offset + polar2cartesian(size, angle+PI/2.0)
vertices[i*3+2] = offset + polar2cartesian(theme.sprite_size2, angle-PI/2.0) vertices[i*3+2] = offset + polar2cartesian(size, angle-PI/2.0)
arrays[Mesh.ARRAY_VERTEX] = vertices arrays[Mesh.ARRAY_VERTEX] = vertices
arrays[Mesh.ARRAY_TEX_UV] = uvs arrays[Mesh.ARRAY_TEX_UV] = uvs

View File

@ -12,3 +12,9 @@ uniform float bps = 1.0;
void vertex() { void vertex() {
COLOR.a = clamp(COLOR.a-trail_progress, 0.0, 1.0); COLOR.a = clamp(COLOR.a-trail_progress, 0.0, 1.0);
} }
void fragment() {
vec4 sample = texture(TEXTURE, UV);
COLOR.rgb = sample.rgb;
COLOR.a *= sample.a;
}