@@ -265,12 +265,7 @@ analyze_renderstate(const RenderState *rs) {
265
265
266
266
const MaterialAttrib *material;
267
267
rs->get_attrib_def (material);
268
-
269
- if (!material->is_off ()) {
270
- _material = material->get_material ();
271
- } else {
272
- _material = Material::get_default ();
273
- }
268
+ _material_flags = material->get_material_flags ();
274
269
275
270
// Break out the lights by type.
276
271
@@ -285,14 +280,7 @@ analyze_renderstate(const RenderState *rs) {
285
280
nassertv (light_obj != (PandaNode *)NULL );
286
281
287
282
if (light_obj->is_ambient_light ()) {
288
- if (_material->has_ambient ()) {
289
- LColor a = _material->get_ambient ();
290
- if ((a[0 ]!=0.0 )||(a[1 ]!=0.0 )||(a[2 ]!=0.0 )) {
291
- _have_ambient = true ;
292
- }
293
- } else {
294
- _have_ambient = true ;
295
- }
283
+ _have_ambient = true ;
296
284
_lighting = true ;
297
285
298
286
} else if (light_obj->is_of_type (LightLensNode::get_class_type ())) {
@@ -369,29 +357,16 @@ analyze_renderstate(const RenderState *rs) {
369
357
// Decide which material modes need to be calculated.
370
358
371
359
if (_lighting) {
372
- if (_material->has_diffuse ()) {
373
- LColor d = _material->get_diffuse ();
374
- if ((d[0 ]!=0.0 )||(d[1 ]!=0.0 )||(d[2 ]!=0.0 )) {
375
- _have_diffuse = true ;
376
- }
377
- } else {
378
- _have_diffuse = true ;
379
- }
360
+ _have_diffuse = true ;
380
361
}
381
362
382
- if (_lighting && (_material->has_emission ())) {
383
- LColor e = _material->get_emission ();
384
- if ((e[0 ]!=0.0 )||(e[1 ]!=0.0 )||(e[2 ]!=0.0 )) {
385
- _have_emission = true ;
386
- }
363
+ if (_lighting && (_material_flags & Material::F_emission) != 0 ) {
364
+ _have_emission = true ;
387
365
}
388
366
389
367
if (_lighting) {
390
- if (_material->has_specular ()) {
391
- LColor s = _material->get_specular ();
392
- if ((s[0 ]!=0.0 )||(s[1 ]!=0.0 )||(s[2 ]!=0.0 )) {
393
- _have_specular = true ;
394
- }
368
+ if (_material_flags & Material::F_specular) {
369
+ _have_specular = true ;
395
370
} else if (_map_index_gloss >= 0 ) {
396
371
_have_specular = true ;
397
372
}
@@ -402,14 +377,10 @@ analyze_renderstate(const RenderState *rs) {
402
377
// Decide whether to separate ambient and diffuse calculations.
403
378
404
379
if (_have_ambient && _have_diffuse) {
405
- if (_material->has_ambient ()) {
406
- if (_material->has_diffuse ()) {
407
- _separate_ambient_diffuse = _material->get_ambient () != _material->get_diffuse ();
408
- } else {
409
- _separate_ambient_diffuse = true ;
410
- }
380
+ if (_material_flags & Material::F_ambient) {
381
+ _separate_ambient_diffuse = true ;
411
382
} else {
412
- if (_material-> has_diffuse () ) {
383
+ if (_material_flags & Material::F_diffuse ) {
413
384
_separate_ambient_diffuse = true ;
414
385
} else {
415
386
_separate_ambient_diffuse = false ;
@@ -431,10 +402,10 @@ analyze_renderstate(const RenderState *rs) {
431
402
// Does the shader need material properties as input?
432
403
433
404
_need_material_props =
434
- (_have_ambient && (_material-> has_ambient ())) ||
435
- (_have_diffuse && (_material-> has_diffuse ())) ||
436
- (_have_emission && (_material-> has_emission ())) ||
437
- (_have_specular && (_material-> has_specular ()) );
405
+ (_have_ambient && (_material_flags & Material::F_ambient) != 0 ) ||
406
+ (_have_diffuse && (_material_flags & Material::F_diffuse) != 0 ) ||
407
+ (_have_emission && (_material_flags & Material::F_emission) != 0 ) ||
408
+ (_have_specular && (_material_flags & Material::F_specular) != 0 );
438
409
439
410
// Check for clip planes.
440
411
@@ -494,7 +465,7 @@ clear_analysis() {
494
465
_out_aux_normal = false ;
495
466
_out_aux_glow = false ;
496
467
_out_aux_any = false ;
497
- _material = (Material*) NULL ;
468
+ _material_flags = 0 ;
498
469
_need_material_props = false ;
499
470
_need_world_position = false ;
500
471
_need_world_normal = false ;
@@ -867,7 +838,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
867
838
text << " \t uniform float4x4 attr_material,\n " ;
868
839
}
869
840
if (_have_specular) {
870
- if (_material-> get_local () ) {
841
+ if (_material_flags & Material::F_local ) {
871
842
text << " \t uniform float4 mspos_view,\n " ;
872
843
} else {
873
844
text << " \t uniform float4 row1_view_to_model,\n " ;
@@ -1041,7 +1012,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1041
1012
}
1042
1013
if (_have_specular) {
1043
1014
text << " \t float4 tot_specular = float4(0,0,0,0);\n " ;
1044
- if (_material-> has_specular () ) {
1015
+ if (_material_flags & Material::F_specular ) {
1045
1016
text << " \t float shininess = attr_material[3].w;\n " ;
1046
1017
} else {
1047
1018
text << " \t float shininess = 50; // no shininess specified, using default\n " ;
@@ -1073,7 +1044,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1073
1044
text << " \t tot_diffuse += lcolor;\n " ;
1074
1045
}
1075
1046
if (_have_specular) {
1076
- if (_material-> get_local () ) {
1047
+ if (_material_flags & Material::F_local ) {
1077
1048
text << " \t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n " ;
1078
1049
} else {
1079
1050
text << " \t lhalf = dlight_light" << i << " _rel_view[3].xyz;\n " ;
@@ -1103,7 +1074,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1103
1074
text << " \t tot_diffuse += lcolor;\n " ;
1104
1075
}
1105
1076
if (_have_specular) {
1106
- if (_material-> get_local () ) {
1077
+ if (_material_flags & Material::F_local ) {
1107
1078
text << " \t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n " ;
1108
1079
} else {
1109
1080
text << " \t lhalf = normalize(lvec - float3(0, 1, 0));\n " ;
@@ -1141,7 +1112,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1141
1112
text << " \t tot_diffuse += lcolor;\n " ;
1142
1113
}
1143
1114
if (_have_specular) {
1144
- if (_material-> get_local () ) {
1115
+ if (_material_flags & Material::F_local ) {
1145
1116
text << " \t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n " ;
1146
1117
} else {
1147
1118
text << " \t lhalf = normalize(lvec - float3(0,1,0));\n " ;
@@ -1199,7 +1170,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1199
1170
}
1200
1171
}
1201
1172
if ((_have_ambient)&&(_separate_ambient_diffuse)) {
1202
- if (_material-> has_ambient () ) {
1173
+ if (_material_flags & Material::F_ambient ) {
1203
1174
text << " \t result += tot_ambient * attr_material[0];\n " ;
1204
1175
} else if (_vertex_colors) {
1205
1176
text << " \t result += tot_ambient * l_color;\n " ;
@@ -1210,7 +1181,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1210
1181
}
1211
1182
}
1212
1183
if (_have_diffuse) {
1213
- if (_material-> has_diffuse () ) {
1184
+ if (_material_flags & Material::F_diffuse ) {
1214
1185
text << " \t result += tot_diffuse * attr_material[1];\n " ;
1215
1186
} else if (_vertex_colors) {
1216
1187
text << " \t result += tot_diffuse * l_color;\n " ;
@@ -1389,7 +1360,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
1389
1360
1390
1361
if (_lighting) {
1391
1362
if (_have_specular) {
1392
- if (_material-> has_specular () ) {
1363
+ if (_material_flags & Material::F_specular ) {
1393
1364
text << " \t tot_specular *= attr_material[3];\n " ;
1394
1365
}
1395
1366
if (_map_index_gloss >= 0 && _auto_gloss_on) {
0 commit comments