A Godot plugin to interact with the toon shader

If you followed the toon shader tutorial, you’d know that deferred rendering can be a powerful tool to re-use render data. But when there’s a difference between the deferred data and the main view, it doesn’t look right until you run the game. This makes editing a toon character’s material tricky. It requires setting the game resolution to your viewport; or your viewport to your game resolution and then looking at the scene from the camera’s eye.

But we can fix this. The editor runs in the Godot engine, which means the editor’s camera has a global_transform running in a Viewport with its resolution. We can take the information and control the viewport cameras when in the editor, and let the game act as normal when out of the editor.

Tools and editor plugins

Here are the tools we’ll build and the problems they’ll solve.

Scene Builder

We create a special node that automatically creates viewport containers and viewports when added to the scene. It also holds data that other tools use to refer to those viewports.

Proxy Builder

We create another node that automatically creates duplicates, assigns them the diffuse and specular materials, and connects remote transforms on the original when added to an object like a light, camera, or mesh instance in the scene.

Camera Controller

We create an editor plugin that finds and takes control of the cameras in the viewports to match the editor’s camera and sets the viewport’s resolution to the editor’s. This turns off when starting the game, so it looks correct in the editor and the game.

Custom Inspector Button

We use the plugin API to add a custom button to the inspector. When pressed, all mesh instances that use the toon shader will have their viewport textures set to the light and specular data.

Building the plugin

To create a plugin in Godot, you need specific files and a particular folder structure. Follow these steps:

  1. Navigate to the Project Settings and go to the Plugins tab.
  2. Tap the Create button
  3. Fill in required information:

Hit create to make Godot create an “addons” folder with a subfolder for your plugin. Add a new subfolder in it called “Tools”.