Skip to content

Instantly share code, notes, and snippets.

@danzeeeman
Created April 22, 2014 20:32
Show Gist options
  • Save danzeeeman/11193283 to your computer and use it in GitHub Desktop.
Save danzeeeman/11193283 to your computer and use it in GitHub Desktop.
sphere dots shader
#version 120
#define PI (3.1415926536)
#define TWO_PI (6.2831853072)
uniform sampler2DRect bumpmap;
uniform float elapsedTime;
varying vec2 TexCoord;
varying vec3 normal;
varying vec3 pos;
void main(void) {
vec4 color = texture2DRect(bumpmap, TexCoord);
float t = mod(elapsedTime/160, 80.)+5.;
float d = mod(dot(pos, normal)*1., t) / t;
float a = sin(d * TWO_PI) * 0.5+0.5;
if (a > 0.5){
gl_FragColor = vec4(color.xyz, 1);
}
else{
// d = mod(pos.y*1.0, t) / t;
// a = sin(d * TWO_PI) * 0.5 + 0.5;
// if (a > 0.5){
// gl_FragColor = vec4(color.xyz, 1);
// }
// else{
// d = mod(pos.z*1.0, t) / t;
// a = sin(d * TWO_PI) * 0.5 + 0.5;
// if (a > 0.5){
// gl_FragColor = vec4(color.xyz, 1);
// }
// else{
gl_FragColor = vec4(0,0,0, 1);
}
// }
// }
}
#version 120
uniform sampler2DRect bumpmap;
varying vec2 TexCoord;
varying vec3 normal;
varying vec3 pos;
void main(void) {
// get the texture coordinates
TexCoord = gl_MultiTexCoord0.xy;
normal = gl_Normal;
// get the position of the vertex relative to the modelViewProjectionMatrix
vec4 position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 modifiedPosition = position;
pos = gl_Vertex.xyz;
// we need to scale up the values we get from the texture
// here we get the red channel value from the texture
// to use it as vertical displacement
vec4 c = texture2DRect(bumpmap, TexCoord);
float df = (c.x + c.y + c.z);
float scale = 125;//*sin(df);
modifiedPosition.xyz+=normal*df*scale;
//modifiedPosition.z+=normal.z*df*scale;
// this is the resulting vertex position
gl_Position = modifiedPosition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment