Skip to content

Instantly share code, notes, and snippets.

@merpnderp
merpnderp / rss.r
Last active August 29, 2015 14:20
Processes RSS Global Land and Sea data for least squares linear regression
# data set is for 1979.01 to 2015.05
data <- read.table("tlt.dat", sep="", skip=5)
data = subset(data, data[,1] >= 1995.12 & data[,3] > -98)
months <- data[,1] + data[,2]/100
anomolies <- data[,3]
@merpnderp
merpnderp / gulpfile.js
Created March 19, 2015 15:12
Gulpfile example
// Load some modules which are installed through NPM.
var gulp = require('gulp');
var browserify = require('browserify'); // Bundles JS.
var del = require('del'); // Deletes files.
var brfs = require('brfs');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
// Define some paths.
var paths = {
worker: ['./app/mainRouter.js'],
@merpnderp
merpnderp / gist:8656124
Created January 27, 2014 20:00
New QuadBuilder for working with BuggerGeometry
QuadBuilder.prototype = {
BuildQuadForGrid: function () {
var baseIndex, index0, index1, index2, index3, n = new THREE.Vector3(0, 0, 1);
return function (positions, position, uv, buildTriangles, vertsPerRow, swapOrder) {
positions.push(position.x);
positions.push(position.y);
@merpnderp
merpnderp / planet.shader
Created January 15, 2014 16:28
Planet Shader
Shader "Custom/PlanetShader" {
Properties {
Position ("Position", Vector) = (0,0,0,0)
WidthDir ("WidthDir", Vector) = (1,0,0,0)
HeightDir ("HeightDir", Vector) = (0,1,0,0)
Width ("Width", Float) = 1
Radius ("Radius", Float) = 1
c ("debug", Float) = 1
}
SubShader {
@merpnderp
merpnderp / MeshSplitter.cs
Created September 10, 2013 15:57
Tenebrous MeshSplitter
List<Vector3> oldVerts = blah;
List<int> oldTris = blah;
Dictionary<int,int> vertMap;
List<Vector3> newVerts;
List<int> newTris;
public void Process()
{
vertMap = new Dictionary<int,int>();
@merpnderp
merpnderp / MeshSplitter.cs
Last active December 22, 2015 18:09
Kruncher MeshSplitter
public class MeshSplitter {
// Maps old vertex indices to new ones.
private Dictionary<int, int> _map = new Dictionary<int, int>();
// Input mesh data.
int[] _triangles;
Vector3[] _verts;
Vector2[] _uvs;
@merpnderp
merpnderp / gist:6234948
Last active December 21, 2015 02:28
Heightmap to clipmap mapping

Heightmaps are 2D rectangles representing the topography of a sphere. Spherical clipmaps are 2D rings projected onto a sphere as a partial sphere cap.

Heightmaps are defined by:

  • Have a height (H) and width (W) with x,y coordinates centered at 0,0 at H/2, W/2.
  • Cover some percentage of the circumference of the sphere (scaledPI)
  • Points (x,y) on the heightmap map to a phi, theta (polar coordinates)
  • The heightmap is centered on the sphere at phi,theta (polar coordinates)
  • For a point in the heightmap, y maps to T(y) and x manps to P(x)
  • T(y) = ( y / ( H / 2 ) * scaledPI ) + theta
@merpnderp
merpnderp / Scale a set into the middle of itself
Last active December 20, 2015 14:49
Why it takes so long to write games. I spent two hours yesterday morning just rediscovering how to scale a set of numbers into the middle of itself.
/*Suppose your linear function is
f(x) = ax + b.
Then f(0.1) = 0.25,
and f(1) = 0.75.
a * 0.1 + b = 0.25,
a * 1 + b = 0.75,
so b = 0.75 - a.
a * 0.1 + (0.75 - a) = 0.25, so a = 5 / 9, (-.9a = -.5)
@merpnderp
merpnderp / gist:5060297
Last active December 14, 2015 08:49
How to project spherical clipmaps onto a sphere and apply texture heightmaps.
  • Based on the distance between the camera and planet determine how many clipmaps will be created and at what detail level.

  • Get camera vector in planet's local space.

  • Find point planet where the line between the camera and planet's center intersects its surface.

  • Convert that point into phi and theta.

  • Based on phi and theta generate metatextures for each clipmap level.

  • The top level clipmap will simply be the coarsest texture, with a x axis twice as wide as the y. The x axis will be mapped from -PI to PI with 0 at the prime meridian. The y axis will be mapped from 0 to PI with 0 at the N. Pole.

@merpnderp
merpnderp / Swizzle.cs
Created December 28, 2012 19:38
Move a point to/from the front face of a cube to/from another face.
private Vector3 getTransformedPoint (Vector3 point, bool _inverse)
{
float inverse = _inverse ? -1f : 1f;
float x;
float y;
/*
-20, 1 -60 // front point
20, 1, 60 // back point
60, 1, -20 // right point