Skip to content

Instantly share code, notes, and snippets.

@ishikawash
ishikawash / gist:3249901
Created August 3, 2012 17:42
Rendering sin wave in GLSL
// vertex shader ----------------------------------
uniform float t;
uniform float freq;
uniform float amp;
varying vec3 normal;
varying vec2 uv;
void main()
@ishikawash
ishikawash / gist:3287209
Created August 7, 2012 16:46
bump mapping example ( calculating tangent vector by vertex shader )
// vertex shader
#version 120
uniform vec3 light_position; // in eye space
varying vec3 light_dir;
varying vec3 eye_dir;
varying vec2 uv;
vec3 calculate_tangent(vec3 n) {
@ishikawash
ishikawash / gist:4608718
Created January 23, 2013 16:05
Distance function : example program
#version 120
// === vertex shader
//
// When you use OpenGL Shader Builder to execute shader programs,
// * select plane as geometry
// * set resolution to 640x480
// * set scale_factor to 2.5
uniform vec2 resolution;
@ishikawash
ishikawash / gist:4648390
Created January 27, 2013 13:46
Distance function with texture mapping.
#version 120
// === vertex shader
//
// When you use OpenGL Shader Builder to execute shader programs,
// * select plane as geometry
// * set resolution to 640x480
// * set scale_factor to 2.5
uniform vec2 resolution;
@ishikawash
ishikawash / box.fs
Created December 19, 2013 12:22
Instanced rendering demo using openFrameworks.
#version 120
uniform vec3 light_direction;
varying vec3 vertex_normal;
varying vec3 vertex_color;
void main(void) {
vec3 N = normalize(vertex_normal);
vec3 L = normalize(light_direction);
@ishikawash
ishikawash / box.fs
Created January 5, 2014 05:36
Instanced rendering demo using openFrameworks Part 2. The shader program use vertex attributes instead of uniform variables.
#version 120
uniform vec3 light_direction;
varying vec3 vertex_normal;
varying vec3 vertex_color;
void main(void) {
vec3 N = normalize(vertex_normal);
vec3 L = normalize(light_direction);
@ishikawash
ishikawash / pin-hole.fs
Created January 7, 2014 16:18
Pin-Hole like effect
// fragment shader
uniform sampler2D tex;
uniform vec2 viewport;
uniform vec2 origin;
uniform float radius;
uniform float attenuation;
uniform vec3 background_color;
void main()
{
@ishikawash
ishikawash / fog.vs
Created March 30, 2014 15:15
Fog effect
#version 120
struct Fog {
float start;
float density;
vec3 color;
};
uniform Fog fog;
@ishikawash
ishikawash / demo.pde
Created July 14, 2014 15:37
Basic shader demo with Processing
PShader sh;
PShader f;
PShape square;
PGraphics canvas;
void setup() {
size(640, 480, P3D);
canvas = createGraphics(width, height, P3D);
@ishikawash
ishikawash / stripe.glsl
Created August 24, 2014 00:52
Stripe shader
#version 120
uniform float rows;
uniform float cols;
void main()
{
int x = int(floor(gl_TexCoord[0].x * cols));
int y = int(floor(gl_TexCoord[0].y * rows));
if (mod(x + y, 2) == 0) {