webgl_shader.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - shader [Monjori]</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. color: #ffffff;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. font-weight: bold;
  14. background-color: #000000;
  15. margin: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. position: absolute;
  20. top: 0px; width: 100%;
  21. padding: 5px;
  22. }
  23. a {
  24. color: #ffffff;
  25. }
  26. #oldie a { color:#da0 }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="container"></div>
  31. <div id="info"><a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - shader demo. featuring <a href="http://www.pouet.net/prod.php?which=52761" target="_blank" rel="noopener">Monjori by Mic</a></div>
  32. <script src="../build/three.js"></script>
  33. <script src="js/Detector.js"></script>
  34. <script id="vertexShader" type="x-shader/x-vertex">
  35. void main() {
  36. gl_Position = vec4( position, 1.0 );
  37. }
  38. </script>
  39. <script id="fragmentShader" type="x-shader/x-fragment">
  40. uniform vec2 resolution;
  41. uniform float time;
  42. void main() {
  43. vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
  44. float a = time*40.0;
  45. float d,e,f,g=1.0/40.0,h,i,r,q;
  46. e=400.0*(p.x*0.5+0.5);
  47. f=400.0*(p.y*0.5+0.5);
  48. i=200.0+sin(e*g+a/150.0)*20.0;
  49. d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;
  50. r=sqrt(pow(abs(i-e),2.0)+pow(abs(d-f),2.0));
  51. q=f/r;
  52. e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;
  53. d=sin(e*g)*176.0+sin(e*g)*164.0+r;
  54. h=((f+d)+a/2.0)*g;
  55. i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);
  56. h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;
  57. h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;
  58. i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);
  59. i=mod(i/5.6,256.0)/64.0;
  60. if(i<0.0) i+=4.0;
  61. if(i>=2.0) i=4.0-i;
  62. d=r/350.0;
  63. d+=sin(d*d*8.0)*0.52;
  64. f=(sin(a*g)+1.0)/2.0;
  65. gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);
  66. }
  67. </script>
  68. <script>
  69. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  70. var container;
  71. var camera, scene, renderer;
  72. var uniforms;
  73. init();
  74. animate();
  75. function init() {
  76. container = document.getElementById( 'container' );
  77. camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  78. scene = new THREE.Scene();
  79. var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
  80. uniforms = {
  81. time: { value: 1.0 },
  82. resolution: { value: new THREE.Vector2() }
  83. };
  84. var material = new THREE.ShaderMaterial( {
  85. uniforms: uniforms,
  86. vertexShader: document.getElementById( 'vertexShader' ).textContent,
  87. fragmentShader: document.getElementById( 'fragmentShader' ).textContent
  88. } );
  89. var mesh = new THREE.Mesh( geometry, material );
  90. scene.add( mesh );
  91. renderer = new THREE.WebGLRenderer();
  92. renderer.setPixelRatio( window.devicePixelRatio );
  93. container.appendChild( renderer.domElement );
  94. onWindowResize();
  95. window.addEventListener( 'resize', onWindowResize, false );
  96. }
  97. function onWindowResize( event ) {
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. uniforms.resolution.value.x = renderer.domElement.width;
  100. uniforms.resolution.value.y = renderer.domElement.height;
  101. }
  102. //
  103. function animate( timestamp ) {
  104. requestAnimationFrame( animate );
  105. uniforms.time.value = timestamp / 1000;
  106. renderer.render( scene, camera );
  107. }
  108. </script>
  109. </body>
  110. </html>