Advertisement
Ramy1989

Untitled

Oct 22nd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.89 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <title> Complex Shader </title>
  4.         <style> canvas { width:100%; height:100%; background-color: black;} </style>
  5.     </head>
  6.     <body>
  7.         <h1 align= "center" style="color:red"> Complex Shader </h1>
  8.         <script src="../Three.js-master/build/three.min.js"></script>
  9.         <script type="x-shader/x-vertex" id="vertexShader">
  10.  
  11.         attribute vec4 color;
  12.         varying vec4 outColor;
  13.  
  14.         void main()
  15.         {
  16.             outColor= color;
  17.             gl_Position= projectionMatrix * modelViewMatrix * vec4(position,1.0);
  18.         }
  19.  
  20.         </script>
  21.         <script type="x-shader/x-fragment" id="fragmentShader">
  22.  
  23.         varying vec4 outColor;
  24.  
  25.         void main() {
  26.             gl_FragColor = outColor;
  27.         }
  28.  
  29.         </script>
  30.         <script>
  31.             // Creazione scena, camera e renderer:
  32.             var scene= new THREE.Scene();
  33.             var camera= new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);
  34.             var renderer= new THREE.WebGLRenderer();
  35.             renderer.setSize(window.innerWidth,window.innerHeight);
  36.             document.body.appendChild(renderer.domElement);
  37.             camera.position.z=5;
  38.  
  39.             // Geometria, materiale
  40.             var geometry= new THREE.CubeGeometry(2,2,2);
  41.  
  42.             var uniforms= {
  43.             };
  44.             var colors= [];
  45.             for(var i=0; i<geometry.vertices.length; i++) {
  46.                 colors.push(new THREE.Vector4(0.0,1.0,0.0,1.0));
  47.             }
  48.             var attributes = {
  49.                 color: {type:"v4", value: colors}
  50.             };
  51.  
  52.             var material= new THREE.ShaderMaterial({
  53.                 uniforms: uniforms,
  54.                 attributes: {},
  55.                 vertexShader: document.getElementById("vertexShader").textContent,
  56.                 fragmentShader: document.getElementById("fragmentShader").textContent
  57.             });
  58.             var cube= new THREE.Mesh(geometry,material);
  59.             scene.add(cube);
  60.  
  61.             // Creazione della  funzione di rendering:
  62.             var render= function() {
  63.                 requestAnimationFrame(render);
  64.                 cube.rotation.x+= 0.025;
  65.                 cube.rotation.y+= 0.025;
  66.                 renderer.render(scene,camera);
  67.             }
  68.             render();
  69.         </script>
  70.     </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement