Toon shading model

effect is achieved by changing the normal direction to spherical (the center of the sphere is at a fairly low position). Because is not a personal project, I do not have the right to share technical details.

But the basic idea I mentioned earlier is:
Copy and paste the MaterialExpressionClearCoatNormalCustomOutput.h and change it to your own custom node. ​​​​​​​
shader side you modify Engine/Shaders/Private/ShadingModelsMaterial.ush

You can try it yourself;)

According to the existing file structure, Toon Shading model can actually be implemented as a plug-in. As long as the shader file of the Clearcoat shading model is replaced by the shader file of the Toon Shading model, it can be implemented without changing the cpp file. Of course, you will lose the Clearcoat shading model, but considering that you are already in a project that has a stylized need, that should not be a problem.

That would be incredibly useful. Also would be nice to have support for forward renderer :wink:

In the forward rendering, you can get the shadow information directly.
So complex implementations like Toon shading model may not be necessary.
At the same time, consider the lack of GBuffer, you will lose the possibility of implementing a post processing outline.
By that time, implementing outline via vertex shader can be a big issue.

It should be considered that as we are still struggling with simulate old anime, the new anime has recently gone further in lighting effects.
New anime season, “Violet Evergarden” has introduced a stylized bounce light on the character.
(And at the moment I can not find a way to do in render)

Now I’m working on stylized indirect lighting for dynamic object… and can’t find the code were indirect lighting added to dynamic object surface:confused:

Any Idea why the editor is running like a snail? The “Normal” editor works just fine.

Could you please write down the steps necessary for ?
Thank you =)

Finally find something about indirect lighting in BassPassPixelShader.usf.

Though I’m still struggling with third-order Spherical Harmonic and not able to add stylize bounce color.
I can make my shading model ignore bounce light color now.

I think it’s way tougher than just clone and compiles Toon Shading branch.

1.Look at https://github.com/EpicGames/UnrealEngine/compare/release...JSEM100:4.18.1-release-toon

2.Transfer all the diff shader code of toon shading branch to your cleatcoat shading model.

3.replace what custom pin in toon shading model did with clearcoat custom normal node(in ShadingModelsMaterial.ush)

I can also fail miserably by myself too ! :wink:

I did have a look into it but I’m not really a coder (can usually understand the syntax but fail to implement anything from scratch - visual scripting on the other hand is wonderful), so I didn’t really know where to begin. In fact as I type VS is again trying to compile the 4.19 source code after no success all day, but hopefully time I’ll have success as VS is no longer being blocked by my AV from writing the compiled .dll and .exe files.

Looking it up online I found one reference to somebody who was attempting to convert mesh normals to a spherical offset through openGL and the response to them was that the actual calculation is pretty straight forward, it was the normal - world location of the sphere.

Not entirely sure how that works since if your sphere is at 0,0,0 and your normal at say 50,50,50 then 50-0 is still 50.

My own thought of something to try would be to use BP to trace out from a static mesh sections normals to an encapsulating larger sphere, use the traces’ hit normal, reverse it and then plug that back into the normals array and finally create the new mesh - not sure if that would work how I picture in my mind and can’t test it with VS compiling anyway :slight_smile:

Do you have any reference images/videos of as the few clips I saw of when I searched , I didn’t actually spot the bounce lights (maybe I saw them and they didn’t register) but I was curious to see what new lighting you meant.

Thanks.

That is just some highschool math.

  1. normal direction of any given point on a sphere is:vertexPosition - spherePosition
  2. Then,you set a spherePos var via BP,so if you mesh is a sphere,and spherePos is just equal to it’s object position.The normal direction is obvious: vertex WorldPositon - spherePos
  3. But you know that you mesh is not a sphere,so the length of the normal vector may != 1.And you normalize it:normalize(WorldPositon - spherePos)
  4. Finally,use result to override GBuffer.WorldNormal(if you have that custom normal mat node).
  5. You can also do some lerp between vertexNormal and Calculate Normal.

3.jpg

Let me call the NEXT GEN ANIME!!!

Been trying to port to a plugin but I’m kinda of a newbie in messing with the rendering code in the engine now and I’m stuck. Can anyone help?

https://forums.unrealengine.com/development-discussion/engine-source-github/1447332-how-to-use-a-global-shader-on-a-plugin

Here we are…stylize bounce light(WIP)
stylize-bounce.jpg

Does anyone know what happened to the pull request back in the day?
the one talked about in thread ( https://forums.unrealengine.com/unre…Shading-Model= )

did the changes to plugins kill it? just asking because i saw the training stream and it was pitiful compared to . to be honest i think it is a disgrace isn’t in the engine yet.

Are they afraid of look being too easy to achieve with ? (because games using a good toon shader would not stand out as much or something like that)
Do they have a deal with another plugin and its vendor?
Can’t we do anything?

oh and by the way:

it took me much too long to find thread again for what a good solution is, so i am going to say something now:

celshading is easy in cel shading celshader , or cel-shader if you want. the shade or shadow can look like in a cartoon , anime or manga with . is easy to use and can be controlled in materials , you don’t need to create a pp-volume in unreal engine blueprints to achieve a stylized indie look with . and to beginners wanting to learn how to get free addition: just read page one and to learn how github works + help add to the engine by upvoting the pull request wherever you see it (that is if the creator is still interested after epic has ignored for about 3 years now)

They don’t need a deal. Anyone can implement since the engine source code is there for anyone to see. It is a matter to implement it yourself or anyone who want it. Day after day more and more people are learning how to write plugin code, global shaders and shader models, I do recommend people to get there too.

tl;dr , for PBR use UE4. For Stylized use Unity. You can get a new “shader model” by writing 1 single file in Unity. UE4, you have to edit at least 9 different engine files.

Arnage’s shader model is still the best one out there that’s open source. IOChair has made massive improvements to it, but that’s closed source.

He’s just wondering why Epic hasn’t made an official Toon Shader model. Anyone can implement one, sure, but no one (no matter how good you are at C++/UE4/hlsl) can implement it as easy and quick as it can be implemented in Unity. Unity’s going to get an even more flexible rendering solution soon (like the material editor) and it makes me sad…

I’ve followed and read all the tutorials and documentation out there on toon shading spanning the life of UE4. Most of that is easy to implement, but it doesn’t look great. GG and DBF arguably look the best, but what they’re doing really only works in controlled environments with very few actors (i.e., fighting games).

Btw, I’ve only used Unity for about 20 hours. UE4 4800+ hours. I got something better looking in Unity after spending 1 day. What I got in UE4 still looks worse. 4 hour build times don’t give me much incentive for enduring. I’m torn because Niagara is going to be incredible, while on the other hand stylized rendering (custom light models) is such a pain to achieve…

It’s never easy to make stylistic rendering, especially when your artist always asks for more control. And you can’t give them, because you’ve used all GBuffers.:rolleyes:
Adding new GBuffers will at least change the code of hundreds of files (which is too hard for me).

And, even worse, even if you have all the necessary mathematical programming knowledge that you need(I don’t have:confused:), it’s still very difficult to find the function you need in the huge shader file structure that lacks code annotations and help documents.

It took me a week to find the indirect light related functions of dynamic objects, and to figure out which macros in the function worked at the same time took me two days.:frowning:

Finally, about Anime style rendering, English information is so lacking (and I can’t read Japanese). It makes me wonder how many people in the world are really concerned about problem.

@IOchair.

Believe it or not there’s far more info out there on toon shader models/materials in English than there is in Japanese. The vast majority of Japanese developers don’t explain how they achieved something. They just show screenshots.

Those that do provide details don’t provide much, and the authors don’t update their info either.

Here’s a guy who looked for all the info he could find on Toon shading in UE4 (UE4のセルシェード実装方法を纏めたい - Qiita) Last updated 2017/10/14. He explains how to add a shadow color pin/parameter for a Toon Shading model (that uses forward shading). He made it in an older version, so you have to make additional changes he didn’t specify in order to get it to compile. In the end I managed to get it work, but it’s nothing special. It just simply adds a pin to change the color of shaded areas.

I understand Japanese fairly fluently so if you happened across a thread that you feel contains valuable info, by all means PM it to me. I’ll translate it so we can (edit:) ALL use it.

There is also : https://.com/JKashaar/status/946586092026892288

https://github.com/LuggLD/UnrealEngine/commit/02959bceb42aac10214008d07625d32ee52793ec

I wish someone cleaned toon shader, ported it to forward rendering so toon shading can be used in VR (mobile and desktop) and made it a plugin.