xref: /haiku/src/tests/kits/opengl/glsl/CH06-brick.vert (revision 6eba5912150d8bedb7d4e5f4bc883d499c2a0ce3)
1*6eba5912SPhilippe Houdoin//
2*6eba5912SPhilippe Houdoin// Vertex shader for procedural bricks
3*6eba5912SPhilippe Houdoin//
4*6eba5912SPhilippe Houdoin// Authors: Dave Baldwin, Steve Koren, Randi Rost
5*6eba5912SPhilippe Houdoin//          based on a shader by Darwyn Peachey
6*6eba5912SPhilippe Houdoin//
7*6eba5912SPhilippe Houdoin// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
8*6eba5912SPhilippe Houdoin//
9*6eba5912SPhilippe Houdoin// See 3Dlabs-License.txt for license information
10*6eba5912SPhilippe Houdoin//
11*6eba5912SPhilippe Houdoin
12*6eba5912SPhilippe Houdoinuniform vec3 LightPosition;
13*6eba5912SPhilippe Houdoin
14*6eba5912SPhilippe Houdoinconst float SpecularContribution = 0.3;
15*6eba5912SPhilippe Houdoinconst float DiffuseContribution  = 1.0 - SpecularContribution;
16*6eba5912SPhilippe Houdoin
17*6eba5912SPhilippe Houdoinvarying float LightIntensity;
18*6eba5912SPhilippe Houdoinvarying vec2  MCposition;
19*6eba5912SPhilippe Houdoin
20*6eba5912SPhilippe Houdoinvoid main()
21*6eba5912SPhilippe Houdoin{
22*6eba5912SPhilippe Houdoin    vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
23*6eba5912SPhilippe Houdoin    vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal);
24*6eba5912SPhilippe Houdoin    vec3 lightVec   = normalize(LightPosition - ecPosition);
25*6eba5912SPhilippe Houdoin    vec3 reflectVec = reflect(-lightVec, tnorm);
26*6eba5912SPhilippe Houdoin    vec3 viewVec    = normalize(-ecPosition);
27*6eba5912SPhilippe Houdoin    float diffuse   = max(dot(lightVec, tnorm), 0.0);
28*6eba5912SPhilippe Houdoin    float spec      = 0.0;
29*6eba5912SPhilippe Houdoin
30*6eba5912SPhilippe Houdoin    if (diffuse > 0.0)
31*6eba5912SPhilippe Houdoin    {
32*6eba5912SPhilippe Houdoin        spec = max(dot(reflectVec, viewVec), 0.0);
33*6eba5912SPhilippe Houdoin        spec = pow(spec, 16.0);
34*6eba5912SPhilippe Houdoin    }
35*6eba5912SPhilippe Houdoin
36*6eba5912SPhilippe Houdoin    LightIntensity  = DiffuseContribution * diffuse +
37*6eba5912SPhilippe Houdoin                      SpecularContribution * spec;
38*6eba5912SPhilippe Houdoin
39*6eba5912SPhilippe Houdoin    MCposition      = gl_Vertex.xy;
40*6eba5912SPhilippe Houdoin    gl_Position     = ftransform();
41*6eba5912SPhilippe Houdoin}
42