[feature] Cartoon shader improvements

Bug #1221546 reported by Juha Jeronen
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

As described on the forum:


attached is a patch containing some new features for the cartoon shader, hereby submitted for code review. The patch has been tested against Panda3D 1.8.1.


- Smoothed light/dark boundaries in light ramping. In addition to sharp thresholding as previously, a linearly interpolated transition is now supported in both single and double threshold modes. The length of the interpolation range can be adjusted (separately for both transitions in double threshold mode). This exploits the continuity of lighting values on smooth surfaces, and is not the proper way to antialias the boundaries under arbitrary circumstances, but in practice it seems to give satisfactory results.

- Light ramping now optionally affects the specular lighting contribution, too. The threshold/level/smoothing parameters for the specular component can be adjusted separately. This feature is mainly useful for anime style hair and glossy eyes (if the eyes in the character model have actual geometry).

- An "advanced ink" filter has been added to CommonFilters.py. It is based on the existing inker, but it has some new features. It accounts for the distance of each pixel from the camera (nearer = larger separation parameter -> thicker line), smooths the lines using a blur filter, and optionally the inking can be rendered into a double-sized buffer to reduce artifacts at nearly horizontal or vertical edges.

- The "cutoff" parameter of Tut-Cartoon-Advanced.py is now integrated into the inker in CommonFIlters.py, enabling users of "Basic" (autoshader) cartoon shading to take advantage of it.

Additionally, this patch contains fixes to #1214782 and #1219422. (Separate patches fixing only those bugs are available in the respective bug reports.)

- Fixed the double threshold light ramp ( https://bugs.launchpad.net/panda3d/+bug/1214782 )

- Fixed a shader generator error with some material property combinations ( https://bugs.launchpad.net/panda3d/+bug/1219422 )

Revision history for this message
Juha Jeronen (juha-jeronen) wrote :
Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

New version of patch.

- added a helper function to always allocate consecutive TEXCOORD registers, regardless of which combination of filters is enabled

- removed double resolution inking (from first patch), as it was basically useless

- added docstrings to setXXX() functions, documenting most of them. (This should probably be moved into its own patch.)

Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

Note: as part of its feature set, this patch resolves issue #497297 (cartoon shading of specular component).

Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

Updated patch. Inker rewritten to support proper antialiasing in two modes: oversample and postprocess. Line blur removed.

Now contains also an example program Tut-Cartoon-Basic-190.py, which is based on Tut-Cartoon-Basic.py. The example program shows how to use the new features.

The attached patch is designed to replace the previous one.

Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

Patch updated to include a new fast antialiasing algorithm that in most cases produces the best-looking result. This is now the default when antialias=True.

Updated example program included in the patch.

This is now the final version of the patch before Panda 1.9.0, except for possible changes required after code review.

Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

Attached is a patch containing only the light-ramping changes, affecting LightRampAttrib and ShaderGenerator. The patch adds two new features: light ramping for the specular component, and smoothing (by linear interpolation) of light/dark boundaries in lighting space.

The new inkers have been moved into the new postprocessing filter framework; see the forum thread:


To post a comment you must log in.