Skip to content

Instantly share code, notes, and snippets.

View supahfunk's full-sized avatar

Supah supahfunk

View GitHub Profile
@supahfunk
supahfunk / background.js
Created June 22, 2021 14:56
GLSL Background size cover - R3F
const Background = () => {
const { viewport } = useThree()
const scale = useMemo(() => ((40 + 15) / viewport.distance), [viewport])
const [bgTexture] = useTexture(['./bg.png'])
const shaderArgs = useMemo(() => ({
uniforms: {
uTexture: { value: bgTexture },
uResolution: { value: { x: viewport.width, y: viewport.height } },
uImageRegsolution: { value: { x: bgTexture.image.width, y: bgTexture.image.height } },
@supahfunk
supahfunk / shaderMaterial.js
Created June 3, 2021 13:29
ShaderMaterial
const vertexShader = /* glsl */`
uniform float uTime;
varying vec3 vPos;
varying vec2 vUv;
#define PI 3.14159265
void main() {
vec3 pos = position;
vPos = pos;
vUv = uv;
export const mapRange = (num, inMin, inMax, outMin, outMax) => {
return (num - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
}
export const newMapRange = (value, rangeA, rangeB, limit) => {
if (limit == null) {
limit = false; // eslint-disable-line
}
const [fromLow, fromHigh] = Array.from(rangeA)
const [toLow, toHigh] = Array.from(rangeB)
vec3 rotateAxis(vec3 p, vec3 axis, float angle) {
return mix(dot(axis, p)*axis, p, cos(angle)) + cross(axis,p)*sin(angle);
}
// pos = rotateAxis(pos, vec3(1., 0., 0.), PI * .5); // => Rotate X Axis 180deg
:root {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
@supahfunk
supahfunk / OrbitControls.js
Created June 18, 2020 08:24
OrbitControls
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
@supahfunk
supahfunk / cloudSettings
Last active April 16, 2021 19:22
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-04-16T19:22:17.345Z","extensionVersion":"v3.4.3"}
vec2 rotate(vec2 v, float a) {
float s = sin(a);
float c = cos(a);
mat2 m = mat2(c, -s, s, c);
return m * v;
}
@supahfunk
supahfunk / bezier.glsl
Created January 14, 2020 17:46 — 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);
vec3 align(vec3 pos, vec3 dir) {
vec3 initDir = vec3(1.0, 0.0, 0.0);
vec3 axis = cross(dir, initDir);
float angle = acos(dot(dir, initDir));
return rotate(pos, axis, angle);
}