Skip to content

Instantly share code, notes, and snippets.

View zhoyq's full-sized avatar
🏠
Working at home

衷于栖 zhoyq

🏠
Working at home
View GitHub Profile
@zhoyq
zhoyq / sample01.js
Created April 25, 2021 08:54
POST EFFECT API PUBLIC
const app = new NOTHING.App('#divId');
async function createContext() {
// 配置 offscreen 可以在不输出的情况下生成 ImageData 对象
return await app.getContext(
'postEffect', // or pe for short
{
offscreen: false
}
);
@zhoyq
zhoyq / bezier.glsl
Created April 22, 2021 09:55 — forked from yiwenl/bezier.glsl
Bezier curve in GLSL
// bezier curve with 2 control points
// A is the starting point, B, C are the control points, D is the destination
// t from 0 ~ 1
vec3 bezier(vec3 A, vec3 B, vec3 C, vec3 D, float t) {
vec3 E = mix(A, B, t);
vec3 F = mix(B, C, t);
vec3 G = mix(C, D, t);
vec3 H = mix(E, F, t);
vec3 I = mix(F, G, t);
@zhoyq
zhoyq / cavas2d.idl
Created April 22, 2021 08:56
canvas 2d idl
typedef (HTMLImageElement or
HTMLVideoElement or
HTMLCanvasElement) CanvasImageSource;
interface CanvasRenderingContext2D {
// back-reference to the canvas
readonly attribute HTMLCanvasElement canvas;
// state
@zhoyq
zhoyq / background.glsl
Last active April 22, 2021 07:23
sketchfab background
float inputRatio = u_TextureInputWidth / u_TextureInputHeight;
float revInputRatio = 1.0 / inputRatio;
float screenRatio = u_Width / u_Height;
float revScreenRatio = 1.0 / screenRatio;
vec2 crood = vec2(gl_FragCoord.x, u_Height - gl_FragCoord.y) / vec2(u_Width, u_Height);
if (screenRatio > inputRatio) {
float y = ((revInputRatio - revScreenRatio) / 2.0 + revScreenRatio * crood.y) / revInputRatio;
color = vec3(texture2D(u_BackgroundImageSampler, vec2(crood.x, y)));