Forums > Jitter

colored stripes shader

November 21, 2010 | 11:29 pm

Hello list,
I’m trying to create a shader for generating colored stripes. I found a stripe shader in the orange book, but this one does only create 2 stripes, and I need one that makes 3. I tried to figure out how to modify the example, but so far no luck.
Can somebody hint me in the right direction how to go from 2 to 3 stripes?
Best Lev


Shader for generating Procedural Stripes












< ![CDATA[
//
// Author: OGLSL implementation by Ian Nurse
//
// Copyright (C) 2002-2006 LightWork Design Ltd.
// http://www.lightworkdesign.com
//
// See LightworkDesign-License.txt for license information
//

uniform vec3 LightPosition;
uniform vec3 LightColor;
uniform vec3 EyePosition;
uniform vec3 Specular;
uniform vec3 Ambient;
uniform float Kd;

varying vec3 DiffuseColor;
varying vec3 SpecularColor;

void main()
{
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
vec3 lightVec = normalize(LightPosition – ecPosition);
vec3 viewVec = normalize(EyePosition – ecPosition);
vec3 Hvec = normalize(viewVec + lightVec);

float spec = clamp(dot(Hvec, tnorm), 0.0, 1.0);
spec = pow(spec, 16.0);

DiffuseColor = LightColor * vec3(Kd * dot(lightVec, tnorm));
DiffuseColor = clamp(Ambient + DiffuseColor, 0.0, 1.0);
SpecularColor = clamp((LightColor * Specular * spec), 0.0, 1.0);

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

]]>

< ![CDATA[

uniform vec3 StripeColor;
uniform vec3 BackColor;
uniform float Width;
uniform float Fuzz;
uniform float Scale;

varying vec3 DiffuseColor;
varying vec3 SpecularColor;

void main()
{
float scaled_t = fract(gl_TexCoord[0].t * Scale);

float frac1 = clamp(scaled_t / Fuzz, 0.0, 1.0);
float frac2 = clamp((scaled_t – Width) / Fuzz, 0.0, 1.0);

frac1 = frac1 * (1.0 – frac2);
frac1 = frac1 * frac1 * (3.0 – (2.0 * frac1));

vec3 finalColor = mix(BackColor, StripeColor, frac2);
finalColor = finalColor * DiffuseColor + SpecularColor;

gl_FragColor = vec4(finalColor, 1.0);
}
]]>


Viewing 1 post (of 1 total)