| 1 |
|
|---|
| 2 |
// |
|---|
| 3 |
// brick.frag: Fragment shader for procedural bricks |
|---|
| 4 |
// an example of an OpenGL Shading Language source file. |
|---|
| 5 |
// |
|---|
| 6 |
// author: Dave Baldwin, Steve Koren, Randi Rost |
|---|
| 7 |
// originally based on a shader by Darwyn Peachey |
|---|
| 8 |
// |
|---|
| 9 |
// Copyright (c) 2002: 3Dlabs, Inc. |
|---|
| 10 |
// |
|---|
| 11 |
|
|---|
| 12 |
// This file derived from the ogl2demo example in the 3Dlabs OpenGL2 SDK |
|---|
| 13 |
// available from http://www.3dlabs.com/opengl2/ |
|---|
| 14 |
// Mike Weiblen 2003-07-14 : til osgGL2 implements the setting of uniforms, |
|---|
| 15 |
// temporarily use consts instead. |
|---|
| 16 |
|
|---|
| 17 |
// uniform vec3 BrickColor, MortarColor; |
|---|
| 18 |
// uniform float ColumnWidth, RowHeight; |
|---|
| 19 |
// uniform float Bwf, Bhf; |
|---|
| 20 |
|
|---|
| 21 |
const vec3 BrickColor = vec3(1.0, 0.3, 0.2); |
|---|
| 22 |
const vec3 MortarColor = vec3(0.85, 0.85, 0.85); |
|---|
| 23 |
const float ColumnWidth = 0.30; |
|---|
| 24 |
const float RowHeight = 0.15; |
|---|
| 25 |
const float Bwf = 0.95; |
|---|
| 26 |
const float Bhf = 0.90; |
|---|
| 27 |
|
|---|
| 28 |
varying vec2 MCposition; |
|---|
| 29 |
varying float LightIntensity; |
|---|
| 30 |
|
|---|
| 31 |
void main(void) |
|---|
| 32 |
{ |
|---|
| 33 |
vec3 color; |
|---|
| 34 |
float ss, tt, w, h; |
|---|
| 35 |
|
|---|
| 36 |
ss = MCposition.x / ColumnWidth; |
|---|
| 37 |
tt = MCposition.y / RowHeight; |
|---|
| 38 |
|
|---|
| 39 |
if (fract(tt * 0.5) > 0.5) |
|---|
| 40 |
ss += 0.5; |
|---|
| 41 |
|
|---|
| 42 |
ss = fract(ss); |
|---|
| 43 |
tt = fract(tt); |
|---|
| 44 |
|
|---|
| 45 |
w = step(ss, Bwf); |
|---|
| 46 |
h = step(tt, Bhf); |
|---|
| 47 |
|
|---|
| 48 |
color = mix(MortarColor, BrickColor, w * h) * LightIntensity; |
|---|
| 49 |
gl_FragColor = vec4 (color, 1.0); |
|---|
| 50 |
} |
|---|