Merge branch 'main' into new-editors
This commit is contained in:
@@ -14,6 +14,7 @@ function onPlaySingAnim(event) {
|
||||
}
|
||||
|
||||
function update(elapsed) {
|
||||
if (getAnimName() == null || (getAnimName().substr(0, 5) == "shoot" && isAnimFinished()))
|
||||
var animName = getAnimName();
|
||||
if (animName == null || (animName.substr(0, 5) == "shoot" && isAnimFinished()))
|
||||
dance();
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
## Here are guides on common mistakes and advices for writting shaders for flixel and openfl.
|
||||
|
||||
It's important to follow this guide as most shader coders make these mistakes a lot and end up with shaders that only work on certain devices.
|
||||
|
||||
-------
|
||||
### Common mistakes and how to avoid them
|
||||
Avoid using `0.` or `.0` for floats, instead, use `0.0` (ending the float number with an `.0`)
|
||||
(please note that despite half floats working on nVidia gpus, other gpus like AMD gpus don't support this feature)
|
||||
|
||||
Avoid using switch cases, and use if statements where possible.
|
||||
(switch cases are not supported on macOS or miscellaneous platforms)
|
||||
|
||||
Ints are not recommended when initiating vectors. (ex, vec2(1, 1) is not supported on certain platforms).
|
||||
And use floats where it's expected. Like mod(1.0, 2.0) instead of mod(1, 2)
|
||||
|
||||
Avoid using the following types:
|
||||
- ivec2,3,4
|
||||
- bvec2,3,4
|
||||
- uvec2,3,4
|
||||
- uint
|
||||
|
||||
as they are unsupported on certain platforms.
|
||||
|
||||
Avoid using `gl_` at the start of your variables (ex, `float gl_Number` can break your shaders).
|
||||
|
||||
Applying defaults to uniforms is not possible, so please set the defaults in your shader constructor or after initializing the shader.
|
||||
|
||||
Avoid using `<number>u` (ex, 8u)
|
||||
Avoid initializing variables with the name `input` or `sample`, as those cause the shader to stop working on AMD gpus or other platforms.
|
||||
|
||||
Avoid using the % operator, instead use the mod function.
|
||||
|
||||
Avoid using arrays if possible.
|
||||
|
||||
### Guide to porting shaders from shadertoy.com
|
||||
This is a sample shader that simply renders the texture of a sprite/camera.
|
||||
```glsl
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
// Normalized pixel coordinates (from 0 to 1)
|
||||
vec2 uv = fragCoord/iResolution.xy;
|
||||
|
||||
// Time varying pixel color
|
||||
vec4 col = texture(iChannel0, uv);
|
||||
|
||||
// Output to screen
|
||||
fragColor = col;
|
||||
}
|
||||
```
|
||||
We will show each step to converting this shader into an usable openfl/flixel shader
|
||||
|
||||
1. replace ``void mainImage( out vec4 fragColor, in vec2 fragCoord )`` with a simple ``void main()`` (flixel and openfl do not have any parameters since the coords are defined outside the function)
|
||||
2. replace ``vec2 uv = fragCoord/iResolution.xy;`` with ``vec2 uv = openfl_TextureCoordv`` (or in some cases, add ``vec2 fragCoord = openfl_TextureCoordv*openfl_TextureSize.xy`` before it and replace `iResolution.xy` with ``openfl_TextureSize.xy`` (if the uv value is different than usual))
|
||||
3. replace ``vec4 col = texture(iChannel0, uv);`` with ``vec4 col = texture2D(bitmap, uv);`` or ``vec4 col = flixel_texture2D(bitmap, uv);`` (keep in mind bitmap is the pixels of the camera/sprite the shader is aplied to)
|
||||
4. finally, replace ``fragColor = col;`` with ``gl_FragColor = col;``
|
||||
|
||||
###### Keep in mind that this covers the most basic on how to convert a shader from shadertoy.com, complex shaders will need more expertise with handling shaders before converting those.
|
||||
|
||||
-------
|
||||
|
||||
### Common Practice:
|
||||
|
||||
Use ``texture2D`` for camera shaders, and FlxGame shaders, and ``flixel_texture2D`` for sprite shaders.
|
||||
``flixel_texture2D`` applies the .colorTransform, while ``texture2D`` doesn't.
|
||||
|
||||
-------
|
||||
|
||||
Extra:
|
||||
|
||||
Use tabs for indentation
|
||||
@@ -13,5 +13,5 @@ void main()
|
||||
vec2 pixel = gl_FragCoord.xy;
|
||||
|
||||
if (boxCollision(pixel, clipRect)) gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv.xy);
|
||||
else gl_FragColor = vec4(0.);
|
||||
else gl_FragColor = vec4(0.0);
|
||||
}
|
||||
@@ -7,12 +7,9 @@ int steps = 16;
|
||||
int stepsInside = 2;
|
||||
float strength = 0.0075;
|
||||
vec4 getColor(vec2 pos) {
|
||||
if (pos.x < 0.0) pos.x = 0.0;
|
||||
else if (pos.x > 1.0 - (1.0 / openfl_TextureSize.x)) pos.x = 1.0 - (1.0 / openfl_TextureSize.x);
|
||||
if (pos.y < 0.0) pos.y = 0.0;
|
||||
else if (pos.y > 1.0 - (1.0 / openfl_TextureSize.y)) pos.y = 1.0 - (1.0 / openfl_TextureSize.y);
|
||||
// return textureCam(bitmap, pos);
|
||||
return flixel_texture2D(bitmap, pos);
|
||||
vec2 ps = (pos);
|
||||
ps = clamp(ps, vec2(0.0), 1.0 - (1.0 / openfl_TextureSize.xy));
|
||||
return flixel_texture2D(bitmap, (ps));
|
||||
}
|
||||
void main() {
|
||||
// vec2 camPos = getCamPos(openfl_TextureCoordv);
|
||||
|
||||
@@ -14,7 +14,7 @@ uniform float pixelOffset;
|
||||
uniform float playerPosition;
|
||||
|
||||
uniform sampler2D waveformTexture;
|
||||
uniform ivec2 waveformSize;
|
||||
uniform vec2 waveformSize;
|
||||
|
||||
uniform bool lowDetail;
|
||||
|
||||
@@ -22,7 +22,7 @@ float getAmplitude(vec2 pixel) {
|
||||
float pixelID = floor((pixel.y+pixelOffset)/3.0);
|
||||
|
||||
// TODO: INVESTIGATE THE 1.+ AND WHY IT WORKS (SRSLY I GOT NO CLUE) -lunar
|
||||
vec2 wavePixel = vec2(mod(pixelID,waveformSize.x), 1.0+floor(pixelID/waveformSize.x));
|
||||
vec2 wavePixel = vec2(mod(pixelID, waveformSize.x), 1.0+floor(pixelID/waveformSize.x));
|
||||
vec4 waveData = texture2D(waveformTexture, wavePixel / waveformSize);
|
||||
|
||||
int id = int(mod(wavePixel.x, 3.0));
|
||||
|
||||
@@ -8,10 +8,7 @@ var tankmanPool = [];
|
||||
|
||||
function recycleTankman() {
|
||||
if(tankmanPool.length == 0) {
|
||||
var a = new TankmenBG();
|
||||
a.self = a;
|
||||
a.fuckingnewfuckingnew();
|
||||
return a;
|
||||
return new TankmenBG();
|
||||
} else {
|
||||
return tankmanPool.shift(); // can be pop but it causes it to be less random
|
||||
}
|
||||
@@ -73,8 +70,7 @@ function update(elapsed) {
|
||||
}
|
||||
}
|
||||
|
||||
class TankmenBG
|
||||
{
|
||||
class TankmenBG {
|
||||
var strumTime = 0;
|
||||
var goingRight = false;
|
||||
var tankSpeed = 0.7;
|
||||
@@ -82,11 +78,9 @@ class TankmenBG
|
||||
var endingOffset = null;
|
||||
var sprite = null;
|
||||
|
||||
var self = null;
|
||||
var killed = false;
|
||||
|
||||
var fuckingnewfuckingnew = function()
|
||||
{
|
||||
function new() {
|
||||
this.sprite = new FlxSprite();
|
||||
var sprite = this.sprite;
|
||||
|
||||
@@ -102,8 +96,7 @@ class TankmenBG
|
||||
sprite.updateHitbox();
|
||||
}
|
||||
|
||||
var resetShit = function(x, y, isGoingRight)
|
||||
{
|
||||
function resetShit(x, y, isGoingRight) {
|
||||
var sprite = this.sprite;
|
||||
sprite.revive();
|
||||
sprite.setPosition(x, y);
|
||||
@@ -120,8 +113,7 @@ class TankmenBG
|
||||
sprite.flipX = goingRight;
|
||||
}
|
||||
|
||||
var update = function(elapsed)
|
||||
{
|
||||
function update(elapsed) {
|
||||
var sprite = this.sprite;
|
||||
sprite.visible = !(sprite.x >= FlxG.width * 1.5 || sprite.x <= FlxG.width * -0.5);
|
||||
|
||||
@@ -143,8 +135,8 @@ class TankmenBG
|
||||
killed = true;
|
||||
grpTankmanRun.remove(sprite, true);
|
||||
sprite.kill();
|
||||
tankmanPool.push(self);
|
||||
tankmanRun.remove(self);
|
||||
tankmanPool.push(this);
|
||||
tankmanRun.remove(this);
|
||||
}
|
||||
|
||||
if (goingRight)
|
||||
|
||||
Reference in New Issue
Block a user