Skip to content

ChickenToonOutlines

Michael edited this page Oct 19, 2023 · 3 revisions

Outlines are a popular element to toon shaders, but setting them up requires a little more than the main toon shader effect.

Outlines are a post-processing effect which make use of some additional information about the scene. While this lighting itself is evaluated using forward rendering, the outlines require information about depth and normal vectors in a post-processing pass.

As such, outlines only work on devices which support Multiple Render Targets.

As with pretty much all post-processing, you're going to want to want to disable automatic drawing of the application surface by putting

application_surface_draw_enable(false);

in some Game Start event, and manually drawing it later.

cluck_mrt_create()

Returns: chickens mrt struct

Creates a bundle of MRT surfaces. Like other GameMaker surfaces, these should be freed when you're done with them using

cluck_mrt_free(cluck_mrt)

Returns: N/A

Parameter Type Description
cluck_mrt a mrt struct The Chickens MRT struct you want to get rid of

because some gamers get touchy if they see your game leaking memory.

cluck_mrt_set(cluck_mrt, main_surface*)

Returns: N/A

Parameter Type Description
cluck_mrt a mrt struct The Chickens MRT struct you want to begin writing to
main_surface surface The surface you're using as your main render target (optional, defaults to the application surface)

Bind the Chickens render targets so they can be used. Call this before you do any drawing.

You should do this before calling draw_clear(...) on your main surface, assuming you don't want the contents to be carried over from whatever you drew on them last.

cluck_mrt_clear(cluck_mrt, color*, alpha*)

Returns: N/A

Parameter Type Description
cluck_mrt a mrt struct The Chickens MRT struct you want to begin writing to
color color The color you want to clear the surfaces to (defaults to black)
alpha number The alpha you want to clear the surfaces to (defaults to 1)

Clear the Chickens MRT surfaces. Analogous to calling one of the draw_clear functions. Do this before you start drawing things with a shader that uses MRT.

cluck_apply_post(shader, cluck_mrt)

Returns: N/A

Parameter Type Description
shader shader The shader you want to use for post-processing
cluck_mrt a mrt struct The Chickens MRT struct you want to begin writing to

Call this to set the shader and relevant render inputs.

There's currently just one post-processing outline shader, shd_cluck_post_outlines. I might add more later if I get bored.

You probably want to do this in the Post Draw event, right before manually drawing the application surface:

cluck_apply_post(shd_cluck_post_outlines, self.extra_chickens_surfaces);
draw_surface_stretched(application_surface, 0, 0, window_get_width(), window_get_height());
shader_reset();

Extra parameters

There are a few extra settings you can configure for outlines.

cluck_set_toon_outline_strength(strength)

Returns: N/A

Parameter Type Description
strength number (0 to 1) The strength of the outline

Use this function to set the strength (i.e. the transparency) of the outline used with shd_cluck_post_outline. It will have no effect with shd_cluck_toon. A strength of 0 will mean the outline is not visible, and a strength of 1 will mean the outline is fully opaque.

cluck_set_toon_outline_sensitivity(sensitivity)

Returns: N/A

Parameter Type Description
sensitivity number (0 to 10ish) The sensitivity of the outline

Control the sensitivity of the outline detection. A higher value will ignore slight details, while a lower value will outline them. Use a high value if you want outlines to ignore softer edges.

A value lower than 1 will cause visual artifacts which most of you probably don't want.

I suppose this is the opposite of what "sensitivity" usually means but I couldn't think of a better name for it.

cluck_set_toon_outline_fade_distance(near, far)

Returns: N/A

Parameter Type Description
near number The distance after which outlines will start to fade off.
far number The distance after which outlines will not be visible

You probably only want nearby objects to be outlined, as outlining objects way off in the hecking distance can be a little distracting. Use this to control the minimum and maximum distances.

Clone this wiki locally