Skip to content
/ twigl Public

twigl.app is an online editor for One tweet shader, with gif generator and sound shader, and broadcast live coding.

License

Notifications You must be signed in to change notification settings

doxas/twigl

Repository files navigation

twigl

twigl.app is an online editor for One tweet shader, with gif(or webm, jpeg, png) generator and sound shader, and broadcast live coding.

get started

$ npm install
$ npm start

screen shot

Example:

precisionhighpfloat;
uniformfloattime;
voidmain(){vec4p=vec4((gl_FragCoord.xy/4e2),0,-4);for(inti=0;i<9;++i)p+=vec4(sin(-(p.x+time*.2))+atan(p.y*p.w),cos(-p.x)+atan(p.z*p.w),cos(-(p.x+sin(time*.8)))+atan(p.z*p.w),0);gl_FragColor=p;}

Live:DEMO

regulation

There are four modes in twigl.app, each of which has a sub-mode that uses GLSL ES 3.0, or in addition to it, a mode that enables MRT.

classic:

This mode is compatible with GLSLSandbox.

The uniform variables are "resolution", "mouse", "time", "frame", and "backbuffer".

geek:

In this mode, the various uniform variables are in a single-character style.

"r", "m", "t", "f", and "b", respectively.

geeker:

In this mode, there is no need to declare precision and uniform. They are automatically complemented on the implementation side. Otherwise, it is the same as in geek mode.

geekest:

In this mode, the description of "void main(){}" may be omitted (or not), and "gl_FragCoord" can be described as "FC". In addition, a variety of GLSL snippets are available.

The reason why we support the notation that does not omit the definition of the main function is to allow users to define their own functions.

For more information on snippets, please see below.

advanced

backbuffers

As a general rule, attempt to process in the highest precision texture format possible. Under ideal circumstances, a 32-bit floating-point format is used.

However, there may be cases where floating-point textures are not available, depending on the execution environment and whether or not extensions can be enabled. In such cases, textures generated in RGBA8(unsigned byte) format are used.

300 es

GLSL ES 3.0 is available for WebGL 2.0 enabled environments.

When using GLSL ES 3.0, useoutColorinstead ofgl_FragColorfor the final output in classic mode.

In the other geek, geeker, and geekest modes,outColoris shortened too.

MRT (Multiple Render Targets)

In classic mode,outColor0andoutColor1can be used to output to two channels simultaneously.

In non-classical mode, these are written aso0ando1.

The result of the previous frame can be referenced asbackbuffer0andbackbuffer1in classic mode. In other modes, they are written asb0andb1.

Input from the sound shader

The audio data generated by the sound shader can be received as a uniform variable in the shader for graphics.

In classic mode, this is a floating-point variable namedsound.In other modes, it is denoted ass.

GLSL snippets in GEEKEST mode

twigl with geekest mode have included simplex-noise, you can call it as follows.

floatf=snoise2D(v.xy);
floatg=snoise3D(v.xyz);
floath=snoise4D(v.xyzw);

If you are more concerned with speed than accuracy, the following functions may be more appropriate.

//fract sin noise
floatfsnoise(vec2c){
returnfract(sin(dot(c,vec2(12.9898,78.233)))*43758.5453);
}

//fsnoise for macOS
floatfsnoiseDigits(vec2c){
returnfract(sin(dot(c,vec2(0.129898,0.78233)))*437.585453);
}

//for example
floati=fsnoise(v.xy);
floatj=fsnoiseDigits(v.xy);

Other pre-defined constants and functions are as follows.

vec3hsv(floath,floats,floatv){
vec4t=vec4(1.0,2.0/3.0,1.0/3.0,3.0);
vec3p=abs(fract(vec3(h)+t.xyz)*6.0-vec3(t.w));
returnv*mix(vec3(t.x),clamp(p-vec3(t.x),0.0,1.0), s);
}

mat2rotate2D(floatr){
returnmat2(cos(r),sin(r),-sin(r),cos(r));
}

mat3rotate3D(floatangle,vec3axis){
vec3a=normalize(axis);
floats=sin(angle);
floatc=cos(angle);
floatr=1.0-c;
returnmat3(
a.x*a.x*r+c,
a.y*a.x*r+a.z*s,
a.z*a.x*r-a.y*s,
a.x*a.y*r-a.z*s,
a.y*a.y*r+c,
a.z*a.y*r+a.x*s,
a.x*a.z*r+a.y*s,
a.y*a.z*r-a.x*s,
a.z*a.z*r+c
);
}

constfloatPI=3.141592653589793;
constfloatPI2=PI*2.0;

Note that the above snippets are only available in GEEKEST mode.

keyboard shortcut

key action
Alt +Enter play sound
Ctrl + Alt +Enter stop sound
Ctrl + Alt +v vim mode
Ctrl + Alt +t change view
Ctrl + Alt +. up font size
Ctrl + Alt +, down font size

You can useCommandinsteadCtrlon the macOS.

credit

spite/ccapture.js: A library to capture canvas-based animations at a fixed framerate

jnordberg/gif.js: JavaScript GIF encoding library

Ace - The High Performance Code Editor for the Web

ashima/webgl-noise: Procedural Noise Shader Routines compatible with WebGL

Shadertoy BETA

interface design by@iY0Yi

license

MIT licensed.

About

twigl.app is an online editor for One tweet shader, with gif generator and sound shader, and broadcast live coding.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published