Is it possible to make a custom shading model?

I see that the surface materials have various shading model options, like unlit or default lit. How can I create my own model, let’s say if I wanted to make a cell-shading material? Essentially a default lit model with rounded light direction and normal dot product.

I am sure you found it, there is some documentation here: Trying to make Toon Shader Material on UE4 - World Creation - Unreal Engine Forums

Im sure it is possible to write a plugin or something to make an actual cell shading option available… but for that… I guess someone with proper knowledge needs to reply :stuck_out_tongue:

Well, cell-shading was just an example of shading model. Ideally I would like to create my own through code instead of “hacking” through the unlit model with nodes. Currently, it is unclear how to achieve that.

/me passes a beer/or other beverage of choice

Lets hope someone from epic or another experienced person can help you out with this :slight_smile:

Hey Douglas -

As long as you have a copy of the GitHub version of the engine (which is included in your subscription - a good guide to use for setup is found here) you will be able to edit everything about and add to the engine. In the source code, we have a shaders directory where all the material instructions for rendering are kept. You would need to right your own HLSL code shader and save as a *.usf file and then go into the Engine’s C++ code and add references to the new shader where needed in the material call coding to open the shader model to the material editor.

Thank You

Eric Ketchum

Lets say Douglas does that, and makes the most awesome cellshader… would there be a chance it could be added in an actual build?

Thanks for the answer Eric, that should be enough to get started. I just wish I did not have to get a familiar with a third shading language. Luos, if I come up with something nice and re-usable I will try to push it.

Hey Luos -

Code Changes and addtions can be submitted for review by our Engineers through a GitHub pull request and as long as it follows good programming syntax, commented well and doesn’t break or possibly break another component in the engine (including causing performance related issues) we can make it a commit which will then be integrated into all future builds of the engine.

Thank You

Eric Ketchum

Hey Eric, I am going through the process of building my own version of the engine and I cannot help thinking that it feels a bit weird that I have to maintain my own version of the engine simply because I want to add a couple hand coded shaders. Is there no way to add these to my project like it is done for custom classes through the File > Add Code to Project feature?

Hey Douglas -

The distinction is what is your game and what is the game engine running your game. Shaders are always actual a part of the game engine. Epic developed the Material Editor to allow Artists to generate their own shaders based on preexisting coded shader methods and math modules. In other engines you must code each shader from scratch, which is a valid, but the Unreal Engine is about fast iteration and development and having a system to allow shaders to be rapidly developed with the material editor is a part of that process. Obviously, we don’t want to limit talented rendering and graphics programmers out their from achieving their own shader models, and in order to accommodate that we offer the source code of the engine to add in those shaders.

Thank You

Eric Ketchum

It makes sense to me as a design philosophy and I am open to be using the visual programming interface whenever possible. I suppose I am wondering if it is technically possible to recreate a default lit shading model with cast shadows from an unlit model just with the nodes?

Hey Douglas -

I am going to preface this answer with a different answer: No it is not really possible to recreate a default lit shader using just nodes.

Now, you could use a combination of Blueprints, vector parameters in your material and a lot of testing to gather basic light vectors (mostly directional based) and pass those as Vector Parameters into the Material where the math could be computational done with nodes.

You could also create an unlit material that “fakes” lighting quite easily in the material editor with just nodes, but again no lighting vector information can be shared to the material because of the deferred rendering pipeline.

Hopefully that was not too confusing,

Eric Ketchum

No actually it makes sense, especially after having started to play with the source code. Hooking the light direction into an exposed color node of the material using a blue print was my first idea but it is not going to allow me to get cast shadows and other cool things I might need. I just wish there was something I could reference for writing my own shading model since the engine code is like a maze. With a lot of “find in solution” I should get there though.