@@ -251,21 +251,21 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
251
251
alpha_source = alpha_source_specular ;
252
252
}
253
253
254
- if ( state -> ambient_src == MATERIAL_COLOR_SRC_MATERIAL ) {
255
- mstring_append_fmt ( body , "oD0 = vec4(sceneAmbientColor, %s);\n" , alpha_source );
256
- } else if ( state -> ambient_src == MATERIAL_COLOR_SRC_DIFFUSE ) {
257
- mstring_append_fmt ( body , "oD0 = vec4(diffuse.rgb, %s);\n" , alpha_source ) ;
258
- } else if ( state -> ambient_src == MATERIAL_COLOR_SRC_SPECULAR ) {
259
- mstring_append_fmt ( body , "oD0 = vec4(specular.rgb , %s);\n" , alpha_source );
260
- }
261
-
262
- mstring_append ( body , "oD0.rgb *= materialEmissionColor.rgb;\n" );
263
- if ( state -> emission_src == MATERIAL_COLOR_SRC_MATERIAL ) {
264
- mstring_append ( body , "oD0.rgb += sceneAmbientColor;\n" );
265
- } else if (state -> emission_src == MATERIAL_COLOR_SRC_DIFFUSE ) {
266
- mstring_append (body , "oD0.rgb += diffuse.rgb;\n" );
267
- } else if (state -> emission_src == MATERIAL_COLOR_SRC_SPECULAR ) {
268
- mstring_append (body , "oD0.rgb += specular.rgb;\n" );
254
+ // If emission and ambient sources are taken from a vertex color, the scene ambient color is reconstructed from
255
+ // the vertex colors.
256
+ bool use_scene_ambient =
257
+ state -> emission_src == MATERIAL_COLOR_SRC_MATERIAL || state -> ambient_src == MATERIAL_COLOR_SRC_MATERIAL ;
258
+ mstring_append_fmt ( body ,
259
+ "oD0 = vec4(%s , %s);\n" ,
260
+ use_scene_ambient ? "sceneAmbientColor" :
261
+ ( state -> emission_src == MATERIAL_COLOR_SRC_DIFFUSE ? "diffuse.rgb" : "specular.rgb" ),
262
+ alpha_source
263
+ );
264
+
265
+ if (state -> emission_src == MATERIAL_COLOR_SRC_DIFFUSE || state -> ambient_src == MATERIAL_COLOR_SRC_DIFFUSE ) {
266
+ mstring_append (body , "oD0.rgb += diffuse.rgb * materialEmissionColor ;\n" );
267
+ } else if (state -> emission_src == MATERIAL_COLOR_SRC_SPECULAR || state -> ambient_src == MATERIAL_COLOR_SRC_SPECULAR ) {
268
+ mstring_append (body , "oD0.rgb += specular.rgb * materialEmissionColor ;\n" );
269
269
}
270
270
271
271
mstring_append (body , "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n" );
@@ -370,8 +370,20 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
370
370
" vec3 lightSpecular = lightSpecularColor(%d) * attenuation * pf;\n" ,
371
371
i , i , i );
372
372
373
- mstring_append (body ,
374
- " oD0.xyz += lightAmbient;\n" );
373
+ switch (state -> ambient_src ) {
374
+ case MATERIAL_COLOR_SRC_MATERIAL :
375
+ mstring_append (body ,
376
+ " oD0.rgb += lightAmbient;\n" );
377
+ break ;
378
+ case MATERIAL_COLOR_SRC_DIFFUSE :
379
+ mstring_append (body ,
380
+ " oD0.rgb += diffuse.rgb * lightAmbient;\n" );
381
+ break ;
382
+ case MATERIAL_COLOR_SRC_SPECULAR :
383
+ mstring_append (body ,
384
+ " oD0.rgb += specular.rgb * lightAmbient;\n" );
385
+ break ;
386
+ }
375
387
376
388
switch (state -> diffuse_src ) {
377
389
case MATERIAL_COLOR_SRC_MATERIAL :
0 commit comments