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