Graphics Reference
In-Depth Information
The hedgehog plot geometry shader is shown below. It takes triangles
as inputs and outputs line strips. As these are single line spikes, it would be
more efficient to output line segments, but these are not allowed as the output
from a geometry shader. For fun, a uDroop variable has been added so that this
shader can also do simple hair.
#version 330
#extension GL_EXT_geometry_shader4: enable
layout( triangles ) in;
layout( line_strip, max_vertices=1024 ) out;
uniform int uDetail;
uniform float uDroop;
uniform int uLength;
uniform float uStep;
in vec3 vNormal[3];
in vec4 vColor[3];
out vec4 gColor;
vec3 Norm[3];
vec3 N0, N01, N02;
vec4 V0, V01, V02;
void
ProduceVertices( float s, float t )
{
vec4 v = V0 + s*V01 + t*V02;
vec3 n = normalize( N0 + s*N01 + t*N02 );
for( int i = 0; i <= Length; i++ )
{
gl_Position = uProjectionMatrix * v;
gColor = vColor[0];
EmitVertex( );
v.xyz += Step * n;
v.y -= uDroop * float(i*i);
}
EndPrimitive( );
}
void main( )
{
V0 = gl_PositionIn[0];
V01 = ( gl_PositionIn[1] - gl_PositionIn[0] );
V02 = ( gl_PositionIn[2] - gl_PositionIn[0] );
Search WWH ::




Custom Search