Hi all,
An error, an investigation and an idea.
I’m getting the following error in the console when using the autoshader in Panda3D 1.8.1 with light ramping enabled:
:gobj(error): created-shader: (60) : error C1008: undefined variable "tot_diffuse"
:gobj(error): created-shader: (62) : error C1008: undefined variable "tot_diffuse"
:gobj(error): created-shader: (62) : error C1008: undefined variable "tot_diffuse"
:gobj(error): Shader encountered an error.
:gobj(error): created-shader: (70) : error C1008: undefined variable "tot_diffuse"
:gobj(error): created-shader: (72) : error C1008: undefined variable "tot_diffuse"
:gobj(error): created-shader: (72) : error C1008: undefined variable "tot_diffuse"
:gobj(error): Shader encountered an error.
Considering the possible code paths in ShaderGenerator::synthesize_shader() in panda/src/pgraphnodes/shaderGenerator.cxx, it seems there is indeed a case where “tot_diffuse” may get used without being defined, indeed related to light ramps. Consider the following:
-
“tot_diffuse” is defined if:
_separate_ambient_diffuse && _have_diffuse
or
_have_ambient || _have_diffuse -
“tot_diffuse” is used if:
!(_separate_ambient_diffuse && _have_ambient) && _have_diffuse
or
_have_diffuse
or
_auto_ramp_on
The _auto_ramp_on case does not care about _have_diffuse, _separate_ambient_diffuse and _have_ambient. Hence, if a light ramp is applied, it may occur that tot_diffuse is referred to (by the light ramp code) without being defined.
The combination of conditions suggests that the error will be triggered if a material has specular, but no ambient or diffuse. While this is unusual, it would be nice not to generate errors even in corner cases
Now, how to fix this?
Currently, the light ramping code only affects the diffuse lighting. I think that the most consistent solution would be to change the ramping to affect all lighting types (diffuse, specular, ambient), and each of those only if the relevant variable (tot_diffuse, tot_specular, tot_ambient) is defined (which is easy to track in the code that generates the definitions).
This would make the calculations for all lighting types consistent, and notably, quantization of specular highlights would be very useful for rendering anime style hair. Currently, if light ramping is enabled, having specular highlights in the materials (in my opinion) breaks the cartoon look.
I’m basically posting to ask, what do others (especially more experienced members of the community) think? Is this the way to fix the error, or should it be fixed in some other way?
And how difficult is it to compile the Panda source in Linux? I think the required modifications are pretty trivial, if I can just get a working development tree set up