| 1 |
|
|---|
| 2 |
// |
|---|
| 3 |
// screen.vert: Vertex shader for testing the "discard" command |
|---|
| 4 |
// in a fragment shader |
|---|
| 5 |
// an example of an OpenGL Shading Language source file. |
|---|
| 6 |
// |
|---|
| 7 |
// author: Randi Rost |
|---|
| 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 Scale = 2.1; |
|---|
| 21 |
|
|---|
| 22 |
varying float lightIntensity; |
|---|
| 23 |
varying vec3 Position; |
|---|
| 24 |
|
|---|
| 25 |
const float specularContribution = 0.5; |
|---|
| 26 |
const float diffuseContribution = (1.0 - specularContribution); |
|---|
| 27 |
|
|---|
| 28 |
void main(void) { |
|---|
| 29 |
vec4 pos = gl_ModelViewMatrix * gl_Vertex; |
|---|
| 30 |
Position = gl_Vertex.xyz * Scale; |
|---|
| 31 |
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); |
|---|
| 32 |
vec3 lightVec = normalize(LightPosition - vec3(pos)); |
|---|
| 33 |
vec3 reflectVec = reflect(lightVec, tnorm); |
|---|
| 34 |
vec3 viewVec = normalize(vec3(pos)); |
|---|
| 35 |
float dotval = abs(dot(lightVec, tnorm)); |
|---|
| 36 |
|
|---|
| 37 |
float spec = pow(dot(reflectVec, viewVec), 8.0); |
|---|
| 38 |
|
|---|
| 39 |
lightIntensity = diffuseContribution * dotval + |
|---|
| 40 |
specularContribution * spec; |
|---|
| 41 |
|
|---|
| 42 |
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; |
|---|
| 43 |
|
|---|
| 44 |
} |
|---|