Created
May 15, 2012 17:41
-
-
Save brunokruse/2703602 to your computer and use it in GitHub Desktop.
Reverse Light Geometry Shader
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
/*********************************************** | |
Geometry shader to convert lines into triangle strips | |
Memo Akten | |
www.memo.tv | |
modified by: STEADY | |
************************************************/ | |
#version 120 | |
#extension GL_EXT_geometry_shader4 : enable | |
uniform float thickness; | |
uniform vec3 lightDir; | |
uniform vec4 currentColor; | |
//uniform vec4 brighten = vec4(1.0,1.0,1.0, 0.9); | |
void main() { | |
vec3 p0 = gl_PositionIn[0].xyz; | |
vec3 p1 = gl_PositionIn[1].xyz; | |
vec3 up = vec3(0, 0, 1); // arbitrary up vector | |
vec4 brighten = vec4(1.0,1.0,1.0, 0.8); | |
vec3 dir = normalize(p1 - p0); // normalized direction vector from p0 to p1 | |
vec3 right = normalize(cross(dir, up)); // right vector | |
vec3 norm = cross(right, dir); | |
float fColMult = abs(dot(norm, lightDir)); | |
vec4 colMult = vec4(fColMult, fColMult, fColMult, 1.0); | |
right *= thickness; | |
gl_Position = gl_ModelViewProjectionMatrix * vec4(p0 - right*1.0, 1.0); | |
//gl_FrontColor = gl_FrontColorIn[0] * colMult; | |
gl_FrontColor = currentColor; | |
EmitVertex(); | |
gl_Position = gl_ModelViewProjectionMatrix * vec4(p0 + right*1.0, 1.0); | |
//gl_FrontColor = gl_FrontColorIn[0] * colMult; | |
gl_FrontColor = currentColor; | |
EmitVertex(); | |
gl_Position = gl_ModelViewProjectionMatrix * vec4(p1 - right*3.0, 1.0); | |
//gl_FrontColor = gl_FrontColorIn[1] * colMult; | |
gl_FrontColor = brighten; | |
EmitVertex(); | |
gl_Position = gl_ModelViewProjectionMatrix * vec4(p1 + right*3.0, 1.0); | |
//gl_FrontColor = gl_FrontColorIn[1] * colMult; | |
gl_FrontColor = brighten; | |
EmitVertex(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment