This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const app = new NOTHING.App('#divId'); | |
| async function createContext() { | |
| // 配置 offscreen 可以在不输出的情况下生成 ImageData 对象 | |
| return await app.getContext( | |
| 'postEffect', // or pe for short | |
| { | |
| offscreen: false | |
| } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef (HTMLImageElement or | |
| HTMLVideoElement or | |
| HTMLCanvasElement) CanvasImageSource; | |
| interface CanvasRenderingContext2D { | |
| // back-reference to the canvas | |
| readonly attribute HTMLCanvasElement canvas; | |
| // state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))); |