19
19
< script type ="text/javascript " src ="../libs/postprocessing/RenderPass.js "> </ script >
20
20
21
21
< style >
22
- body {
22
+ body {
23
23
/* set margin to 0 and overflow to hidden, to go fullscreen */
24
24
margin : 0 ;
25
25
overflow : hidden;
54
54
webGLRenderer . setSize ( window . innerWidth , window . innerHeight ) ;
55
55
webGLRenderer . shadowMapEnabled = true ;
56
56
57
- var sphere = createMesh ( new THREE . SphereGeometry ( 10 , 40 , 40 ) ) ;
57
+ var sphere = createMesh ( new THREE . SphereGeometry ( 10 , 40 , 40 ) ) ;
58
58
// add the sphere to the scene
59
59
scene . add ( sphere ) ;
60
60
63
63
camera . position . y = 15 ;
64
64
camera . position . z = 25 ;
65
65
66
- camera . lookAt ( new THREE . Vector3 ( 0 , 0 , 0 ) ) ;
66
+ camera . lookAt ( new THREE . Vector3 ( 0 , 0 , 0 ) ) ;
67
67
68
68
var orbitControls = new THREE . OrbitControls ( camera ) ;
69
- orbitControls . autoRotate = false ;
69
+ orbitControls . autoRotate = false ;
70
70
var clock = new THREE . Clock ( ) ;
71
71
72
72
var ambi = new THREE . AmbientLight ( 0x181818 ) ;
73
73
scene . add ( ambi ) ;
74
74
75
- var spotLight = new THREE . DirectionalLight ( 0xffffff ) ;
76
- spotLight . position . set ( 550 , 100 , 550 ) ;
75
+ var spotLight = new THREE . DirectionalLight ( 0xffffff ) ;
76
+ spotLight . position . set ( 550 , 100 , 550 ) ;
77
77
spotLight . intensity = 0.6 ;
78
78
79
- scene . add ( spotLight ) ;
79
+ scene . add ( spotLight ) ;
80
80
81
81
// add the output of the renderer to the html element
82
82
$ ( "#WebGL-output" ) . append ( webGLRenderer . domElement ) ;
83
83
84
- var renderPass = new THREE . RenderPass ( scene , camera ) ;
85
- var effectFilm = new THREE . FilmPass ( 0.8 , 0.325 , 256 , false ) ;
86
- effectFilm . renderToScreen = true ;
84
+ var renderPass = new THREE . RenderPass ( scene , camera ) ;
85
+ var effectFilm = new THREE . FilmPass ( 0.8 , 0.325 , 256 , false ) ;
86
+ effectFilm . renderToScreen = true ;
87
87
88
88
var composer = new THREE . EffectComposer ( webGLRenderer ) ;
89
89
composer . addPass ( renderPass ) ;
90
90
composer . addPass ( effectFilm ) ;
91
91
92
92
93
93
// setup the control gui
94
- var controls = new function ( ) {
94
+ var controls = new function ( ) {
95
95
this . scanlinesCount = 256 ;
96
96
this . grayscale = false ;
97
97
this . scanlinesIntensity = 0.3 ;
98
98
this . noiseIntensity = 0.8 ;
99
99
100
- this . updateEffectFilm = function ( ) {
100
+ this . updateEffectFilm = function ( ) {
101
101
effectFilm . uniforms . grayscale . value = controls . grayscale ;
102
102
effectFilm . uniforms . nIntensity . value = controls . noiseIntensity ;
103
103
effectFilm . uniforms . sIntensity . value = controls . scanlinesIntensity ;
107
107
108
108
109
109
var gui = new dat . GUI ( ) ;
110
- gui . add ( controls , "scanlinesIntensity" , 0 , 1 ) . onChange ( controls . updateEffectFilm ) ;
111
- gui . add ( controls , "noiseIntensity" , 0 , 3 ) . onChange ( controls . updateEffectFilm ) ;
112
- gui . add ( controls , "grayscale" ) . onChange ( controls . updateEffectFilm ) ;
113
- gui . add ( controls , "scanlinesCount" , 0 , 2048 ) . step ( 1 ) . onChange ( controls . updateEffectFilm ) ;
110
+ gui . add ( controls , "scanlinesIntensity" , 0 , 1 ) . onChange ( controls . updateEffectFilm ) ;
111
+ gui . add ( controls , "noiseIntensity" , 0 , 3 ) . onChange ( controls . updateEffectFilm ) ;
112
+ gui . add ( controls , "grayscale" ) . onChange ( controls . updateEffectFilm ) ;
113
+ gui . add ( controls , "scanlinesCount" , 0 , 2048 ) . step ( 1 ) . onChange ( controls . updateEffectFilm ) ;
114
114
115
115
// call the render function
116
- var step = 0 ;
116
+ var step = 0 ;
117
117
118
118
119
119
render ( ) ;
120
120
121
121
function createMesh ( geom ) {
122
- var planetTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/Earth.png" ) ;
123
- var specularTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/EarthSpec.png" ) ;
124
- var normalTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/EarthNormal.png" ) ;
122
+ var planetTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/Earth.png" ) ;
123
+ var specularTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/EarthSpec.png" ) ;
124
+ var normalTexture = THREE . ImageUtils . loadTexture ( "../assets/textures/planets/EarthNormal.png" ) ;
125
125
126
126
127
127
var planetMaterial = new THREE . MeshPhongMaterial ( ) ;
128
128
planetMaterial . specularMap = specularTexture ;
129
- planetMaterial . specular = new THREE . Color ( 0x4444aa ) ;
129
+ planetMaterial . specular = new THREE . Color ( 0x4444aa ) ;
130
130
131
131
132
132
planetMaterial . normalMap = normalTexture ;
135
135
136
136
137
137
// create a multimaterial
138
- var mesh = THREE . SceneUtils . createMultiMaterialObject ( geom , [ planetMaterial ] ) ;
138
+ var mesh = THREE . SceneUtils . createMultiMaterialObject ( geom , [ planetMaterial ] ) ;
139
139
140
140
return mesh ;
141
141
}
147
147
var delta = clock . getDelta ( ) ;
148
148
orbitControls . update ( delta ) ;
149
149
150
- sphere . rotation . y += 0.002 ;
150
+ sphere . rotation . y += 0.002 ;
151
151
152
152
// render using requestAnimationFrame
153
153
requestAnimationFrame ( render ) ;
165
165
stats . domElement . style . left = '0px' ;
166
166
stats . domElement . style . top = '0px' ;
167
167
168
- $ ( "#Stats-output" ) . append ( stats . domElement ) ;
168
+ $ ( "#Stats-output" ) . append ( stats . domElement ) ;
169
169
170
170
return stats ;
171
171
}
172
172
} ) ;
173
173
174
174
175
-
176
175
</ script >
177
176
</ body >
178
177
</ html >
0 commit comments