| 1 |
|
|---|
| 2 |
// |
|---|
| 3 |
// brick.vert: Vertex shader for procedural bricks |
|---|
| 4 |
// an example of an OpenGL Shading Language source file. |
|---|
| 5 |
// |
|---|
| 6 |
// author: Dave Baldwin, Steve Koren, Randi Rost |
|---|
| 7 |
// 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 LightPosition; |
|---|
| 18 |
const vec3 LightPosition = vec3(0.0, 0.0, 4.0); |
|---|
| 19 |
|
|---|
| 20 |
const float specularContribution = 0.3; |
|---|
| 21 |
const float diffuseContribution = (1.0 - specularContribution); |
|---|
| 22 |
|
|---|
| 23 |
varying float LightIntensity; |
|---|
| 24 |
varying vec2 MCposition; |
|---|
| 25 |
|
|---|
| 26 |
void main(void) |
|---|
| 27 |
{ |
|---|
| 28 |
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; |
|---|
| 29 |
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); |
|---|
| 30 |
vec3 lightVec = normalize(LightPosition - vec3 (ecPosition)); |
|---|
| 31 |
vec3 reflectVec = reflect(-lightVec, tnorm); |
|---|
| 32 |
vec3 viewVec = normalize(vec3 (-ecPosition)); |
|---|
| 33 |
float spec = max(dot(reflectVec, viewVec), 0.0); |
|---|
| 34 |
spec = pow(spec, 16.0); |
|---|
| 35 |
LightIntensity = diffuseContribution * max(dot(lightVec, tnorm), 0.0) + |
|---|
| 36 |
specularContribution * spec; |
|---|
| 37 |
MCposition = gl_Vertex.xz; |
|---|
| 38 |
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; |
|---|
| 39 |
} |
|---|