Ported to GLES2

This commit is contained in:
Luke Hubmayer-Werner 2020-04-26 21:20:31 +09:30
parent dcc25dae5f
commit 9e70c0b4f4
6 changed files with 80 additions and 39 deletions

View File

@ -376,6 +376,7 @@ func touchbutton_released(col):
check_hold_release(col) check_hold_release(col)
#---------------------------------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------------------------------
var arr_div := Vector3(2.0, float(Rules.COLS), TAU)
func _draw(): func _draw():
var mesh := ArrayMesh.new() var mesh := ArrayMesh.new()
var noteline_data : Image = noteline_array_image.get_rect(Rect2(0, 0, 16, 16)) var noteline_data : Image = noteline_array_image.get_rect(Rect2(0, 0, 16, 16))
@ -386,7 +387,13 @@ func _draw():
for note in active_notes: for note in active_notes:
var position : float = (t+GameTheme.note_forecast_beats-note.time_hit)/GameTheme.note_forecast_beats var position : float = (t+GameTheme.note_forecast_beats-note.time_hit)/GameTheme.note_forecast_beats
var scale := 1.0 var scale := 1.0
noteline_data.set_pixel(i%16, i/16, Color(position, note.column, GameTheme.RADIAL_COL_ANGLES[note.column])) noteline_data.set_pixel(
i%16, i/16, Color(
position/arr_div.x,
note.column/arr_div.y,
GameTheme.RADIAL_COL_ANGLES[note.column]/arr_div.z
)
)
i += 1 i += 1
if position < GameTheme.INNER_NOTE_CIRCLE_RATIO: if position < GameTheme.INNER_NOTE_CIRCLE_RATIO:
scale *= position/GameTheme.INNER_NOTE_CIRCLE_RATIO scale *= position/GameTheme.INNER_NOTE_CIRCLE_RATIO
@ -536,6 +543,7 @@ func _ready():
notelines.set_mesh(make_noteline_mesh()) notelines.set_mesh(make_noteline_mesh())
notelines.material.set_shader_param("bps", bpm/60.0) notelines.material.set_shader_param("bps", bpm/60.0)
notelines.material.set_shader_param("array_postmul", arr_div)
noteline_array_image.create(16, 16, false, Image.FORMAT_RGBF) noteline_array_image.create(16, 16, false, Image.FORMAT_RGBF)

View File

@ -115,7 +115,6 @@ func _draw():
var ideal_ring_area = PI * (pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2) - pow(GameTheme.receptor_ring_radius-receptor_px/2-shadow_px, 2)) var ideal_ring_area = PI * (pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2) - pow(GameTheme.receptor_ring_radius-receptor_px/2-shadow_px, 2))
var quad_area = 4*pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2) var quad_area = 4*pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2)
# $"/root/main/InputHandler".text = "Vertices: %d*2 Skew: %.3f\nArea: %.0f\n(%.0f%% ideal ring)\n(%.0f%% quad)\nFPS: %.0f"%[mesh_v, skew, estimated_area, 100.0*estimated_area/ideal_ring_area, 100.0*estimated_area/quad_area, fps]
material.set_shader_param("dot_radius", 0.5*receptor_px/GameTheme.receptor_ring_radius) material.set_shader_param("dot_radius", 0.5*receptor_px/GameTheme.receptor_ring_radius)
material.set_shader_param("line_thickness", 0.5*ring_px/GameTheme.receptor_ring_radius) material.set_shader_param("line_thickness", 0.5*ring_px/GameTheme.receptor_ring_radius)
@ -133,16 +132,8 @@ func set_ring_skew(skew: int):
update_ring_mesh() update_ring_mesh()
func set_receptor_positions(skew:=0.0): func set_receptor_positions(skew:=0.0):
var receptor_array_image := Image.new()
receptor_array_image.create(8, 8, false, Image.FORMAT_RF)
receptor_array_image.lock()
for i in Rules.COLS:
receptor_array_image.set_pixel(i%8, i/8, Color(GameTheme.RADIAL_COL_ANGLES[i]+skew, 0.0, 0.0))
receptor_array_image.unlock()
var receptor_data_tex = ImageTexture.new()
receptor_data_tex.create_from_image(receptor_array_image, 0)
set_texture(receptor_data_tex)
material.set_shader_param("num_receptors", Rules.COLS) material.set_shader_param("num_receptors", Rules.COLS)
material.set_shader_param("receptor_offset", PI/Rules.COLS)
func _ready(): func _ready():
set_receptor_positions() set_receptor_positions()
@ -151,7 +142,8 @@ func _ready():
# $"../InputHandler/SkewSlider".connect("value_changed", self, "set_ring_skew") # $"../InputHandler/SkewSlider".connect("value_changed", self, "set_ring_skew")
$"/root".connect("size_changed", self, "update") $"/root".connect("size_changed", self, "update")
func _process(delta): #func _process(delta):
if not Engine.editor_hint: # pass
set_receptor_positions(sin(OS.get_ticks_msec()*0.001*0.0125*PI)*PI) # if not Engine.editor_hint:
update() # set_receptor_positions(sin(OS.get_ticks_msec()*0.001*0.0125*PI)*PI)
# update()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=2] [gd_scene load_steps=23 format=2]
[ext_resource path="res://main.gd" type="Script" id=1] [ext_resource path="res://main.gd" type="Script" id=1]
[ext_resource path="res://video.gd" type="Script" id=2] [ext_resource path="res://video.gd" type="Script" id=2]
@ -21,23 +21,37 @@
[sub_resource type="ShaderMaterial" id=1] [sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 4 ) shader = ExtResource( 4 )
shader_param/num_receptors = 8 shader_param/num_receptors = 8
shader_param/receptor_offset = 0.0
shader_param/line_color = Color( 0, 0, 1, 1 ) shader_param/line_color = Color( 0, 0, 1, 1 )
shader_param/dot_color = Color( 0, 0, 1, 1 ) shader_param/dot_color = Color( 0, 0, 1, 1 )
shader_param/shadow_color = Color( 0, 0, 0, 1 ) shader_param/shadow_color = Color( 0, 0, 0, 1 )
shader_param/line_thickness = 0.006 shader_param/line_thickness = 0.00434783
shader_param/dot_radius = 0.033 shader_param/dot_radius = 0.026087
shader_param/shadow_thickness = 0.01 shader_param/shadow_thickness = 0.0173913
shader_param/shadow_thickness_taper = 0.33 shader_param/shadow_thickness_taper = -0.75
shader_param/px = 0.002 shader_param/px = 0.00108696
[sub_resource type="ShaderMaterial" id=2] [sub_resource type="ArrayMesh" id=2]
surfaces/0 = {
"aabb": AABB( -481.834, -481.834, 0, 963.667, 963.667, 0 ),
"array_data": PoolByteArray( 0, 0, 220, 67, 0, 0, 0, 0, 166, 59, 0, 0, 177, 234, 240, 67, 0, 0, 0, 0, 48, 60, 0, 0, 95, 168, 216, 67, 118, 207, 152, 66, 137, 59, 80, 49, 183, 65, 237, 67, 202, 86, 167, 66, 32, 60, 210, 49, 125, 187, 206, 67, 38, 125, 22, 67, 48, 59, 60, 53, 64, 99, 226, 67, 249, 203, 36, 67, 223, 59, 187, 53, 141, 134, 190, 67, 0, 0, 92, 67, 160, 58, 166, 55, 217, 163, 208, 67, 177, 234, 112, 67, 65, 59, 48, 56, 159, 135, 168, 67, 204, 105, 141, 67, 220, 57, 235, 56, 142, 141, 184, 67, 186, 219, 154, 67, 107, 58, 98, 57, 204, 105, 141, 67, 159, 135, 168, 67, 235, 56, 220, 57, 186, 219, 154, 67, 142, 141, 184, 67, 98, 57, 107, 58, 0, 0, 92, 67, 141, 134, 190, 67, 166, 55, 160, 58, 177, 234, 112, 67, 217, 163, 208, 67, 48, 56, 65, 59, 38, 125, 22, 67, 125, 187, 206, 67, 60, 53, 48, 59, 249, 203, 36, 67, 64, 99, 226, 67, 187, 53, 223, 59, 118, 207, 152, 66, 95, 168, 216, 67, 80, 49, 137, 59, 202, 86, 167, 66, 183, 65, 237, 67, 210, 49, 32, 60, 141, 172, 242, 40, 0, 0, 220, 67, 0, 0, 166, 59, 143, 223, 4, 41, 177, 234, 240, 67, 0, 0, 48, 60, 118, 207, 152, 194, 95, 168, 216, 67, 80, 177, 137, 59, 202, 86, 167, 194, 183, 65, 237, 67, 210, 177, 32, 60, 38, 125, 22, 195, 125, 187, 206, 67, 60, 181, 48, 59, 249, 203, 36, 195, 64, 99, 226, 67, 187, 181, 223, 59, 0, 0, 92, 195, 141, 134, 190, 67, 166, 183, 160, 58, 177, 234, 112, 195, 217, 163, 208, 67, 48, 184, 65, 59, 204, 105, 141, 195, 159, 135, 168, 67, 235, 184, 220, 57, 186, 219, 154, 195, 142, 141, 184, 67, 98, 185, 107, 58, 159, 135, 168, 195, 204, 105, 141, 67, 220, 185, 235, 56, 142, 141, 184, 195, 186, 219, 154, 67, 107, 186, 98, 57, 141, 134, 190, 195, 0, 0, 92, 67, 160, 186, 166, 55, 217, 163, 208, 195, 177, 234, 112, 67, 65, 187, 48, 56, 125, 187, 206, 195, 38, 125, 22, 67, 48, 187, 60, 53, 64, 99, 226, 195, 249, 203, 36, 67, 223, 187, 187, 53, 95, 168, 216, 195, 118, 207, 152, 66, 137, 187, 80, 49, 183, 65, 237, 195, 202, 86, 167, 66, 32, 188, 210, 49, 0, 0, 220, 195, 141, 172, 114, 41, 166, 187, 0, 0, 177, 234, 240, 195, 143, 223, 132, 41, 48, 188, 0, 0, 95, 168, 216, 195, 118, 207, 152, 194, 137, 187, 80, 177, 183, 65, 237, 195, 202, 86, 167, 194, 32, 188, 210, 177, 125, 187, 206, 195, 38, 125, 22, 195, 48, 187, 60, 181, 64, 99, 226, 195, 249, 203, 36, 195, 223, 187, 187, 181, 141, 134, 190, 195, 0, 0, 92, 195, 160, 186, 166, 183, 217, 163, 208, 195, 177, 234, 112, 195, 65, 187, 48, 184, 159, 135, 168, 195, 204, 105, 141, 195, 220, 185, 235, 184, 142, 141, 184, 195, 186, 219, 154, 195, 107, 186, 98, 185, 204, 105, 141, 195, 159, 135, 168, 195, 235, 184, 220, 185, 186, 219, 154, 195, 142, 141, 184, 195, 98, 185, 107, 186, 0, 0, 92, 195, 141, 134, 190, 195, 166, 183, 160, 186, 177, 234, 112, 195, 217, 163, 208, 195, 48, 184, 65, 187, 38, 125, 22, 195, 125, 187, 206, 195, 60, 181, 48, 187, 249, 203, 36, 195, 64, 99, 226, 195, 187, 181, 223, 187, 118, 207, 152, 194, 95, 168, 216, 195, 80, 177, 137, 187, 202, 86, 167, 194, 183, 65, 237, 195, 210, 177, 32, 188, 106, 1, 182, 169, 0, 0, 220, 195, 0, 0, 166, 187, 87, 79, 199, 169, 177, 234, 240, 195, 0, 0, 48, 188, 118, 207, 152, 66, 95, 168, 216, 195, 80, 49, 137, 187, 202, 86, 167, 66, 183, 65, 237, 195, 210, 49, 32, 188, 38, 125, 22, 67, 125, 187, 206, 195, 60, 53, 48, 187, 249, 203, 36, 67, 64, 99, 226, 195, 187, 53, 223, 187, 0, 0, 92, 67, 141, 134, 190, 195, 166, 55, 160, 186, 177, 234, 112, 67, 217, 163, 208, 195, 48, 56, 65, 187, 204, 105, 141, 67, 159, 135, 168, 195, 235, 56, 220, 185, 186, 219, 154, 67, 142, 141, 184, 195, 98, 57, 107, 186, 159, 135, 168, 67, 204, 105, 141, 195, 220, 57, 235, 184, 142, 141, 184, 67, 186, 219, 154, 195, 107, 58, 98, 185, 141, 134, 190, 67, 0, 0, 92, 195, 160, 58, 166, 183, 217, 163, 208, 67, 177, 234, 112, 195, 65, 59, 48, 184, 125, 187, 206, 67, 38, 125, 22, 195, 48, 59, 60, 181, 64, 99, 226, 67, 249, 203, 36, 195, 223, 59, 187, 181, 95, 168, 216, 67, 118, 207, 152, 194, 137, 59, 80, 177, 183, 65, 237, 67, 202, 86, 167, 194, 32, 60, 210, 177, 0, 0, 220, 67, 0, 0, 0, 0, 166, 59, 0, 0, 177, 234, 240, 67, 0, 0, 0, 0, 48, 60, 0, 0 ),
"array_index_data": PoolByteArray( ),
"blend_shape_data": [ ],
"format": 359441,
"index_count": 0,
"primitive": 5,
"skeleton_aabb": [ ],
"vertex_count": 74
}
[sub_resource type="ShaderMaterial" id=3]
shader = ExtResource( 9 ) shader = ExtResource( 9 )
shader_param/bps = null shader_param/bps = null
shader_param/star_color = null shader_param/star_color = null
shader_param/held_color = null shader_param/held_color = null
shader_param/screen_size = null shader_param/screen_size = null
[sub_resource type="ShaderMaterial" id=3] [sub_resource type="ShaderMaterial" id=4]
shader = ExtResource( 10 ) shader = ExtResource( 10 )
shader_param/line_color = Color( 0.8, 0.8, 1, 0.8 ) shader_param/line_color = Color( 0.8, 0.8, 1, 0.8 )
shader_param/line_color_double = Color( 1, 1, 0.6, 0.9 ) shader_param/line_color_double = Color( 1, 1, 0.6, 0.9 )
@ -49,8 +63,11 @@ shader_param/dot_thickness = 0.033
shader_param/dot_fullbright_thickness = 0.013 shader_param/dot_fullbright_thickness = 0.013
shader_param/max_angle = 1.0708 shader_param/max_angle = 1.0708
shader_param/max_dist = 1.25 shader_param/max_dist = 1.25
shader_param/array_postmul = Vector3( 1, 1, 1 )
shader_param/array_sidelen = 16
shader_param/array_size = 256
[sub_resource type="CanvasItemMaterial" id=4] [sub_resource type="CanvasItemMaterial" id=5]
blend_mode = 4 blend_mode = 4
[node name="main" type="Node2D"] [node name="main" type="Node2D"]
@ -62,6 +79,7 @@ __meta__ = {
} }
[node name="music" type="AudioStreamPlayer" parent="."] [node name="music" type="AudioStreamPlayer" parent="."]
volume_db = -6.0
[node name="video" type="VideoPlayer" parent="."] [node name="video" type="VideoPlayer" parent="."]
margin_left = -540.0 margin_left = -540.0
@ -84,6 +102,7 @@ script = ExtResource( 3 )
[node name="Receptors" type="MeshInstance2D" parent="."] [node name="Receptors" type="MeshInstance2D" parent="."]
material = SubResource( 1 ) material = SubResource( 1 )
mesh = SubResource( 2 )
script = ExtResource( 5 ) script = ExtResource( 5 )
[node name="NoteHandler" type="Node2D" parent="."] [node name="NoteHandler" type="Node2D" parent="."]
@ -106,13 +125,13 @@ scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 8 ) texture = ExtResource( 8 )
[node name="meshinstance" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"] [node name="meshinstance" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"]
material = SubResource( 2 )
[node name="notelines" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"]
material = SubResource( 3 ) material = SubResource( 3 )
[node name="Painter" type="Node2D" parent="NoteHandler"] [node name="notelines" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"]
material = SubResource( 4 ) material = SubResource( 4 )
[node name="Painter" type="Node2D" parent="NoteHandler"]
material = SubResource( 5 )
script = ExtResource( 11 ) script = ExtResource( 11 )
[node name="Menu" type="Control" parent="."] [node name="Menu" type="Control" parent="."]

View File

@ -59,6 +59,7 @@ singletons_disabled=[ ]
[rendering] [rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true vram_compression/import_etc=true
environment/default_clear_color=Color( 0.16, 0.16, 0.16, 1 ) environment/default_clear_color=Color( 0.16, 0.16, 0.16, 1 )
quality/filters/msaa=1 quality/filters/msaa=1

View File

@ -1,6 +1,9 @@
shader_type canvas_item; shader_type canvas_item;
render_mode blend_premul_alpha; render_mode blend_premul_alpha;
const float TAU = 6.283185307;
const float PI = 3.1415926536;
uniform vec4 line_color : hint_color = vec4(0.8, 0.8, 1.0, 0.8); uniform vec4 line_color : hint_color = vec4(0.8, 0.8, 1.0, 0.8);
uniform vec4 line_color_double : hint_color = vec4(1.0, 1.0, 0.6, 0.9); uniform vec4 line_color_double : hint_color = vec4(1.0, 1.0, 0.6, 0.9);
uniform vec4 dot_color : hint_color = vec4(1.0, 1.0, 1.0, 0.8); uniform vec4 dot_color : hint_color = vec4(1.0, 1.0, 1.0, 0.8);
@ -12,12 +15,15 @@ uniform float dot_fullbright_thickness = 0.013;
uniform float max_angle = 1.0708; //3.14159*0.5; //radians(90.0); uniform float max_angle = 1.0708; //3.14159*0.5; //radians(90.0);
uniform float max_dist = 1.25; uniform float max_dist = 1.25;
// GLES2 clamps our color values that we send as makeshift arrays, so we need to divide them in code and multiply them in our shader
uniform vec3 array_postmul = vec3(1.0);
//void vertex() { //void vertex() {
//} //}
float angle_diff(float a, float b) { float angle_diff(float a, float b) {
float d = mod((a - b), 6.28318); float d = mod((a - b), TAU);
if (d > 3.14159) d = 6.28318 - d; if (d > PI) d = TAU - d;
return d; return d;
} }
@ -38,6 +44,17 @@ float angle_diff(float a, float b) {
// return color; // return color;
//} //}
uniform int array_sidelen = 16;
uniform int array_size = 256; // Remember to set both of these when using different sizes!
vec3 array_get(sampler2D tex, int index) {
// GLES3 only
//return texelFetch(TEXTURE, ivec2(index%array_sidelen, index/array_sidelen), 0).xyz;
// GLES2 workaround
float x = float(index%array_sidelen)/float(array_sidelen);
float y = float(index/array_sidelen)/float(array_sidelen);
return texture(tex, vec2(x, y), -100.0).xyz * array_postmul;
}
void fragment() { void fragment() {
float dist = distance(UV, vec2(0.0)); float dist = distance(UV, vec2(0.0));
@ -50,7 +67,7 @@ void fragment() {
bool last_double = false; bool last_double = false;
for (int i=0; i<238; i++){ for (int i=0; i<238; i++){
// x, y, z = distance, column, column_radians // x, y, z = distance, column, column_radians
vec3 sample = texelFetch(TEXTURE, ivec2(i%16, i/16), 0).xyz; vec3 sample = array_get(TEXTURE, i).xyz;
if (sample == vec3(0.0)) break; if (sample == vec3(0.0)) break;
float diff = abs(dist - sample.x); float diff = abs(dist - sample.x);
// Short-circuit out if our radial difference is too high to matter in any case. // Short-circuit out if our radial difference is too high to matter in any case.
@ -74,7 +91,7 @@ void fragment() {
float diff_a = angle_diff(angle, sample.z); float diff_a = angle_diff(angle, sample.z);
// Check if this note is a double with the next one // Check if this note is a double with the next one
vec3 sample2 = texelFetch(TEXTURE, ivec2((i+1)%16, (i+1)/16), 0).xyz; vec3 sample2 = array_get(TEXTURE, (i+1)).xyz;
if (sample.x == sample2.x){ if (sample.x == sample2.x){
// This note is a double! // This note is a double!
last_double = true; last_double = true;
@ -113,8 +130,9 @@ void fragment() {
} }
// Draw release dots // Draw release dots
for (int i=0; i<15; i++){ int i_start = array_size - array_sidelen;
vec3 sample = texelFetch(TEXTURE, ivec2(i, 15), 0).xyz; for (int i=i_start; i<array_size; i++){
vec3 sample = array_get(TEXTURE, i).xyz;
if (sample == vec3(0.0)) break; if (sample == vec3(0.0)) break;
vec2 uv = sample.x * vec2(cos(sample.z), -sin(sample.z)); vec2 uv = sample.x * vec2(cos(sample.z), -sin(sample.z));
float dist2 = distance(UV, uv); float dist2 = distance(UV, uv);

View File

@ -1,7 +1,11 @@
shader_type canvas_item; shader_type canvas_item;
render_mode blend_premul_alpha; render_mode blend_premul_alpha;
const float TAU = 6.283185307;
const float PI = 3.1415926536;
uniform int num_receptors = 8; uniform int num_receptors = 8;
uniform float receptor_offset = 0.0;
uniform vec4 line_color : hint_color = vec4(0.0, 0.0, 1.0, 1.0); uniform vec4 line_color : hint_color = vec4(0.0, 0.0, 1.0, 1.0);
uniform vec4 dot_color : hint_color = vec4(0.0, 0.0, 1.0, 1.0); uniform vec4 dot_color : hint_color = vec4(0.0, 0.0, 1.0, 1.0);
uniform vec4 shadow_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0); uniform vec4 shadow_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0);
@ -16,8 +20,8 @@ uniform float px = 0.002; // Represents 1px in UV space, for AA purposes
//} //}
float angle_diff(float a, float b) { float angle_diff(float a, float b) {
float d = mod((a - b), 6.28318); float d = mod((a - b), TAU);
if (d > 3.14159) d = 6.28318 - d; if (d > PI) d = TAU - d;
return d; return d;
} }
@ -42,9 +46,8 @@ void fragment() {
} }
// Iterate over all the receptors and check distance to them // Iterate over all the receptors and check distance to them
for (int i=0; i<num_receptors; i++){ float receptor_spacing = TAU/float(num_receptors);
lowp float rads = texelFetch(TEXTURE, ivec2(i%8, i/8), 0).x; for (float rads=receptor_offset; rads<TAU; rads+=receptor_spacing){
// Check for dot distance // Check for dot distance
vec2 uv = vec2(cos(rads), -sin(rads)); vec2 uv = vec2(cos(rads), -sin(rads));
float dist2 = distance(UV, uv); float dist2 = distance(UV, uv);