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="fragmentShader" type="text/something-not-javascript"> |
| 20 // fragment shader with for loop should succeed |
| 21 |
| 22 // TODO(gman): trim to min size to test bug. |
| 23 precision highp float; |
| 24 uniform float time; |
| 25 uniform vec2 resolution; |
| 26 |
| 27 // Saw-tooth function that is synced with the demo music (128bpm) |
| 28 float gBeat=fract(time*3.2/3.); |
| 29 |
| 30 // Calculate the surface color |
| 31 vec3 surfColor(vec2 p) |
| 32 { |
| 33 vec2 q=vec2(sin(.08*p.x),4.*p.y); |
| 34 vec3 c=vec3(0); |
| 35 for(float i=0.;i<15.;i++) |
| 36 c+=(1.+sin(i*sin(time)+vec3(0.,1.3,2.2)))*.2/length(q-vec2(sin(i),12.*sin(
.3*time+i))); |
| 37 return c+vec3(mix(mod(floor(p.x*.2)+floor(p.y*2.2),2.),.2,gBeat)); |
| 38 } |
| 39 |
| 40 // Ray trace (cylinder) |
| 41 vec3 trace(vec3 o,vec3 d) |
| 42 { |
| 43 d.y*=.65+.1*sin(.5*time); |
| 44 float D=1./(d.y*d.y+d.z*d.z), |
| 45 a=(o.y*d.y+o.z*d.z)*D, |
| 46 b=(o.y*o.y+o.z*o.z-36.)*D, |
| 47 t=-a-sqrt(a*a-b); |
| 48 o+=t*d; |
| 49 return surfColor(vec2(o.x,atan(o.y,o.z)))*(1.+.01*t); |
| 50 } |
| 51 |
| 52 void main() |
| 53 { |
| 54 // Screen setup |
| 55 vec2 p=(2.*gl_FragCoord.xy-resolution)/resolution.y, |
| 56 q=2.*gl_FragCoord.xy/resolution-1.; |
| 57 |
| 58 // Camera setup |
| 59 vec3 cp=vec3(-time*20.+1.,1.6*sin(time*1.2),2.+2.*cos(time*.3)), |
| 60 ct=cp+vec3(1.,.3*cos(time),-.2), |
| 61 cd=normalize(ct-cp), |
| 62 cr=normalize(cross(cd,vec3(.5*cos(.3*time),0.,1.))), |
| 63 cu=cross(cr,cd), |
| 64 rd=normalize(2.*cd+cr*p.x+cu*p.y); |
| 65 |
| 66 // Trace! (+some funky lens/raster effects) |
| 67 vec3 c=trace(cp,rd)* |
| 68 min(1.,1.8-dot(q,q))* |
| 69 (.9+.1*sin(3.*sin(gBeat)*gl_FragCoord.y)); |
| 70 |
| 71 gl_FragColor=vec4(c,1); |
| 72 } |
| 73 </script> |
| 74 <script> |
| 75 GLSLConformanceTester.runTest(); |
| 76 successfullyParsed = true; |
| 77 </script> |
| 78 </body> |
| 79 </html> |
| 80 |
| 81 |
OLD | NEW |