shaders and editor optimizations

This commit is contained in:
KadeDeveloper 2021-07-26 13:43:01 -07:00
parent 3e500b7a4d
commit 6010812204
7 changed files with 206 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package; package;
import openfl.system.System; import openfl.system.System;
import lime.app.Application;
#if sys #if sys
import sys.io.File; import sys.io.File;
#end #end
@ -1491,6 +1490,36 @@ class ChartingState extends MusicBeatState
{ {
updateHeads(); updateHeads();
for(i in sectionRenderes)
{
var diff = getYfromStrum(i.y) - Conductor.songPosition;
if (diff < 10000 && diff >= -40000)
{
i.active = true;
i.visible = true;
}
else
{
i.active = false;
i.visible = false;
}
}
for(i in curRenderedNotes)
{
var diff = i.strumTime - Conductor.songPosition;
if (diff < 10000 && diff >= -40000)
{
i.active = true;
i.visible = true;
}
else
{
i.active = false;
i.visible = false;
}
}
var doInput = true; var doInput = true;
for (i in Typeables) for (i in Typeables)

View File

@ -85,10 +85,10 @@ class FreeplayState extends MusicBeatState
} }
var diffs = []; var diffs = [];
var diffsThatExist = []; var diffsThatExist = [];
#if sys
if (FileSystem.exists('assets/data/${format}/${format}-hard.json')) if (FileSystem.exists('assets/data/${format}/${format}-hard.json'))
diffsThatExist.push("Hard"); diffsThatExist.push("Hard");
if (FileSystem.exists('assets/data/${format}/${format}-easy.json')) if (FileSystem.exists('assets/data/${format}/${format}-easy.json'))
@ -101,6 +101,9 @@ class FreeplayState extends MusicBeatState
Application.current.window.alert("No difficulties found for chart, skipping.",meta.songName + " Chart"); Application.current.window.alert("No difficulties found for chart, skipping.",meta.songName + " Chart");
continue; continue;
} }
#else
diffsThatExist = ["Easy","Normal","Hard"];
#end
if (diffsThatExist.contains("Easy")) if (diffsThatExist.contains("Easy"))
FreeplayState.loadDiff(0,format,meta.songName,diffs); FreeplayState.loadDiff(0,format,meta.songName,diffs);
if (diffsThatExist.contains("Normal")) if (diffsThatExist.contains("Normal"))

View File

@ -78,6 +78,10 @@ class Main extends Sprite
gameHeight = Math.ceil(stageHeight / zoom); gameHeight = Math.ceil(stageHeight / zoom);
} }
#if !cpp
framerate = 60;
#end
#if cpp #if cpp
initialState = Caching; initialState = Caching;
game = new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen); game = new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen);

74
source/ModchartShader.hx Normal file
View File

@ -0,0 +1,74 @@
import flixel.system.FlxAssets.FlxShader;
class ModchartShader extends FlxShader
{
public var vertexHeader = "attribute float openfl_Alpha;
attribute vec4 openfl_ColorMultiplier;
attribute vec4 openfl_ColorOffset;
attribute vec4 openfl_Position;
attribute vec2 openfl_TextureCoord;
varying float openfl_Alphav;
varying vec4 openfl_ColorMultiplierv;
varying vec4 openfl_ColorOffsetv;
varying vec2 openfl_TextureCoordv;
uniform mat4 openfl_Matrix;
uniform bool openfl_HasColorTransform;
uniform vec2 openfl_TextureSize;";
public var vertexBody = "openfl_Alphav = openfl_Alpha;
openfl_TextureCoordv = openfl_TextureCoord;
if (openfl_HasColorTransform) {
openfl_ColorMultiplierv = openfl_ColorMultiplier;
openfl_ColorOffsetv = openfl_ColorOffset / 255.0;
}
gl_Position = openfl_Matrix * openfl_Position;";
public var vertexSource = "#pragma header
void main(void) {
#pragma body
}";
public var fragmentHeader = "varying float openfl_Alphav;
varying vec4 openfl_ColorMultiplierv;
varying vec4 openfl_ColorOffsetv;
varying vec2 openfl_TextureCoordv;
uniform bool openfl_HasColorTransform;
uniform sampler2D openfl_Texture;
uniform vec2 openfl_TextureSize;";
public var fragmentBody = "vec4 color = texture2D (openfl_Texture, openfl_TextureCoordv);
if (color.a == 0.0) {
gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0);
} else if (openfl_HasColorTransform) {
color = vec4 (color.rgb / color.a, color.a);
mat4 colorMultiplier = mat4 (0);
colorMultiplier[0][0] = openfl_ColorMultiplierv.x;
colorMultiplier[1][1] = openfl_ColorMultiplierv.y;
colorMultiplier[2][2] = openfl_ColorMultiplierv.z;
colorMultiplier[3][3] = 1.0; // openfl_ColorMultiplierv.w;
color = clamp (openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0);
if (color.a > 0.0) {
gl_FragColor = vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav);
} else {
gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0);
}
} else {
gl_FragColor = color * openfl_Alphav;
}";
public function new(frag:String,?vert:String = "")
{
if (vert != "")
glVertexSource = vert;
glFragmentSource = frag;
if (glVertexSource != null)
{
glVertexSource = StringTools.replace(glVertexSource, "#pragma header", vertexHeader);
glVertexSource = StringTools.replace(glVertexSource, "#pragma body", vertexBody);
}
if (glVertexSource != null)
{
glFragmentSource = StringTools.replace(glFragmentSource, "#pragma header", fragmentHeader);
glFragmentSource = StringTools.replace(glFragmentSource, "#pragma body", fragmentBody);
}
super();
}
}

View File

@ -347,6 +347,8 @@ class ModchartState
lua = null; lua = null;
} }
public var luaWiggles:Map<String,WiggleEffect> = new Map<String,WiggleEffect>();
// LUA SHIT // LUA SHIT
function new() function new()
@ -427,6 +429,41 @@ class ModchartState
Lua_helper.add_callback(lua,"getProperty", getPropertyByName); Lua_helper.add_callback(lua,"getProperty", getPropertyByName);
Lua_helper.add_callback(lua,"setNoteWiggle", function(wiggleId) {
PlayState.instance.camNotes.setFilters([new ShaderFilter(luaWiggles.get(wiggleId).shader)]);
});
Lua_helper.add_callback(lua,"setSustainWiggle", function(wiggleId) {
PlayState.instance.camSustains.setFilters([new ShaderFilter(luaWiggles.get(wiggleId).shader)]);
});
Lua_helper.add_callback(lua,"createWiggle", function(freq:Float,amplitude:Float,speed:Float) {
var wiggle = new WiggleEffect();
wiggle.waveAmplitude = amplitude;
wiggle.waveSpeed = speed;
wiggle.waveFrequency = freq;
var id = Lambda.count(luaWiggles) + 1 + "";
luaWiggles.set(id,wiggle);
return id;
});
Lua_helper.add_callback(lua,"setWiggleTime", function(wiggleId:String,time:Float) {
var wiggle = luaWiggles.get(wiggleId);
wiggle.shader.uTime.value = [time];
});
Lua_helper.add_callback(lua,"setWiggleAmplitude", function(wiggleId:String,amp:Float) {
var wiggle = luaWiggles.get(wiggleId);
wiggle.waveAmplitude = amp;
});
// Lua_helper.add_callback(lua,"makeAnimatedSprite", makeAnimatedLuaSprite); // Lua_helper.add_callback(lua,"makeAnimatedSprite", makeAnimatedLuaSprite);
// this one is still in development // this one is still in development

View File

@ -1,5 +1,6 @@
package; package;
import Song.Event; import Song.Event;
import openfl.media.Sound; import openfl.media.Sound;
#if sys #if sys
@ -178,6 +179,8 @@ class PlayState extends MusicBeatState
public var iconP1:HealthIcon; // making these public again because i may be stupid public var iconP1:HealthIcon; // making these public again because i may be stupid
public var iconP2:HealthIcon; // what could go wrong? public var iconP2:HealthIcon; // what could go wrong?
public var camHUD:FlxCamera; public var camHUD:FlxCamera;
public var camSustains:FlxCamera;
public var camNotes:FlxCamera;
private var camGame:FlxCamera; private var camGame:FlxCamera;
public var cannotDie = false; public var cannotDie = false;
@ -382,9 +385,15 @@ class PlayState extends MusicBeatState
camGame = new FlxCamera(); camGame = new FlxCamera();
camHUD = new FlxCamera(); camHUD = new FlxCamera();
camHUD.bgColor.alpha = 0; camHUD.bgColor.alpha = 0;
camSustains = new FlxCamera();
camSustains.bgColor.alpha = 0;
camNotes = new FlxCamera();
camNotes.bgColor.alpha = 0;
FlxG.cameras.reset(camGame); FlxG.cameras.reset(camGame);
FlxG.cameras.add(camHUD); FlxG.cameras.add(camHUD);
FlxG.cameras.add(camSustains);
FlxG.cameras.add(camNotes);
FlxCamera.defaultCameras = [camGame]; FlxCamera.defaultCameras = [camGame];
@ -2327,10 +2336,10 @@ class PlayState extends MusicBeatState
luaModchart.setVar('cameraZoom', FlxG.camera.zoom); luaModchart.setVar('cameraZoom', FlxG.camera.zoom);
luaModchart.executeState('update', [elapsed]); luaModchart.executeState('update', [elapsed]);
for (i in luaWiggles) for (key => value in luaModchart.luaWiggles)
{ {
trace('wiggle le gaming'); trace('wiggle le gaming');
i.update(elapsed); value.update(elapsed);
} }
/*for (i in 0...strumLineNotes.length) { /*for (i in 0...strumLineNotes.length) {
@ -2904,6 +2913,10 @@ class PlayState extends MusicBeatState
{ {
var dunceNote:Note = unspawnNotes[0]; var dunceNote:Note = unspawnNotes[0];
notes.add(dunceNote); notes.add(dunceNote);
if (!dunceNote.isSustainNote)
dunceNote.cameras = [camNotes];
else
dunceNote.cameras = [camSustains];
var index:Int = unspawnNotes.indexOf(dunceNote); var index:Int = unspawnNotes.indexOf(dunceNote);
unspawnNotes.splice(index, 1); unspawnNotes.splice(index, 1);

41
source/ShaderShader.hx Normal file
View File

@ -0,0 +1,41 @@
import flixel.system.FlxAssets;
class ShaderShader extends FlxShader
{
@:glFragmentSource('
#pragma header
uniform float fade;
varying vec4 color;
varying vec2 textureCoord;
varying vec2 textureSize;
uniform sampler2D sampler0;
float luma(vec3 color) {
return dot(color, vec3(0.299, 0.587, 0.114));
}
vec3 rgb(float r, float g, float b) {
return vec3(r/255.0,g/255.0,b/255.0);
}
void main()
{
vec2 uv = textureCoord;
vec3 col = texture2D( sampler0, uv ).rgb;
float bright=floor(luma(col+0.4)*4.0)/4.0;
vec3 newcol;
if (bright<0.3) newcol = rgb(54.0,87.0,53.0);
else if (bright<0.6) newcol = rgb(128.0,128.0,0.0);
else newcol = rgb(157.0,187.0,97.0);
gl_FragColor = vec4( newcol*(fade)+col*(1.0-fade), 1.0 ) * color;
}
')
public function new()
{
super();
}
}