-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple-shader.html
108 lines (87 loc) · 2.6 KB
/
simple-shader.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>A Shader Object</title>
<style>
#container {
background: #000;
}
</style>
</head>
<body style="margin: 0px;">
<div id="container">
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="js/three.min.js"></script>
<script type="text/javascript">
// set the scene size
var WIDTH = $(window).width()-20,
HEIGHT = $(window).height()-5;
// set some camera attributes
var VIEW_ANGLE = 45,
ASPECT = WIDTH / HEIGHT,
NEAR = 0.1,
FAR = 1000;
// get the DOM element to attach to
// - assume we've got jQuery to hand
var $container = $('#container');
// create a WebGL renderer, camera
// and a scene
var renderer = new THREE.WebGLRenderer();
var camera = new THREE.PerspectiveCamera( VIEW_ANGLE,
ASPECT,
NEAR,
FAR );
var scene = new THREE.Scene();
// the camera starts at 0,0,0 so pull it back
camera.position.z = 300;
// start the renderer
renderer.setSize(WIDTH, HEIGHT);
// attach the render-supplied DOM element
$container.append(renderer.domElement);
// create the sphere's material
var sphereMaterial = new THREE.MeshLambertMaterial(
{
color: 0x498461
});
// set up the sphere vars
var radius = 100, segments = 166, rings = 160;
// create a new mesh with sphere geometry -
// we will cover the sphereMaterial next!
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, rings),
sphereMaterial);
// add the sphere to the scene
scene.add(sphere);
// and the camera
scene.add(camera);
// create a point light
var pointLight = new THREE.PointLight( 0xFFFFFF );
// set its position
pointLight.position.x = 10;
pointLight.position.y = 50;
pointLight.position.z = 130;
// add to the scene
scene.add(pointLight);
// draw!
renderer.render(scene, camera);
</script>
<script type="text/javascript">
$(function(){
$(window).resize(function(){
WIDTH = $(window).width()-20;
HEIGHT = $(window).height()-5;
renderer.setSize(WIDTH, HEIGHT);
});
});
</script>
<script type="text/javascript">
$( "body" ).mousemove(function( event ) {
pointLight.position.x = event.pageX-(WIDTH/2);
pointLight.position.y = -event.pageY+(HEIGHT/2);
renderer.render(scene, camera);
});
</script>
</html>