2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL GLSL Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
13 <link rel=
"stylesheet" href=
"../../../resources/glsl-feature-tests.css"/>
14 <script src=
"../../../js/js-test-pre.js"></script>
15 <script src=
"../../../js/webgl-test-utils.js"></script>
16 <script src=
"../../../js/glsl-conformance-test.js"></script>
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"sharedVertexShader" type=
"text/something-not-javascript">
22 // shared vertex shader should succeed.
23 uniform mat4 viewProjection;
24 uniform vec3 worldPosition;
25 uniform vec3 nextPosition;
26 uniform float fishLength;
27 uniform float fishWaveLength;
28 uniform float fishBendAmount;
29 attribute vec4 position;
30 attribute vec2 texCoord;
31 varying vec4 v_position;
32 varying vec2 v_texCoord;
33 varying vec3 v_surfaceToLight;
35 vec3 vz = normalize(worldPosition - nextPosition);
36 vec3 vx = normalize(cross(vec3(
0,
1,
0), vz));
37 vec3 vy = cross(vz, vx);
38 mat4 orientMat = mat4(
42 vec4(worldPosition,
1));
43 mat4 world = orientMat;
44 mat4 worldViewProjection = viewProjection * world;
45 mat4 worldInverseTranspose = world;
47 v_texCoord = texCoord;
48 // NOTE:If you change this you need to change the laser code to match!
49 float mult = position.z
> 0.0 ?
50 (position.z / fishLength) :
51 (-position.z / fishLength *
2.0);
52 float s = sin(mult * fishWaveLength);
54 float offset = pow(mult,
2.0) * s * fishBendAmount;
58 vec4(offset,
0,
0,
0)));
59 v_surfaceToLight = (world * position).xyz;
60 gl_Position = v_position;
63 <script id=
"fragmentShaderA" type=
"text/something-not-javascript">
64 // shared fragment shader should succeed.
65 precision mediump float;
66 uniform vec4 lightColor;
67 varying vec4 v_position;
68 varying vec2 v_texCoord;
69 varying vec3 v_surfaceToLight;
72 uniform sampler2D diffuse;
73 uniform vec4 specular;
74 uniform float shininess;
75 uniform float specularFactor;
78 vec4 lit(float l ,float h, float m) {
81 (l
> 0.0) ? pow(max(
0.0, h), m) :
0.0,
85 vec4 diffuseColor = texture2D(diffuse, v_texCoord);
86 vec4 normalSpec = vec4(
0,
0,
0,
0); // #noNormalMap
87 vec3 surfaceToLight = normalize(v_surfaceToLight);
88 vec3 halfVector = normalize(surfaceToLight);
89 vec4 litR = lit(
1.0,
1.0, shininess);
91 (lightColor * (diffuseColor * litR.y + diffuseColor * ambient +
92 specular * litR.z * specularFactor * normalSpec.a)).rgb,
95 gl_FragColor = outColor;
98 <script id=
"fragmentShaderB" type=
"text/something-not-javascript">
99 // shared fragment shader should succeed.
100 precision mediump float;
101 varying vec4 v_position;
102 varying vec2 v_texCoord;
103 varying vec3 v_surfaceToLight;
107 vec4 lit(float l ,float h, float m) {
110 (l
> 0.0) ? pow(max(
0.0, h), m) :
0.0,
114 vec4 normalSpec = vec4(
0,
0,
0,
0); // #noNormalMap
115 vec4 reflection = vec4(
0,
0,
0,
0); // #noReflection
116 vec3 surfaceToLight = normalize(v_surfaceToLight);
117 vec4 skyColor = vec4(
0.5,
0.5,
1,
1); // #noReflection
119 vec3 halfVector = normalize(surfaceToLight);
120 vec4 litR = lit(
1.0,
1.0,
10.0);
121 vec4 outColor = vec4(mix(
123 vec4(
1,
2,
3,
4) * (litR.y + litR.z * normalSpec.a),
124 1.0 - reflection.r).rgb,
127 gl_FragColor = outColor;
132 GLSLConformanceTester
.runTests([
133 { vShaderSource
: document
.getElementById("sharedVertexShader").text
,
134 vShaderSuccess
: true,
135 fShaderSource
: document
.getElementById("fragmentShaderA").text
,
136 fShaderSuccess
: true,
138 passMsg
: 'shared fragment shader should succeed',
140 { vShaderSource
: document
.getElementById("sharedVertexShader").text
,
141 vShaderSuccess
: true,
142 fShaderSource
: document
.getElementById("fragmentShaderB").text
,
143 fShaderSuccess
: true,
145 passMsg
: 'shared fragment shader should succeed',
148 var successfullyParsed
= true;