@@ -15,6 +15,7 @@ import {Entities} from "./Entities.coffee"
1515import {PlayerInInventory} from " ./PlayerInInventory.coffee"
1616import {BlockBreak} from " ./BlockBreak.coffee"
1717import {BlockPlace} from " ./BlockPlace.coffee"
18+ import {DistanceBasedFog} from " ./DistanceBasedFog.coffee"
1819
1920class Game
2021 constructor : (options )->
@@ -43,13 +44,22 @@ class Game
4344 @renderer .sortObjects = true
4445 @scene = new THREE.Scene
4546 @dimBg =
46- " minecraft:overworld" : [173 / 255 , 200 / 255 , 255 / 255 ]
47+
48+ " minecraft:overworld" : [165 / 255 , 192 / 255 , 254 / 255 ]
4749 " minecraft:the_end" : [1 / 255 , 20 / 255 , 51 / 255 ]
4850 " minecraft:the_nether" : [133 / 255 , 40 / 255 , 15 / 255 ]
4951 @camera = new THREE.PerspectiveCamera @fov , 2 , 0.1 , 1000
5052 @camera .rotation .order = " YXZ"
5153 @camera .position .set 26 , 26 , 26
5254 @scene .add new THREE.AmbientLight 0xffffff
55+ loader = new THREE.TextureLoader ()
56+ texture = loader .load (' assets/images/skybox.jpg' ,()->
57+ rt = new THREE.WebGLCubeRenderTarget (texture .image .height )
58+ rt .fromEquirectangularTexture (_this .renderer , texture)
59+ _this .rt = rt
60+ return
61+ )
62+ @distanceBasedFog = new DistanceBasedFog
5363 console .warn gpuInfo ()
5464
5565 @nick = document .location .hash .substring 1 ,document .location .hash .length
@@ -68,14 +78,16 @@ class Game
6878 document .body .appendChild @stats .dom
6979
7080 @pii = new PlayerInInventory @
71- @ent = new Entities @
7281 @bb = new BlockBreak @
7382 @bp = new BlockPlace @
7483 @world = new World @
84+ @ent = new Entities @
7585 @chat = new Chat @
76- @inv_bar = new InventoryBar @
77- @FPC = new FirstPersonControls @
78-
86+ @inv_bar = new InventoryBar @
87+ @FPC = new FirstPersonControls @
88+ @distanceBasedFog .addShaderToMaterial @world .material
89+ # @distanceBasedFog.addShaderToMaterial @ent.mobMaterial
90+ # console.log @ent.mobMaterial
7991 eventMap = {
8092 " connect " : ()->
8193 console .log " Connected to server!"
@@ -98,11 +110,14 @@ class Game
98110 console .log " Player dimension has been changed: #{ dim} "
99111 _this .world .resetWorld ()
100112 bg = _this .dimBg [dim]
101- _this .scene .background = new THREE.Color bg...
102- _this .world .ATA .uni .color .x = bg[0 ]
103- _this .world .ATA .uni .color .y = bg[1 ]
104- _this .world .ATA .uni .color .z = bg[2 ]
105- _this .world .ATA .uni .color .w = 1
113+ if dim is " minecraft:overworld"
114+ _this .scene .background = _this .rt
115+ else
116+ _this .scene .background = new THREE.Color bg...
117+ _this .distanceBasedFog .color .x = bg[0 ]
118+ _this .distanceBasedFog .color .y = bg[1 ]
119+ _this .distanceBasedFog .color .z = bg[2 ]
120+ _this .distanceBasedFog .color .w = 1
106121 return
107122 " mapChunk " : (sections ,x ,z ,biomes ,dim )->
108123 _this .world ._computeSections sections,x,z,biomes,dim
@@ -157,13 +172,13 @@ class Game
157172 gui = new dat.GUI
158173 @params =
159174 chunkdist : 3
160- @world . ATA . uni . farnear .x = (@params .chunkdist - 1.5 )* 16
161- @world . ATA . uni . farnear .y = (@params .chunkdist - 0.5 )* 16
175+ @distanceBasedFog . farnear .x = (@params .chunkdist - 1 )* 16
176+ @distanceBasedFog . farnear .y = (@params .chunkdist )* 16
162177 gui .add ( @world .material , " wireframe" ).name ( " Wireframe" ).listen ()
163178 chunkDist = gui .add ( @params , " chunkdist" ,0 ,10 ,1 ).name ( " Render distance" ).listen ()
164179 chunkDist .onChange (val)->
165- _this .world . ATA . uni . farnear .x = (val- 1.5 )* 16
166- _this .world . ATA . uni . farnear .y = (val- 0.5 )* 16
180+ _this .distanceBasedFog . farnear .x = (val- 1 )* 16
181+ _this .distanceBasedFog . farnear .y = (val)* 16
167182 console .log val
168183 return
169184 @mouse = false
@@ -211,7 +226,7 @@ class Game
211226 if @FPC .gameState is " inventory"
212227 @pii .render ()
213228 @inv_bar .tick ()
214- @world . ATA . uni .view .copy (@camera .position ).applyMatrix4 (@camera .matrixWorldInverse )
229+ @distanceBasedFog .view .copy (@camera .position ).applyMatrix4 (@camera .matrixWorldInverse )
215230 @renderer .render @scene , @camera
216231 return
217232new Game ()
0 commit comments