Skip to content

Instantly share code, notes, and snippets.

View marioecg's full-sized avatar

Mario Carrillo marioecg

View GitHub Profile
@marioecg
marioecg / lerp.js
Created January 8, 2020 03:59
Linear interpolation (lerp or mix)
function lerp(start, end, t) {
return start * (1 - t) + end * t;
}
@marioecg
marioecg / scene.js
Created January 8, 2020 04:20
Basic set up for a three.js scene
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
let camera, scene, renderer;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
@marioecg
marioecg / fragment.glsl
Last active April 2, 2020 00:05
default threejs shaders
precision mediump float;
varying vec2 vUv;
void main() {
gl_Position = vec4(vUv, 0., 1.);
}
vec3 palette(in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d) {
return a + b * cos(6.28318 * (c * t + d));
}
const int AMOUNT = 25;
void main () {
float TIME = uTime * 1.0;
vec2 uv = scale * (gl_FragCoord.xy - .5 * uResolution.xy) / uResolution.y;
// uv *= rotate(uv, angle1);
uv.x *= 0.85;
uv.y += 10.;
@marioecg
marioecg / backgroundCoverUv.glsl
Last active January 20, 2021 02:26
Make texture image in a plane behave like background cover in CSS
vec2 backgroundCoverUv(vec2 screenSize, vec2 imageSize, vec2 uv) {
float screenRatio = screenSize.x / screenSize.y;
float imageRatio = imageSize.x / imageSize.y;
vec2 newSize = screenRatio < imageRatio
? vec2(imageSize.x * screenSize.y / imageSize.y, screenSize.y)
: vec2(screenSize.x, imageSize.y * screenSize.x / imageSize.x);
vec2 newOffset = (screenRatio < imageRatio
? vec2((newSize.x - screenSize.x) / 2.0, 0.0)
@marioecg
marioecg / collection.glsl
Last active December 14, 2021 01:48
Collection of GLSL code throughout my learning journey
#define PI 3.1415926538
#define TWO_PI 6.28318530718
vec2 scaleFromCenter = (uv - 0.5) + 0.5;
mat2 scale(vec2 scale){
return mat2(scale.x, 0.0,
0.0, scale.y);
}
mat2 rotation2d(float angle) {
float s = sin(angle);
float c = cos(angle);
return mat2(
c, -s,
s, c
);
}
@marioecg
marioecg / Renderer.js
Created February 27, 2021 00:48
OGL class renderer setup
import { Renderer, Camera, Transform, Orbit } from 'ogl';
import store from '../store';
import { Events } from '../events';
import * as dat from 'dat.gui';
export default new class {
constructor() {
this.renderer = new Renderer({
@marioecg
marioecg / scene.js
Created March 1, 2021 00:19
Threejs renderer setup
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { Events } from '../events';
import store from '../store';
export default new class {
constructor() {
this.renderer = new THREE.WebGLRenderer({
antialias: true,