Created
December 4, 2012 22:32
-
-
Save typpo/4209605 to your computer and use it in GitHub Desktop.
original glsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is autogenerated by Three.js: | |
precision highp float; | |
#define VERTEX_TEXTURES | |
#define MAX_DIR_LIGHTS 0 | |
#define MAX_POINT_LIGHTS 0 | |
#define MAX_SPOT_LIGHTS 0 | |
#define MAX_HEMI_LIGHTS 0 | |
#define MAX_SHADOWS 0 | |
#define MAX_BONES 58 | |
#define SHADOWMAP_SOFT | |
uniform mat4 modelMatrix; | |
uniform mat4 modelViewMatrix; | |
uniform mat4 projectionMatrix; | |
uniform mat4 viewMatrix; | |
uniform mat3 normalMatrix; | |
uniform vec3 cameraPosition; | |
attribute vec3 position; | |
attribute vec3 normal; | |
attribute vec2 uv; | |
attribute vec2 uv2; | |
#ifdef USE_COLOR | |
attribute vec3 color; | |
#endif | |
#ifdef USE_MORPHTARGETS | |
attribute vec3 morphTarget0; | |
attribute vec3 morphTarget1; | |
attribute vec3 morphTarget2; | |
attribute vec3 morphTarget3; | |
#ifdef USE_MORPHNORMALS | |
attribute vec3 morphNormal0; | |
attribute vec3 morphNormal1; | |
attribute vec3 morphNormal2; | |
attribute vec3 morphNormal3; | |
#else | |
attribute vec3 morphTarget4; | |
attribute vec3 morphTarget5; | |
attribute vec3 morphTarget6; | |
attribute vec3 morphTarget7; | |
#endif | |
#endif | |
#ifdef USE_SKINNING | |
attribute vec4 skinIndex; | |
attribute vec4 skinWeight; | |
#endif | |
// ---------------------------------- | |
// This is my code: | |
#define pi 3.141592653589793238462643383279 | |
uniform float earth_i; | |
uniform float earth_om; | |
uniform float jed; | |
attribute float size; | |
attribute float a; | |
attribute float e; | |
attribute float i; | |
attribute float o; | |
attribute float P; | |
attribute float ma; | |
attribute float n; | |
attribute float w; | |
attribute float epoch; | |
attribute float locked; | |
varying float vLocked; | |
attribute vec3 value_color; | |
varying vec3 vColor; | |
vec3 getAstroPos() { | |
float i_rad = (i - earth_i) * pi/180.0; | |
float o_rad = (o - earth_om) * pi/180.0; // longitude of ascending node | |
float p_rad = w * pi/180.0; // longitude of perihelion | |
float ma_rad = ma * pi/180.0; | |
float n_rad; | |
if (n > -1.0) | |
n_rad = n * pi/180.0; // mean motion | |
else { | |
n_rad = 2.0 * pi / P; | |
} | |
float d = epoch - jed; | |
float M = ma_rad + n_rad * -d; | |
// Estimate eccentric and true anom using iterative approx | |
float E0 = M; | |
float lastdiff; | |
// converted do/while: | |
float E1 = M + e * sin(E0); | |
lastdiff = abs(E1-E0); | |
E0 = E1; | |
for (int foo=0; foo < 6; foo++) { | |
float E1 = M + e * sin(E0); | |
lastdiff = abs(E1-E0); | |
E0 = E1; | |
if (lastdiff > 0.0000001) { | |
break; | |
} | |
} | |
float E = E0; | |
float v = 2.0 * atan(sqrt((1.0+e)/(1.0-e)) * tan(E/2.0)); | |
// radius vector, in AU | |
float r = a * (1.0 - e*e) / (1.0 + e * cos(v)) * 50.0; | |
// heliocentric coords | |
float X = r * (cos(o_rad) * cos(v + p_rad - o_rad) - sin(o_rad) * sin(v + p_rad - o_rad) * cos(i_rad)); | |
float Y = r * (sin(o_rad) * cos(v + p_rad - o_rad) + cos(o_rad) * sin(v + p_rad - o_rad) * cos(i_rad)); | |
float Z = r * (sin(v + p_rad - o_rad) * sin(i_rad)); | |
return vec3(X, Y, Z); | |
} | |
void main() { | |
vColor = value_color; | |
vLocked = locked; | |
vec3 newpos = getAstroPos(); | |
vec4 mvPosition = modelViewMatrix * vec4(newpos, 1.0); | |
gl_Position = projectionMatrix * mvPosition; | |
gl_PointSize = size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment