Skip to content

Instantly share code, notes, and snippets.

@floz
floz / bezier.glsl
Created September 27, 2021 14: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);
@floz
floz / levels.glsl
Created January 12, 2021 08:26 — forked from activetheory/levels.glsl
A GLSL module for color levels manipulation
float levelChannel(float inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
return (pow(((inPixel * 255.0) - inBlack) / (inWhite - inBlack), inGamma) * (outWhite - outBlack) + outBlack) / 255.0;
}
vec3 levels(vec3 inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
vec3 o = vec3(1.0);
o.r = levelChannel(inPixel.r, inBlack, inGamma, inWhite, outBlack, outWhite);
o.g = levelChannel(inPixel.g, inBlack, inGamma, inWhite, outBlack, outWhite);
o.b = levelChannel(inPixel.b, inBlack, inGamma, inWhite, outBlack, outWhite);
return o;
@floz
floz / rotate-uv.glsl
Created January 12, 2021 08:26 — forked from ayamflow/rotate-uv.glsl
Rotate UV in GLSL
vec2 rotateUV(vec2 uv, float rotation)
{
float mid = 0.5;
return vec2(
cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,
cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid
);
}
vec2 rotateUV(vec2 uv, float rotation, vec2 mid)
@floz
floz / gpu-infos.js
Created January 12, 2021 08:25 — forked from ayamflow/gpu-infos.js
GPU infos
// https://stackoverflow.com/questions/31775686/is-there-a-way-to-know-anything-about-hardware-resources-of-platform-accessing/31896597#31896597
// https://stackoverflow.com/questions/15464896/get-cpu-gpu-memory-information
var canvas = document.createElement('canvas')
var gl = canvas.getContext('experimental-webgl');
var params = [gl.RENDERER, gl.VENDOR, gl.VERSION, gl.SHADING_LANGUAGE_VERSION];
var infos = gl.getExtension('WEBGL_debug_renderer_info');
params.push(infos.UNMASKED_RENDERER_WEBGL, infos.UNMASKED_VENDOR_WEBGL);
params.forEach(function(param) {
function screenToWorldAtZ(positionX, positionY, z, camera){
var vector = new THREE.Vector3();
var dX, dY, dZ;
if(this.curObject && this.curObject.parent ){
dX = this.curObject.parent.position.x;
dY = this.curObject.parent.position.y;
dZ = this.curObject.parent.position.z;
}else{
dX = 0; dY = 0, dZ = 0;
function screenToWorldAtZ(positionX, positionY, z, camera){
var vector = new THREE.Vector3();
var dX, dY, dZ;
if(this.curObject && this.curObject.parent ){
dX = this.curObject.parent.position.x;
dY = this.curObject.parent.position.y;
dZ = this.curObject.parent.position.z;
}else{
dX = 0; dY = 0, dZ = 0;
@floz
floz / gist:fb2686aab868643e2f1174f9bac1969f
Created November 17, 2017 06:28
Workshop WebGL Advanced - GROW - Github emails link
https://docs.google.com/spreadsheets/d/1H7ITmzPHGjQl_RUrZjJu-uDq37s12YfN3_T8iYo7keU/edit?usp=sharing
@floz
floz / Mirrors.fs
Created July 19, 2017 08:31
Mirrors.fs
uniform sampler2D tInput;
uniform vec2 resolution;
varying vec2 vUv;
uniform float divide3;
uniform float divide4;
uniform float mirrorX;
uniform float mirrorY;
void main() {
@floz
floz / README.md
Created July 18, 2017 12:46
Color Picking Tool
@floz
floz / MeshCustomMaterial.js
Created July 17, 2017 14:02
MeshPhysicalMaterial custom
import vs from "shaders/physicalcustom.vs"
import fs from "shaders/physicalcustom.fs"
export default class MeshCustomMaterial extends THREE.MeshPhysicalMaterial {
constructor(parameters, uniforms={}){
super(parameters)
this.defines = { 'PHYSICAL': '' };