@@ -38,7 +38,6 @@ type MeshShaderProgram struct {
38
38
AlphaMap * graphics.UniformSampler
39
39
BumpMap * graphics.UniformSampler
40
40
41
- LightType * graphics.UniformInteger
42
41
LightPos * graphics.UniformVector3
43
42
LightDir * graphics.UniformVector3
44
43
AmbientLight * graphics.UniformVector3
@@ -51,7 +50,6 @@ type MeshShaderProgram struct {
51
50
DirShadowMap * graphics.UniformSampler
52
51
ShadowFar * graphics.UniformFloat
53
52
LightAttQuad * graphics.UniformFloat
54
- CastShadow * graphics.UniformBool
55
53
}
56
54
57
55
// TODO: redesign attr/uniform access system?
@@ -177,7 +175,6 @@ func NewMeshShaderProgram(defines []string) *MeshShaderProgram {
177
175
sp .AlphaMap = sp .UniformSampler ("material.alphaMap" )
178
176
sp .BumpMap = sp .UniformSampler ("material.bumpMap" )
179
177
180
- sp .LightType = sp .UniformInteger ("light.type" )
181
178
sp .LightPos = sp .UniformVector3 ("light.position" )
182
179
sp .LightDir = sp .UniformVector3 ("light.direction" )
183
180
sp .AmbientLight = sp .UniformVector3 ("light.ambient" )
@@ -190,7 +187,6 @@ func NewMeshShaderProgram(defines []string) *MeshShaderProgram {
190
187
sp .DirShadowMap = sp .UniformSampler ("dirShadowMap" )
191
188
sp .ShadowFar = sp .UniformFloat ("light.far" )
192
189
sp .LightAttQuad = sp .UniformFloat ("light.attenuationQuadratic" )
193
- sp .CastShadow = sp .UniformBool ("light.castshadow" )
194
190
195
191
sp .Position .SetFormat (gl .FLOAT , false )
196
192
sp .Normal .SetFormat (gl .FLOAT , false )
@@ -237,12 +233,14 @@ func (r *MeshRenderer) renderMesh(sp *MeshShaderProgram, m *object.Mesh, c camer
237
233
r .SetCamera (sp , c )
238
234
239
235
// TODO: cache per mesh/camera?
240
- r .normalMatrix .Identity ()
241
- r .normalMatrix .Mult (c .ViewMatrix ())
242
- r .normalMatrix .Mult (m .WorldMatrix ())
243
- r .normalMatrix .Invert ()
244
- r .normalMatrix .Transpose ()
245
- sp .NormalMatrix .Set (& r .normalMatrix )
236
+ if sp .NormalMatrix != nil {
237
+ r .normalMatrix .Identity ()
238
+ r .normalMatrix .Mult (c .ViewMatrix ())
239
+ r .normalMatrix .Mult (m .WorldMatrix ())
240
+ r .normalMatrix .Invert ()
241
+ r .normalMatrix .Transpose ()
242
+ sp .NormalMatrix .Set (& r .normalMatrix )
243
+ }
246
244
247
245
for _ , subMesh := range m .SubMeshes {
248
246
if ! c .Cull (subMesh ) {
@@ -257,8 +255,6 @@ func (r *MeshRenderer) AmbientPass(s *scene.Scene, c camera.Camera) {
257
255
r .renderState .DepthTest = graphics .LessDepthTest
258
256
r .renderState .Program = r .sp1 .ShaderProgram
259
257
260
- // TODO: WHY MUST THIS BE SET FOR AMBIENT LIGHT?!?! GRAPHICS DRIVER BUG?
261
- // TODO: FIX: AVOID BRANCHING IN SHADERS!!!!!!!!!!!!!
262
258
for _ , m := range s .Meshes {
263
259
r .renderMesh (r .sp1 , m , c )
264
260
}
@@ -268,7 +264,7 @@ func (r *MeshRenderer) LightPass(s *scene.Scene, c camera.Camera) {
268
264
r .renderState .DepthTest = graphics .EqualDepthTest
269
265
r .renderState .BlendSourceFactor = graphics .OneBlendFactor
270
266
r .renderState .BlendDestinationFactor = graphics .OneBlendFactor // add to framebuffer contents
271
- r . renderState . Program = r . sp2 . ShaderProgram
267
+
272
268
r .PointLightPass (s , c )
273
269
r .SpotLightPass (s , c )
274
270
r .DirectionalLightPass (s , c )
@@ -280,24 +276,7 @@ func (r *MeshRenderer) PointLightPass(s *scene.Scene, c camera.Camera) {
280
276
for _ , l := range s .PointLights {
281
277
r .SetPointLight (r .sp2 , l )
282
278
for _ , m := range s .Meshes {
283
- sp := r .sp2
284
- r .SetMesh (sp , m )
285
- r .SetCamera (sp , c )
286
-
287
- // TODO: cache per mesh/camera?
288
- r .normalMatrix .Identity ()
289
- r .normalMatrix .Mult (c .ViewMatrix ())
290
- r .normalMatrix .Mult (m .WorldMatrix ())
291
- r .normalMatrix .Invert ()
292
- r .normalMatrix .Transpose ()
293
- sp .NormalMatrix .Set (& r .normalMatrix )
294
-
295
- for _ , subMesh := range m .SubMeshes {
296
- if ! c .Cull (subMesh ) {
297
- r .SetSubMesh (sp , subMesh )
298
- graphics .NewRenderCommand (graphics .Triangle , subMesh .Geo .Inds , 0 , r .renderState ).Execute ()
299
- }
300
- }
279
+ r .renderMesh (r .sp2 , m , c )
301
280
}
302
281
}
303
282
}
@@ -421,17 +400,14 @@ func (r *MeshRenderer) SetSubMesh(sp *MeshShaderProgram, sm *object.SubMesh) {
421
400
}
422
401
423
402
func (r * MeshRenderer ) SetAmbientLight (sp * MeshShaderProgram , l * light.AmbientLight ) {
424
- sp .LightType .Set (0 )
425
403
sp .AmbientLight .Set (l .Color )
426
404
sp .LightAttQuad .Set (0 )
427
405
}
428
406
429
407
func (r * MeshRenderer ) SetPointLight (sp * MeshShaderProgram , l * light.PointLight ) {
430
- sp .LightType .Set (1 )
431
408
sp .LightPos .Set (l .Position )
432
409
sp .DiffuseLight .Set (l .Diffuse )
433
410
sp .SpecularLight .Set (l .Specular )
434
- sp .CastShadow .Set (l .CastShadows )
435
411
if l .CastShadows {
436
412
sp .ShadowFar .Set (l .ShadowFar )
437
413
smap , found := r .pointLightShadowMaps [l .ID ]
@@ -444,13 +420,11 @@ func (r *MeshRenderer) SetPointLight(sp *MeshShaderProgram, l *light.PointLight)
444
420
}
445
421
446
422
func (r * MeshRenderer ) SetSpotLight (sp * MeshShaderProgram , l * light.SpotLight ) {
447
- sp .LightType .Set (2 )
448
423
sp .LightPos .Set (l .Position )
449
424
sp .LightDir .Set (l .Forward ())
450
425
sp .DiffuseLight .Set (l .Diffuse )
451
426
sp .SpecularLight .Set (l .Specular )
452
427
sp .LightAttQuad .Set (l .AttenuationQuadratic )
453
- sp .CastShadow .Set (l .CastShadows )
454
428
455
429
if l .CastShadows {
456
430
sp .ShadowViewMatrix .Set (l .ViewMatrix ())
@@ -465,12 +439,10 @@ func (r *MeshRenderer) SetSpotLight(sp *MeshShaderProgram, l *light.SpotLight) {
465
439
}
466
440
467
441
func (r * MeshRenderer ) SetDirectionalLight (sp * MeshShaderProgram , l * light.DirectionalLight ) {
468
- sp .LightType .Set (3 )
469
442
sp .LightDir .Set (l .Forward ())
470
443
sp .DiffuseLight .Set (l .Diffuse )
471
444
sp .SpecularLight .Set (l .Specular )
472
445
sp .LightAttQuad .Set (0 )
473
- sp .CastShadow .Set (l .CastShadows )
474
446
475
447
if l .CastShadows {
476
448
sp .ShadowViewMatrix .Set (l .ViewMatrix ())
0 commit comments