summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/shared.html
blob: 77786bb3850690fe081a3b7f16aaa04068b42c3a (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
145
146
147
148
149
150
151
<!--
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.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL GLSL Conformance Tests</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"></script>
<script src="../../../js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="sharedVertexShader" type="text/something-not-javascript">
// shared vertex shader should succeed.
uniform mat4 viewProjection;
uniform vec3 worldPosition;
uniform vec3 nextPosition;
uniform float fishLength;
uniform float fishWaveLength;
uniform float fishBendAmount;
attribute vec4 position;
attribute vec2 texCoord;
varying vec4 v_position;
varying vec2 v_texCoord;
varying vec3 v_surfaceToLight;
void main() {
  vec3 vz = normalize(worldPosition - nextPosition);
  vec3 vx = normalize(cross(vec3(0,1,0), vz));
  vec3 vy = cross(vz, vx);
  mat4 orientMat = mat4(
    vec4(vx, 0),
    vec4(vy, 0),
    vec4(vz, 0),
    vec4(worldPosition, 1));
  mat4 world = orientMat;
  mat4 worldViewProjection = viewProjection * world;
  mat4 worldInverseTranspose = world;

  v_texCoord = texCoord;
  // NOTE:If you change this you need to change the laser code to match!
  float mult = position.z > 0.0 ?
      (position.z / fishLength) :
      (-position.z / fishLength * 2.0);
  float s = sin(mult * fishWaveLength);
  float a = sign(s);
  float offset = pow(mult, 2.0) * s * fishBendAmount;
  v_position = (
      worldViewProjection *
      (position +
       vec4(offset, 0, 0, 0)));
  v_surfaceToLight = (world * position).xyz;
  gl_Position = v_position;
}
</script>
<script id="fragmentShaderA" type="text/something-not-javascript">
// shared fragment shader should succeed.
precision mediump float;
uniform vec4 lightColor;
varying vec4 v_position;
varying vec2 v_texCoord;
varying vec3 v_surfaceToLight;

uniform vec4 ambient;
uniform sampler2D diffuse;
uniform vec4 specular;
uniform float shininess;
uniform float specularFactor;
// #fogUniforms

vec4 lit(float l ,float h, float m) {
  return vec4(1.0,
              max(l, 0.0),
              (l > 0.0) ? pow(max(0.0, h), m) : 0.0,
              1.0);
}
void main() {
  vec4 diffuseColor = texture2D(diffuse, v_texCoord);
  vec4 normalSpec = vec4(0,0,0,0);  // #noNormalMap
  vec3 surfaceToLight = normalize(v_surfaceToLight);
  vec3 halfVector = normalize(surfaceToLight);
  vec4 litR = lit(1.0, 1.0, shininess);
  vec4 outColor = vec4(
    (lightColor * (diffuseColor * litR.y + diffuseColor * ambient +
                  specular * litR.z * specularFactor * normalSpec.a)).rgb,
      diffuseColor.a);
  // #fogCode
  gl_FragColor = outColor;
}
</script>
<script id="fragmentShaderB" type="text/something-not-javascript">
// shared fragment shader should succeed.
precision mediump float;
varying vec4 v_position;
varying vec2 v_texCoord;
varying vec3 v_surfaceToLight;

// #fogUniforms

vec4 lit(float l ,float h, float m) {
  return vec4(1.0,
              max(l, 0.0),
              (l > 0.0) ? pow(max(0.0, h), m) : 0.0,
              1.0);
}
void main() {
  vec4 normalSpec = vec4(0,0,0,0);  // #noNormalMap
  vec4 reflection = vec4(0,0,0,0);  // #noReflection
  vec3 surfaceToLight = normalize(v_surfaceToLight);
  vec4 skyColor = vec4(0.5,0.5,1,1);  // #noReflection

  vec3 halfVector = normalize(surfaceToLight);
  vec4 litR = lit(1.0, 1.0, 10.0);
  vec4 outColor = vec4(mix(
      skyColor,
      vec4(1,2,3,4) * (litR.y + litR.z * normalSpec.a),
      1.0 - reflection.r).rgb,
      1.0);
  // #fogCode
  gl_FragColor = outColor;
}
</script>
<script>
"use strict";
GLSLConformanceTester.runTests([
  { vShaderSource: document.getElementById("sharedVertexShader").text,
    vShaderSuccess: true,
    fShaderSource: document.getElementById("fragmentShaderA").text,
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: 'shared fragment shader should succeed',
  },
  { vShaderSource: document.getElementById("sharedVertexShader").text,
    vShaderSuccess: true,
    fShaderSource: document.getElementById("fragmentShaderB").text,
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: 'shared fragment shader should succeed',
  }
]);
var successfullyParsed = true;
</script>
</body>
</html>