content/canvas/test/webgl-conformance/conformance/glsl/misc/shared.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <title>WebGL GLSL Conformance Tests</title>
michael@0 11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
michael@0 12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
michael@0 13 <script src="../../../resources/js-test-pre.js"></script>
michael@0 14 <script src="../../resources/webgl-test-utils.js"></script>
michael@0 15 <script src="../../resources/glsl-conformance-test.js"></script>
michael@0 16 </head>
michael@0 17 <body>
michael@0 18 <div id="description"></div>
michael@0 19 <div id="console"></div>
michael@0 20 <script id="sharedVertexShader" type="text/something-not-javascript">
michael@0 21 // shared vertex shader should succeed.
michael@0 22 uniform mat4 viewProjection;
michael@0 23 uniform vec3 worldPosition;
michael@0 24 uniform vec3 nextPosition;
michael@0 25 uniform float fishLength;
michael@0 26 uniform float fishWaveLength;
michael@0 27 uniform float fishBendAmount;
michael@0 28 attribute vec4 position;
michael@0 29 attribute vec2 texCoord;
michael@0 30 varying vec4 v_position;
michael@0 31 varying vec2 v_texCoord;
michael@0 32 varying vec3 v_surfaceToLight;
michael@0 33 void main() {
michael@0 34 vec3 vz = normalize(worldPosition - nextPosition);
michael@0 35 vec3 vx = normalize(cross(vec3(0,1,0), vz));
michael@0 36 vec3 vy = cross(vz, vx);
michael@0 37 mat4 orientMat = mat4(
michael@0 38 vec4(vx, 0),
michael@0 39 vec4(vy, 0),
michael@0 40 vec4(vz, 0),
michael@0 41 vec4(worldPosition, 1));
michael@0 42 mat4 world = orientMat;
michael@0 43 mat4 worldViewProjection = viewProjection * world;
michael@0 44 mat4 worldInverseTranspose = world;
michael@0 45
michael@0 46 v_texCoord = texCoord;
michael@0 47 // NOTE:If you change this you need to change the laser code to match!
michael@0 48 float mult = position.z > 0.0 ?
michael@0 49 (position.z / fishLength) :
michael@0 50 (-position.z / fishLength * 2.0);
michael@0 51 float s = sin(mult * fishWaveLength);
michael@0 52 float a = sign(s);
michael@0 53 float offset = pow(mult, 2.0) * s * fishBendAmount;
michael@0 54 v_position = (
michael@0 55 worldViewProjection *
michael@0 56 (position +
michael@0 57 vec4(offset, 0, 0, 0)));
michael@0 58 v_surfaceToLight = (world * position).xyz;
michael@0 59 gl_Position = v_position;
michael@0 60 }
michael@0 61 </script>
michael@0 62 <script id="fragmentShaderA" type="text/something-not-javascript">
michael@0 63 // shared fragment shader should succeed.
michael@0 64 precision mediump float;
michael@0 65 uniform vec4 lightColor;
michael@0 66 varying vec4 v_position;
michael@0 67 varying vec2 v_texCoord;
michael@0 68 varying vec3 v_surfaceToLight;
michael@0 69
michael@0 70 uniform vec4 ambient;
michael@0 71 uniform sampler2D diffuse;
michael@0 72 uniform vec4 specular;
michael@0 73 uniform float shininess;
michael@0 74 uniform float specularFactor;
michael@0 75 // #fogUniforms
michael@0 76
michael@0 77 vec4 lit(float l ,float h, float m) {
michael@0 78 return vec4(1.0,
michael@0 79 max(l, 0.0),
michael@0 80 (l > 0.0) ? pow(max(0.0, h), m) : 0.0,
michael@0 81 1.0);
michael@0 82 }
michael@0 83 void main() {
michael@0 84 vec4 diffuseColor = texture2D(diffuse, v_texCoord);
michael@0 85 vec4 normalSpec = vec4(0,0,0,0); // #noNormalMap
michael@0 86 vec3 surfaceToLight = normalize(v_surfaceToLight);
michael@0 87 vec3 halfVector = normalize(surfaceToLight);
michael@0 88 vec4 litR = lit(1.0, 1.0, shininess);
michael@0 89 vec4 outColor = vec4(
michael@0 90 (lightColor * (diffuseColor * litR.y + diffuseColor * ambient +
michael@0 91 specular * litR.z * specularFactor * normalSpec.a)).rgb,
michael@0 92 diffuseColor.a);
michael@0 93 // #fogCode
michael@0 94 gl_FragColor = outColor;
michael@0 95 }
michael@0 96 </script>
michael@0 97 <script id="fragmentShaderB" type="text/something-not-javascript">
michael@0 98 // shared fragment shader should succeed.
michael@0 99 precision mediump float;
michael@0 100 varying vec4 v_position;
michael@0 101 varying vec2 v_texCoord;
michael@0 102 varying vec3 v_surfaceToLight;
michael@0 103
michael@0 104 // #fogUniforms
michael@0 105
michael@0 106 vec4 lit(float l ,float h, float m) {
michael@0 107 return vec4(1.0,
michael@0 108 max(l, 0.0),
michael@0 109 (l > 0.0) ? pow(max(0.0, h), m) : 0.0,
michael@0 110 1.0);
michael@0 111 }
michael@0 112 void main() {
michael@0 113 vec4 normalSpec = vec4(0,0,0,0); // #noNormalMap
michael@0 114 vec4 reflection = vec4(0,0,0,0); // #noReflection
michael@0 115 vec3 surfaceToLight = normalize(v_surfaceToLight);
michael@0 116 vec4 skyColor = vec4(0.5,0.5,1,1); // #noReflection
michael@0 117
michael@0 118 vec3 halfVector = normalize(surfaceToLight);
michael@0 119 vec4 litR = lit(1.0, 1.0, 10.0);
michael@0 120 vec4 outColor = vec4(mix(
michael@0 121 skyColor,
michael@0 122 vec4(1,2,3,4) * (litR.y + litR.z * normalSpec.a),
michael@0 123 1.0 - reflection.r).rgb,
michael@0 124 1.0);
michael@0 125 // #fogCode
michael@0 126 gl_FragColor = outColor;
michael@0 127 }
michael@0 128 </script>
michael@0 129 <script>
michael@0 130 GLSLConformanceTester.runTests([
michael@0 131 { vShaderSource: document.getElementById("sharedVertexShader").text,
michael@0 132 vShaderSuccess: true,
michael@0 133 fShaderSource: document.getElementById("fragmentShaderA").text,
michael@0 134 fShaderSuccess: true,
michael@0 135 linkSuccess: true,
michael@0 136 passMsg: 'shared fragment shader should succeed',
michael@0 137 },
michael@0 138 { vShaderSource: document.getElementById("sharedVertexShader").text,
michael@0 139 vShaderSuccess: true,
michael@0 140 fShaderSource: document.getElementById("fragmentShaderB").text,
michael@0 141 fShaderSuccess: true,
michael@0 142 linkSuccess: true,
michael@0 143 passMsg: 'shared fragment shader should succeed',
michael@0 144 }
michael@0 145 ]);
michael@0 146 successfullyParsed = true;
michael@0 147 </script>
michael@0 148 </body>
michael@0 149 </html>
michael@0 150

mercurial