Created
April 3, 2010 20:26
-
-
Save notlion/354831 to your computer and use it in GitHub Desktop.
View Space Tri Strips Shader
This file contains 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
void Arc::draw(ofxShader& shader) | |
{ | |
GLuint pr_loc = glGetAttribLocationARB(shader.shader, "a_vtx_pr"); | |
GLuint nx_loc = glGetAttribLocationARB(shader.shader, "a_vtx_nx"); | |
glColor4f(color.x, color.y, color.z, 1); | |
glBegin(GL_TRIANGLE_STRIP); | |
ofxVec3f vtx_pr, vtx, vtx_nx; | |
vtx_nx.set(p1); | |
for(int i = 1; i < n_steps; i++){ | |
float u = i / (n_steps - 1.0f); | |
float t = u * t_pos; | |
float th = thickness * ofLerp(0.5f, 1.0f, u); | |
vtx_pr.set(vtx); | |
vtx.set(vtx_nx); | |
vtx_nx.set( | |
Utilz::bezierPoint(p1.x, p2.x, p3.x, p4.x, t), | |
Utilz::bezierPoint(p1.y, p2.y, p3.y, p4.y, t), | |
Utilz::bezierPoint(p1.z, p2.z, p3.z, p4.z, t) | |
); | |
glVertexAttrib4fARB(pr_loc, vtx_pr.x, vtx_pr.y, vtx_pr.z, 1.0f); | |
glVertexAttrib4fARB(nx_loc, vtx_nx.x, vtx_nx.y, vtx_nx.z, 1.0f); | |
glTexCoord3f(t * -tex_reps, 0.0f, -th); | |
glVertex3f(vtx.x, vtx.y, vtx.z); | |
glVertexAttrib4fARB(pr_loc, vtx_pr.x, vtx_pr.y, vtx_pr.z, 1.0f); | |
glVertexAttrib4fARB(nx_loc, vtx_nx.x, vtx_nx.y, vtx_nx.z, 1.0f); | |
glTexCoord3f(t * -tex_reps, 1.0f, th); | |
glVertex3f(vtx.x, vtx.y, vtx.z); | |
} | |
glEnd(); | |
} |
This file contains 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
varying vec3 uv; | |
void main() | |
{ | |
gl_FragColor = gl_Color; | |
} |
This file contains 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
attribute vec4 a_vtx_pr, a_vtx_nx; | |
varying vec3 uv; | |
void main() | |
{ | |
// Project | |
vec4 vtx = gl_ModelViewProjectionMatrix * gl_Vertex; | |
vec4 vtx_pr = gl_ModelViewProjectionMatrix * a_vtx_pr; | |
vec4 vtx_nx = gl_ModelViewProjectionMatrix * a_vtx_nx; | |
// Get 2D Coords | |
vec2 vtx2d = vtx.xy / vtx.w; | |
vec2 vtx_pr2d = vtx_pr.xy / vtx_pr.w; | |
vec2 vtx_nx2d = vtx_nx.xy / vtx_nx.w; | |
vec2 norm2d = normalize( | |
vec2(-(vtx2d.y - vtx_pr2d.y), vtx2d.x - vtx_pr2d.x) + | |
vec2(-(vtx_nx2d.y - vtx2d.y), vtx_nx2d.x - vtx2d.x) | |
); | |
uv = gl_MultiTexCoord0.xyz; | |
gl_Position = vtx + vec4(norm2d * uv.z, 0.0, 0.0); | |
gl_FrontColor = gl_Color; | |
gl_BackColor = gl_Color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment