|
Revision 6871
(checked in by robert, 2 years ago)
|
Checked in first cut of new SVN for OpenSceneGraph-Data
|
| Line | |
|---|
| 1 |
// blocky.frag - an OGLSL fragment shader with animation |
|---|
| 2 |
// Mike Weiblen 2003-09-16 : derived from brick.frag |
|---|
| 3 |
// Copyright 2003 3Dlabs Inc. |
|---|
| 4 |
// see http://www.3dlabs.com/opengl2/ for more OpenGL Shading Language info. |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
// the App updates uniforms "slowly" (eg once per frame) for animation. |
|---|
| 8 |
uniform float Sine; |
|---|
| 9 |
uniform vec3 Color1; |
|---|
| 10 |
uniform vec3 Color2; |
|---|
| 11 |
|
|---|
| 12 |
// varyings are written by vert shader, interpolated, and read by frag shader. |
|---|
| 13 |
varying vec2 BlockPosition; |
|---|
| 14 |
varying float LightIntensity; |
|---|
| 15 |
|
|---|
| 16 |
void main(void) |
|---|
| 17 |
{ |
|---|
| 18 |
vec3 color; |
|---|
| 19 |
float ss, tt, w, h; |
|---|
| 20 |
|
|---|
| 21 |
ss = BlockPosition.x; |
|---|
| 22 |
tt = BlockPosition.y; |
|---|
| 23 |
|
|---|
| 24 |
if (fract(tt * 0.5) > 0.5) |
|---|
| 25 |
ss += 0.5; |
|---|
| 26 |
|
|---|
| 27 |
ss = fract(ss); |
|---|
| 28 |
tt = fract(tt); |
|---|
| 29 |
|
|---|
| 30 |
// animate the proportion of block to mortar |
|---|
| 31 |
float blockFract = (Sine + 1.1) * 0.4; |
|---|
| 32 |
|
|---|
| 33 |
w = step(ss, blockFract); |
|---|
| 34 |
h = step(tt, blockFract); |
|---|
| 35 |
|
|---|
| 36 |
color = mix(Color2, Color1, w * h) * LightIntensity; |
|---|
| 37 |
gl_FragColor = vec4 (color, 1.0); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|