@@ -8,14 +8,13 @@ import {
8
8
Canvas ,
9
9
Context ,
10
10
DefaultFramebuffer ,
11
+ EnvironmentRenderingPass ,
12
+ EnvironmentTextureType ,
11
13
EventProvider ,
12
14
Framebuffer ,
13
15
Invalidate ,
14
16
Navigation ,
15
- NdcFillingTriangle ,
16
- Program ,
17
17
Renderer ,
18
- Shader ,
19
18
Texture2D ,
20
19
TextureCube ,
21
20
Wizard ,
@@ -29,8 +28,7 @@ class EnvironmentProjectionRenderer extends Renderer {
29
28
30
29
protected _defaultFBO : Framebuffer ;
31
30
32
- protected _ndcTriangle : NdcFillingTriangle ;
33
- protected _program : Program ;
31
+ protected _environmentRenderingPass : EnvironmentRenderingPass ;
34
32
35
33
protected _cubeMap : TextureCube ;
36
34
protected _equiRectangularMap : Texture2D ;
@@ -40,12 +38,6 @@ class EnvironmentProjectionRenderer extends Renderer {
40
38
protected _camera : Camera ;
41
39
protected _navigation : Navigation ;
42
40
43
- protected _uViewProjection : WebGLUniformLocation ;
44
- protected _uViewProjectionInverse : WebGLUniformLocation ;
45
-
46
- protected _uViewport : WebGLUniformLocation ;
47
- protected _uTime : WebGLUniformLocation ;
48
- protected _uMode : WebGLUniformLocation ;
49
41
50
42
protected onInitialize ( context : Context ,
51
43
callback : Invalidate ,
@@ -60,38 +52,8 @@ class EnvironmentProjectionRenderer extends Renderer {
60
52
this . _defaultFBO . initialize ( ) ;
61
53
this . _defaultFBO . bind ( ) ;
62
54
63
- const gl = this . _context . gl ;
64
-
65
- this . _ndcTriangle = new NdcFillingTriangle ( this . _context , 'NdcFillingTriangle' ) ;
66
- this . _ndcTriangle . initialize ( ) ;
67
-
68
55
this . fetchTextures ( ) ;
69
56
70
- // Initialize program and uniforms
71
- const vert = new Shader ( this . _context , gl . VERTEX_SHADER , 'ndcvertices' ) ;
72
- vert . initialize ( require ( './data/env-projections.vert' ) ) ;
73
-
74
- const frag = new Shader ( this . _context , gl . FRAGMENT_SHADER , 'env-projections' ) ;
75
- frag . initialize ( require ( './data/env-projections.frag' ) ) ;
76
-
77
- this . _program = new Program ( this . _context , 'EnvProjectionsProgram' ) ;
78
- this . _program . initialize ( [ vert , frag ] , false ) ;
79
-
80
- this . _program . attribute ( 'a_vertex' , this . _ndcTriangle . vertexLocation ) ;
81
- this . _program . link ( ) ;
82
-
83
- this . _program . bind ( ) ;
84
- gl . uniform1i ( this . _program . uniform ( 'u_cubemap' ) , 0 ) ;
85
- gl . uniform1i ( this . _program . uniform ( 'u_equirectmap' ) , 1 ) ;
86
- gl . uniform1i ( this . _program . uniform ( 'u_spheremap' ) , 2 ) ;
87
- gl . uniform1iv ( this . _program . uniform ( 'u_polarmap' ) , [ 3 , 4 ] ) ;
88
-
89
- this . _uViewProjection = this . _program . uniform ( 'u_viewProjection' ) ;
90
- this . _uViewProjectionInverse = this . _program . uniform ( 'u_viewProjectionInverse' ) ;
91
- this . _uViewport = this . _program . uniform ( 'u_viewport' ) ;
92
- this . _uTime = this . _program . uniform ( 'u_time' ) ;
93
- this . _uMode = this . _program . uniform ( 'u_mode' ) ;
94
-
95
57
// Initialize camera
96
58
this . _camera = new Camera ( ) ;
97
59
this . _camera . eye = vec3 . fromValues ( 0.0 , 0.5 , - 1.0 ) ;
@@ -103,7 +65,9 @@ class EnvironmentProjectionRenderer extends Renderer {
103
65
this . _navigation = new Navigation ( callback , eventProvider . mouseEventProvider ! ) ;
104
66
this . _navigation . camera = this . _camera ;
105
67
106
- gl . uniform2iv ( this . _uViewport , this . _canvasSize ) ;
68
+ this . _environmentRenderingPass = new EnvironmentRenderingPass ( this . _context ) ;
69
+ this . _environmentRenderingPass . initialize ( ) ;
70
+ this . _environmentRenderingPass . camera = this . _camera ;
107
71
108
72
return true ;
109
73
}
@@ -142,63 +106,48 @@ class EnvironmentProjectionRenderer extends Renderer {
142
106
143
107
this . _defaultFBO . clear ( gl . COLOR_BUFFER_BIT | gl . DEPTH_BUFFER_BIT , false , false ) ;
144
108
145
- this . _cubeMap . bind ( gl . TEXTURE0 ) ;
146
- this . _equiRectangularMap . bind ( gl . TEXTURE1 ) ;
147
- this . _sphereMap . bind ( gl . TEXTURE2 ) ;
148
- this . _polarMaps [ 0 ] . bind ( gl . TEXTURE3 ) ;
149
- this . _polarMaps [ 1 ] . bind ( gl . TEXTURE4 ) ;
150
- this . _program . bind ( ) ;
151
-
152
- gl . uniform2iv ( this . _uViewport , this . _canvasSize ) ;
153
- gl . uniformMatrix4fv ( this . _uViewProjection , false , this . _camera . viewProjection ) ;
154
- gl . uniformMatrix4fv ( this . _uViewProjectionInverse , false , this . _camera . viewProjectionInverse ) ;
155
-
156
- const t = ( ( new Date ( ) ) . getTime ( ) % 10000000 ) * 0.001 ;
157
- gl . uniform1f ( this . _uTime , t ) ;
158
-
159
- this . _ndcTriangle . bind ( ) ;
160
-
161
109
const b = 1.0 ;
162
110
const w = ( this . _frameSize [ 0 ] - ( 4.0 - 1.0 ) * b ) / 4.0 ;
163
111
const h = this . _frameSize [ 1 ] ;
164
112
165
113
gl . enable ( gl . SCISSOR_TEST ) ;
166
114
115
+ // Sphere Map
167
116
gl . scissor ( ( w + b ) * 0.0 , 0 , w , h ) ;
168
- gl . uniform1i ( this . _uMode , 2 ) ; // sphere map
169
- this . _ndcTriangle . draw ( ) ;
117
+ this . _environmentRenderingPass . environmentTexture = this . _sphereMap ;
118
+ this . _environmentRenderingPass . environmentTextureType = EnvironmentTextureType . SphereMap ;
119
+ this . _environmentRenderingPass . frame ( ) ;
170
120
121
+ // Equirectangular Map
171
122
gl . scissor ( ( w + b ) * 1.0 , 0 , w , h ) ;
172
- gl . uniform1i ( this . _uMode , 1 ) ; // equirectangular map
173
- this . _ndcTriangle . draw ( ) ;
123
+ this . _environmentRenderingPass . environmentTexture = this . _equiRectangularMap ;
124
+ this . _environmentRenderingPass . environmentTextureType = EnvironmentTextureType . EquirectangularMap ;
125
+ this . _environmentRenderingPass . frame ( ) ;
174
126
127
+ // Cube map
175
128
gl . scissor ( ( w + b ) * 2.0 , 0 , w , h ) ;
176
- gl . uniform1i ( this . _uMode , 0 ) ; // cube map
177
- this . _ndcTriangle . draw ( ) ;
129
+ this . _environmentRenderingPass . environmentTexture = this . _cubeMap ;
130
+ this . _environmentRenderingPass . environmentTextureType = EnvironmentTextureType . CubeMap ;
131
+ this . _environmentRenderingPass . frame ( ) ;
178
132
179
133
gl . scissor ( ( w + b ) * 3.0 , 0 , w , h ) ;
180
- gl . uniform1i ( this . _uMode , 3 ) ; // dual paraboloid map
181
- this . _ndcTriangle . draw ( ) ;
134
+ this . _environmentRenderingPass . environmentTexture = this . _polarMaps [ 0 ] ;
135
+ this . _environmentRenderingPass . environmentTexture2 = this . _polarMaps [ 1 ] ;
136
+ this . _environmentRenderingPass . environmentTextureType = EnvironmentTextureType . PolarMap ;
137
+ this . _environmentRenderingPass . frame ( ) ;
182
138
183
139
gl . disable ( gl . SCISSOR_TEST ) ;
184
-
185
- this . _ndcTriangle . unbind ( ) ;
186
-
187
- this . _program . unbind ( ) ;
188
140
}
189
141
190
142
protected onSwap ( ) : void {
191
143
this . invalidate ( ) ;
192
144
}
193
145
194
- protected setupTexture2D ( texture : Texture2D , unit : number ) : void {
146
+ protected setupTexture2D ( texture : Texture2D ) : void {
195
147
const gl = this . _context . gl ;
196
148
197
- texture . bind ( unit ) ;
198
- // gl.generateMipmap(gl.TEXTURE_2D);
199
-
200
- texture . wrap ( gl . REPEAT , gl . REPEAT , false , false ) ;
201
- texture . filter ( gl . NEAREST , gl . NEAREST , false , false ) ;
149
+ texture . wrap ( gl . REPEAT , gl . REPEAT , true , false ) ;
150
+ texture . filter ( gl . NEAREST , gl . NEAREST , false , true ) ;
202
151
203
152
this . invalidate ( true ) ;
204
153
}
@@ -231,7 +180,7 @@ class EnvironmentProjectionRenderer extends Renderer {
231
180
232
181
promises . push (
233
182
this . _equiRectangularMap . fetch ( 'data/equirectangular-map.jpg' ) . then ( ( ) => {
234
- this . setupTexture2D ( this . _equiRectangularMap , gl . TEXTURE1 ) ;
183
+ this . setupTexture2D ( this . _equiRectangularMap ) ;
235
184
} ) ) ;
236
185
237
186
@@ -240,7 +189,7 @@ class EnvironmentProjectionRenderer extends Renderer {
240
189
241
190
promises . push (
242
191
this . _sphereMap . fetch ( 'data/sphere-map-ny.jpg' ) . then ( ( ) => {
243
- this . setupTexture2D ( this . _sphereMap , gl . TEXTURE2 ) ;
192
+ this . setupTexture2D ( this . _sphereMap ) ;
244
193
} ) ) ;
245
194
246
195
@@ -250,7 +199,7 @@ class EnvironmentProjectionRenderer extends Renderer {
250
199
251
200
promises . push (
252
201
this . _polarMaps [ 0 ] . fetch ( 'data/paraboloid-map-py.jpg' ) . then ( ( ) => {
253
- this . setupTexture2D ( this . _polarMaps [ 0 ] , gl . TEXTURE3 ) ;
202
+ this . setupTexture2D ( this . _polarMaps [ 0 ] ) ;
254
203
} ) ) ;
255
204
256
205
@@ -259,7 +208,7 @@ class EnvironmentProjectionRenderer extends Renderer {
259
208
260
209
promises . push (
261
210
this . _polarMaps [ 1 ] . fetch ( 'data/paraboloid-map-ny.jpg' ) . then ( ( ) => {
262
- this . setupTexture2D ( this . _polarMaps [ 1 ] , gl . TEXTURE4 ) ;
211
+ this . setupTexture2D ( this . _polarMaps [ 1 ] ) ;
263
212
} ) ) ;
264
213
265
214
Promise . all ( promises ) . then ( ( ) => {
0 commit comments