summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/ogles/GL2FixedTests/buffer_objects/buffer_objects.vert
blob: 9b8f753d5830a7a75ddee28b4ebbcf1d645e5549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
*/


attribute vec4 gtf_Color;
attribute vec4 gtf_Vertex;
attribute vec3 gtf_Normal;
attribute vec4 gtf_MultiTexCoord0;

uniform mat4 gtf_ModelViewProjectionMatrix;
uniform mat3 gtf_NormalMatrix;

varying vec4 gtf_TexCoord[1];
varying vec4 color;

vec4 Ambient;
vec4 Diffuse;
vec4 Specular;

const vec3 lightPosition = vec3(0.0, 0.0, 1.0);
const vec3 spotDirection = vec3(0.0, 0.0, -1.0);
const float spotCutoff = 180.0;
const float spotExponent = 0.0;

const float lightAttenuationConstant = 1.0;
const float lightAttenuationLinear = 0.0;
const float lightAttenuationQuadratic = 0.0;

const vec4 lightAmbient = vec4(0.0, 0.0, 0.0, 0.0);
vec4 lightDiffuse = vec4(1.0, 1.0, 1.0, 1.0);
vec4 lightSpecular = vec4(1.0, 1.0, 1.0, 1.0);

const float materialShininess = 0.0;

const vec4 sceneColor = vec4(0.0, 0.0, 0.0, 0.0);

void spotLight(in int i,
               in vec3 normal,
               in vec3 eye,
               in vec3 ecPosition3
               )
{
    float nDotVP;           // normal . light direction
    float nDotHV;           // normal . light half vector
    float pf;               // power factor
    float spotDot;          // cosine of angle between spotlight
    float spotAttenuation;  // spotlight attenuation factor
    float attenuation;      // computed attenuation factor
    float d;                // distance from surface to light source
    vec3 VP;                // direction from surface to light position
    vec3 halfVector;        // direction of maximum highlights

    // Compute vector from surface to light position
    VP = lightPosition - ecPosition3;

    // Compute distance between surface and light position
    d = length(VP);

    // Normalize the vector from surface to light position
    VP = normalize(VP);

    // Compute attenuation
    attenuation = 1.0 / (lightAttenuationConstant +
                         lightAttenuationLinear * d +
                         lightAttenuationQuadratic * d * d);

    // See if point on surface is inside cone of illumination
    spotDot = dot(-VP, normalize(spotDirection));

    if (spotDot < cos(radians(spotCutoff)))
        spotAttenuation = 0.0; // light adds no contribution
    else
        spotAttenuation = pow(spotDot, spotExponent);

    // Combine the spotlight and distance attenuation.
    attenuation *= spotAttenuation;

    halfVector = normalize(VP + eye);

    nDotVP = max(0.0, dot(normal, VP));
    nDotHV = max(0.0, dot(normal, halfVector));

    if (nDotVP == 0.0)
        pf = 0.0;
    else
        pf = pow(nDotHV, materialShininess);

    Ambient  += lightAmbient * attenuation;
    Diffuse  += lightDiffuse * nDotVP * attenuation;
    Specular += lightSpecular * pf * attenuation;
}

vec3 fnormal(void)
{
    //Compute the normal 
    vec3 normal = gtf_NormalMatrix * gtf_Normal;
    normal = normalize(normal);
    
	return normal;
}

void flight(in vec3 normal, in vec4 ecPosition, float alphaFade)
{
    vec3 ecPosition3;
    vec3 eye;

    ecPosition3 = (vec3 (ecPosition)) / ecPosition.w;
    eye = vec3 (0.0, 0.0, 1.0);

    // Clear the light intensity accumulators
    Ambient  = vec4 (0.0);
    Diffuse  = vec4 (0.0);
    Specular = vec4 (0.0);
   
   //lightSpecular = gtf_Color;

    spotLight(0, normal, eye, ecPosition3);

    color = sceneColor +
      Ambient  * gtf_Color +
      Diffuse  * gtf_Color;
    color += Specular * gtf_Color;
    color = clamp( color, 0.0, 1.0 );

    color.a *= alphaFade;
}

void main (void)
{
	vec3  transformedNormal;
    float alphaFade = 1.0;
	
	vec4 ecPosition = gtf_Vertex;
	
	color = gtf_Color;
	gtf_TexCoord[0] = gtf_MultiTexCoord0;
	gl_Position = gtf_ModelViewProjectionMatrix * gtf_Vertex;
	transformedNormal = fnormal();
    flight(transformedNormal, ecPosition, alphaFade);
}