Skip to content

Instantly share code, notes, and snippets.

View dghez's full-sized avatar
🌝

Robert dghez

🌝
View GitHub Profile
@dghez
dghez / TruchetTiling.glsl
Created November 13, 2023 23:56 — forked from Forenard/TruchetTiling.glsl
TruchetTiling.glsl
#version 300 es
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
out vec4 outColor;
@dghez
dghez / .eslintrc
Created February 20, 2023 15:28
Next eslint
{
"env": {
"browser": true,
"node": true,
},
"parserOptions": {
"ecmaVersion": 2020
},
"extends": [
"airbnb",
@dghez
dghez / index.js
Created January 11, 2023 16:17
Sync useFrame with gsap ticker
import React, { useEffect } from 'react'
import gsap from 'gsap'
import { useFrame } from '@react-three/fiber'
// sync gsap raf to r3f raf
gsap.ticker.remove(gsap.updateRoot)
export const GsapTicker = () => {
const pg = React.useRef(0)
gsap.ticker.remove(gsap.updateRoot)
@dghez
dghez / fullscreen-quad-threejs.js
Created October 7, 2022 21:27
Fullscreen quad on threejs
this.geometry = new BufferGeometry()
const vertices = new Float32Array([
-1.0, -1.0,
3.0, -1.0,
-1.0, 3.0,
])
const uvs = new Float32Array([0, 0, 2, 0, 0, 2])
this.geometry.setAttribute('uv', new BufferAttribute(uvs, 2))
@dghez
dghez / extendMaterial.js
Last active May 13, 2022 22:46
Extend material threejs
// inspired by https://github.com/jamieowen/three-material-modifier
// Kudos jam3
// typescript, need to convert to js soon
import { UniformsUtils, IUniform } from 'three';
export type Shader = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
uniforms: { [uniform: string]: IUniform<any> };
vertexShader: string;
@dghez
dghez / BoxProjectedEnvMapHelper.js
Created April 5, 2022 10:33 — forked from 0beqz/BoxProjectedEnvMapHelper.js
Updated code to box-project env-maps in three.js (r137) - credits go to codercat (https://codercat.tk) for the box-projecting code
import * as THREE from "three"
// credits for the box-projecting shader code go to codercat (https://codercat.tk)
const worldposReplace = /* glsl */`
#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
#ifdef BOX_PROJECTED_ENV_MAP
vWorldPosition = worldPosition.xyz;
@dghez
dghez / checkPerf
Last active January 18, 2022 14:25
A little function that performs a CPU performance check, based on a similar piece of code orriginally made by Baptise Briel
checkPerf() {
// performance test based on cpu performance
// higher score means worse performance
// based on Baptiste Briel's work: http://awams.bbriel.me/27
// Copied from: https://gist.github.com/martinlaxenaire/27cf27f043ec5ce423ce165e283fc19a
let perf = 0;
const start = (performance || Date).now();
let array = [];
for(let i = 0; i < 20000; i++) {
@dghez
dghez / GSLS_Emulate background-fit:cover
Last active January 7, 2024 13:16
Emulate the cover css property in a shader
// An implementation of CSS `background-size: cover`
// using http://stackoverflow.com/a/6565988
vec2 s = uScreenSize; // Screen
vec2 i = uBGSize; // Image
float rs = s.x / s.y;
float ri = i.x / i.y;
vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);
vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;
vec2 uv = vTexCoord * s / new + offset;
gl_FragColor = texture2D(uBGTex, uv);
@dghez
dghez / MISC - Random values from interval
Last active March 27, 2019 16:02
Return random values, float or int
import RN from 'random-number';
let rand = RN.generator();
let randInt = (min, max) => {
return rand(min, max, true);
};
let randFloat = (min, max) => {
return rand(min, max, false);
@dghez
dghez / GLSL-Rotate on axis
Created March 26, 2019 23:39
Rotate on a specific axe
mat4 rotationMatrix(vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);