@@ -5,8 +5,6 @@ var container, stats;
55var camera , scene , renderer , cameraControls , shader = null ;
66var uniforms ;
77
8- var TEX_RES = 2 * 1024 ;
9-
108function Shader ( mustacheTemplate ) {
119 // Compile-time shader parameters
1210 this . parameters = {
@@ -65,44 +63,13 @@ function degToRad(a) { return Math.PI * a / 180.0; }
6563 checkLoaded ( ) ;
6664 } ) ;
6765
68- texLoader . load ( 'img/moon_1024.jpg' , function ( tex ) {
69- textures . moon = tex ;
70- checkLoaded ( ) ;
71- } ) ;
72-
73- textures . accretion_disk = renderDataTexture ( TEX_RES , TEX_RES / 4 , accretionDiskTexture1D ) ;
74- textures . stars = renderDataTexture ( TEX_RES * 2 , TEX_RES , starBackgroundTexture ) ;
66+ textures . moon = ProceduralTextures . beachBall ( ) ;
67+ textures . accretion_disk = ProceduralTextures . accretionDisk ( ) ;
68+ textures . stars = ProceduralTextures . starBackground ( ) ;
7569
7670 checkLoaded ( ) ;
7771} ) ( ) ;
7872
79- function renderDataTexture ( width , height , renderer ) {
80- // Generate random noise texture
81- var size = width * height ;
82- var data = new Uint8Array ( 3 * size ) ;
83-
84- function to8bit ( f ) {
85- return Math . round ( Math . max ( 0 , Math . min ( f , 1.0 ) ) * 255 ) ;
86- }
87-
88- var i = 0 ;
89- for ( var y = 0 ; y < height ; y ++ ) {
90- for ( var x = 0 ; x < width ; x ++ ) {
91- var col = renderer ( x / width , y / height ) ;
92- data [ i ++ ] = to8bit ( col . r ) ;
93- data [ i ++ ] = to8bit ( col . g ) ;
94- data [ i ++ ] = to8bit ( col . b ) ;
95- }
96- }
97-
98- var dt = new THREE . DataTexture ( data , width , height , THREE . RGBFormat ) ;
99- dt . magFilter = THREE . LinearFilter ;
100- dt . minFilter = THREE . LinearFilter ;
101- dt . needsUpdate = true ;
102-
103- return dt ;
104- }
105-
10673function init ( textures ) {
10774
10875 container = document . createElement ( 'div' ) ;
@@ -195,27 +162,6 @@ function setupGUI() {
195162 gui . add ( shader . parameters , 'time_scale' ) . min ( 0 ) ;
196163}
197164
198- function starBackgroundTexture ( x , y ) {
199-
200- var prob = 5.0 / TEX_RES ;
201- prob *= Math . cos ( ( y - 0.5 ) * Math . PI ) ;
202-
203- var s = Math . random ( ) ;
204-
205- if ( s < prob ) {
206- s /= prob ;
207- return { r : s , g : s , b : s } ;
208- }
209-
210- return { r : 0 , g : 0 , b : 0 } ;
211- }
212-
213- function accretionDiskTexture1D ( x , y ) {
214- var s = x * Math . exp ( - x * 4.0 ) * ( 1.0 - x ) * Math . pow ( ( Math . sin ( x * Math . PI * 20 ) + 1.0 ) * 0.5 , 0.1 ) * 20.0 ;
215- if ( Math . ceil ( y * 50 ) % 2 === 0 ) s *= 0.7 ;
216- return { r : s , g : s * 0.8 , b : s * 0.5 } ;
217- }
218-
219165function onWindowResize ( event ) {
220166
221167 renderer . setSize ( window . innerWidth , window . innerHeight ) ;
0 commit comments