1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/glsl/misc/shared.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 +--> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL GLSL Conformance Tests</title> 1.14 +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> 1.15 +<link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> 1.16 +<script src="../../../resources/js-test-pre.js"></script> 1.17 +<script src="../../resources/webgl-test-utils.js"></script> 1.18 +<script src="../../resources/glsl-conformance-test.js"></script> 1.19 +</head> 1.20 +<body> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<script id="sharedVertexShader" type="text/something-not-javascript"> 1.24 +// shared vertex shader should succeed. 1.25 +uniform mat4 viewProjection; 1.26 +uniform vec3 worldPosition; 1.27 +uniform vec3 nextPosition; 1.28 +uniform float fishLength; 1.29 +uniform float fishWaveLength; 1.30 +uniform float fishBendAmount; 1.31 +attribute vec4 position; 1.32 +attribute vec2 texCoord; 1.33 +varying vec4 v_position; 1.34 +varying vec2 v_texCoord; 1.35 +varying vec3 v_surfaceToLight; 1.36 +void main() { 1.37 + vec3 vz = normalize(worldPosition - nextPosition); 1.38 + vec3 vx = normalize(cross(vec3(0,1,0), vz)); 1.39 + vec3 vy = cross(vz, vx); 1.40 + mat4 orientMat = mat4( 1.41 + vec4(vx, 0), 1.42 + vec4(vy, 0), 1.43 + vec4(vz, 0), 1.44 + vec4(worldPosition, 1)); 1.45 + mat4 world = orientMat; 1.46 + mat4 worldViewProjection = viewProjection * world; 1.47 + mat4 worldInverseTranspose = world; 1.48 + 1.49 + v_texCoord = texCoord; 1.50 + // NOTE:If you change this you need to change the laser code to match! 1.51 + float mult = position.z > 0.0 ? 1.52 + (position.z / fishLength) : 1.53 + (-position.z / fishLength * 2.0); 1.54 + float s = sin(mult * fishWaveLength); 1.55 + float a = sign(s); 1.56 + float offset = pow(mult, 2.0) * s * fishBendAmount; 1.57 + v_position = ( 1.58 + worldViewProjection * 1.59 + (position + 1.60 + vec4(offset, 0, 0, 0))); 1.61 + v_surfaceToLight = (world * position).xyz; 1.62 + gl_Position = v_position; 1.63 +} 1.64 +</script> 1.65 +<script id="fragmentShaderA" type="text/something-not-javascript"> 1.66 +// shared fragment shader should succeed. 1.67 +precision mediump float; 1.68 +uniform vec4 lightColor; 1.69 +varying vec4 v_position; 1.70 +varying vec2 v_texCoord; 1.71 +varying vec3 v_surfaceToLight; 1.72 + 1.73 +uniform vec4 ambient; 1.74 +uniform sampler2D diffuse; 1.75 +uniform vec4 specular; 1.76 +uniform float shininess; 1.77 +uniform float specularFactor; 1.78 +// #fogUniforms 1.79 + 1.80 +vec4 lit(float l ,float h, float m) { 1.81 + return vec4(1.0, 1.82 + max(l, 0.0), 1.83 + (l > 0.0) ? pow(max(0.0, h), m) : 0.0, 1.84 + 1.0); 1.85 +} 1.86 +void main() { 1.87 + vec4 diffuseColor = texture2D(diffuse, v_texCoord); 1.88 + vec4 normalSpec = vec4(0,0,0,0); // #noNormalMap 1.89 + vec3 surfaceToLight = normalize(v_surfaceToLight); 1.90 + vec3 halfVector = normalize(surfaceToLight); 1.91 + vec4 litR = lit(1.0, 1.0, shininess); 1.92 + vec4 outColor = vec4( 1.93 + (lightColor * (diffuseColor * litR.y + diffuseColor * ambient + 1.94 + specular * litR.z * specularFactor * normalSpec.a)).rgb, 1.95 + diffuseColor.a); 1.96 + // #fogCode 1.97 + gl_FragColor = outColor; 1.98 +} 1.99 +</script> 1.100 +<script id="fragmentShaderB" type="text/something-not-javascript"> 1.101 +// shared fragment shader should succeed. 1.102 +precision mediump float; 1.103 +varying vec4 v_position; 1.104 +varying vec2 v_texCoord; 1.105 +varying vec3 v_surfaceToLight; 1.106 + 1.107 +// #fogUniforms 1.108 + 1.109 +vec4 lit(float l ,float h, float m) { 1.110 + return vec4(1.0, 1.111 + max(l, 0.0), 1.112 + (l > 0.0) ? pow(max(0.0, h), m) : 0.0, 1.113 + 1.0); 1.114 +} 1.115 +void main() { 1.116 + vec4 normalSpec = vec4(0,0,0,0); // #noNormalMap 1.117 + vec4 reflection = vec4(0,0,0,0); // #noReflection 1.118 + vec3 surfaceToLight = normalize(v_surfaceToLight); 1.119 + vec4 skyColor = vec4(0.5,0.5,1,1); // #noReflection 1.120 + 1.121 + vec3 halfVector = normalize(surfaceToLight); 1.122 + vec4 litR = lit(1.0, 1.0, 10.0); 1.123 + vec4 outColor = vec4(mix( 1.124 + skyColor, 1.125 + vec4(1,2,3,4) * (litR.y + litR.z * normalSpec.a), 1.126 + 1.0 - reflection.r).rgb, 1.127 + 1.0); 1.128 + // #fogCode 1.129 + gl_FragColor = outColor; 1.130 +} 1.131 +</script> 1.132 +<script> 1.133 +GLSLConformanceTester.runTests([ 1.134 + { vShaderSource: document.getElementById("sharedVertexShader").text, 1.135 + vShaderSuccess: true, 1.136 + fShaderSource: document.getElementById("fragmentShaderA").text, 1.137 + fShaderSuccess: true, 1.138 + linkSuccess: true, 1.139 + passMsg: 'shared fragment shader should succeed', 1.140 + }, 1.141 + { vShaderSource: document.getElementById("sharedVertexShader").text, 1.142 + vShaderSuccess: true, 1.143 + fShaderSource: document.getElementById("fragmentShaderB").text, 1.144 + fShaderSuccess: true, 1.145 + linkSuccess: true, 1.146 + passMsg: 'shared fragment shader should succeed', 1.147 + } 1.148 +]); 1.149 +successfullyParsed = true; 1.150 +</script> 1.151 +</body> 1.152 +</html> 1.153 +