Skip to content

Instantly share code, notes, and snippets.

View spite's full-sized avatar
📦
i'm a smaller box

Jaume Sanchez spite

📦
i'm a smaller box
View GitHub Profile
@spite
spite / gist:f6c9addcfce71a0bb688
Created May 5, 2015 00:22
Private THREE objects
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
<script>
var scene = new THREE.Scene();
function Private() {
var scene = new THREE.Scene();
function render() {}
@spite
spite / gist:a5d4388c01ba59cc879a
Created June 16, 2015 00:05
ShaderToy wrapper
// VERTEX SHADER
attribute vec2 pos;
void main() {
gl_Position = vec4(pos.xy,0.0,1.0);
}
// FRAGMENT SHADER
#ifdef GL_ES
@spite
spite / gist:7ae92212b4f28076ba29
Last active August 29, 2015 14:23
A Modest Proposal: Standard for naming shaders and programs

##A Modest Proposal##

As per version 1.0.13 of the Shader Editor Extension, it will look for #define SHADERNAME name in both the vertex shader code and the fragment shader code.

If name is defined for both shaders, and it's the same string, the name of the program is that string, e.g.: "Shadertoy". common-name

If only one of the two is defined, the name of the program is "vs_name / fs_name", e.g.: "Quad / Shadertoy" mixed-name

@spite
spite / gist:0b84c9a0310d91e0bd89
Created November 30, 2015 14:08
Keep camera between reloads
// save camera views
const savedCamera = JSON.parse( localStorage.getItem( 'savedCamera' ) );
if( savedCamera ){
camera.position.copy( savedCamera.cameraPosition );
controls.target.copy( savedCamera.targetPosition );
}
document.addEventListener( 'unload', function(){
localStorage.savedCamera = JSON.stringify({
cameraPosition: camera.position,
@spite
spite / gist:8506285
Created January 19, 2014 15:23
Going Fullscreen
var c = document.body;
document.getElementById( 'fullscreenBtn' ).addEventListener( 'click', function( e ) {
c.onwebkitfullscreenchange = function(e) {
c.onwebkitfullscreenchange = function() {
};
};
c.onmozfullscreenchange = function(e) {
c.onmozfullscreenchange = function() {
};
};
@spite
spite / gist:58dd1f12e97fedcdc222
Created March 29, 2016 15:32
updating htc vive
- panel says one station needs to update, doesn't tell which one
- i unscrew both, try one, doesn't update. try the other one, it updates
- try the second one -which didn't update before- and it updates
- screw them again
- tells me to set up the room, i do that
- tells me a controller needs update, doesn't tell me which
- try one, it doesn't update, try the other one, it updates
- tells me to set up the room again, i do it and tells me the other controller needs update
- i plug the other controller, it updates
- after all this, with exactly the same setup, it tells me some station has visibility problems, tracking is now spotty
function hashRenderParams() {
var hash;
// hash your render values
//e.g, camera parameters: camera.position.x + '|' + camera.position.y + '|' + camera.position.z
return hash;
}
var hash = '';
// if an invalidate mechanism is in place
// easings based on expressions might have
// a bit of zeno's paradox, in which the
// value infinitesimally converges to the
// target value
var value = 0;
var nValue = 1;
function animate() {
@spite
spite / gist:00b3f17734810168093eb92a12815df3
Created May 13, 2016 14:16
Standard UV map (equirectangular 2:1) to mercator (1:1)
var geometry = new THREE.IcosahedronGeometry( 2, 5 );
for ( var i = 0, l = geometry.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
for ( var j = 0, jl = geometry.faceVertexUvs[ 0 ][ i ].length; j < jl; j ++ ) {
var uv = geometry.faceVertexUvs[ 0 ][ i ][ j ];
var a = uv.y * Math.PI - Math.PI / 2;
a = Math.sin(a);
var canvas = document.createElement( 'canvas' );
!! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );