Strumpy Shader Editor [Now Open Source]

Unity Technologies

I have been a bit bored after work for the past few weeks and my Unity3 beta arrived so I decided to make a shader editor.

I approached the task initially to see just how extensible the Editor API's were and to see if it could be done (fully featured and at a commercial standard). And after an evening or two I was knee deep in the unity3 codebase!

There were a few things I wanted to do when making this editor:
*High quality standard
*Rich feedback to the user
*Realtime previews of the current shader
*Loading / saving of graphs
*Shader export
*Complete support for the unity3 materials system (That aras and co have done an amazing job of!)
*Fits into the unity design principles. Easy to use / simple / 'just works' - this was very important to me!

Neat. Unity really needs something like this so that more people can harness the power of shaders without having to be an advanced programmer.

What would really make this great, besides all those millions of functions you have built in, is to have `presents` or `templates` of various little pieces of typical shaders that you can just drag and plug in without having to start from scratch.

These confuse me. I never bothered to learn them. But, what exactly DO these node base editors do?

Click to expand...

if you had the chance before to write shaders then you will understand why these node based editors are a must. Instead of worrying about syntax and hell of coding you just drag, drop and link ur nodes and ur off to go.

The only things I would actually change are to make the linear node links turned into ease in/out links, and have a node property preview displayed on the node (like how the unreal engine mat editor does it). Can't wait for the open beta, you're saving us from shader coding hell.

CC: The Unreal Engine has a mat editor that uses node based shader programming. It's because of this that games like Unreal Tournament 3 have such incredible shaders. Because they're so easy to make. I played around with the editor in Unreal and was able to edit the shaders and make new, completely different ones on my first try using it. Couldn't have done that to save my life in shaderlab.

Needless to say, I want this in Unity.

P.S. Please be sure the beta (in whatever stage it's in) actually does come out. So that way we at least have something to extend should you cease to work on it (for whatever reason). I only say this because Kurt's shader editor is stuck in development hell (like zjp points out) and he never posted a beta for us to continue. :?

Unity Technologies

Thanks for all the kind words everyone. It's great to hear that you think you will find this useful!

brokenpoly said:

Wowzer!
Been following your development for a little while now must say I`m extremely impressed Really looking forward to giving it a try soon!

Keep up the great work!

Click to expand...

Thanks. For the most part I've found working with the unity API's to be great, although I did encounter a few API limitations and idiosyncrasies while I was working.

ImaginaryHuman said:

Neat. Unity really needs something like this so that more people can harness the power of shaders without having to be an advanced programmer.

What would really make this great, besides all those millions of functions you have built in, is to have `presents` or `templates` of various little pieces of typical shaders that you can just drag and plug in without having to start from scratch.

Click to expand...

The node API is really easy to expand if you know how to program in c#. There are a few 'functions' built in that are non standard (like the UV pan, swizzle, and splat). And I intend to add more / do some tutorials on how to add custom nodes.

niosop said:

Excellent job, this will make tweaking simple surface shaders much easier for most users.

Is it fairly simple to add new node types? If you're not selling this, make sure to put up a donate button somewhere, I'm sure lots of people would like to thank you.

Click to expand...

Very simple to add new node types. I designed it specifically to be easily extensible. You just have to inherit off 'Node' or 'InputNode' ect and implement the interface. There is some field markup required for serialization / getting the node in the nodes lists. But it's quite trivial.

dreamora said:

Looks nice

Will be interesting to see where its going to keep shader model restrictions and alike in mind but its definitely a solid base already at least from the visual look

Click to expand...

Currently is uses the basic unity3 lighitng with a slightly modified lighting shader. I plan to add support for custom lighting shaders ect, that will probably be in beta 3 though.

CreativeCoding said:

These confuse me. I never bothered to learn them. But, what exactly DO these node base editors do?

Click to expand...

They make the creation of shaders a content / art task instead of a programming task. This isn't always so (ie some specific hand crafted shaders for post processing ect). But in general I think it's a fair statement. I have seen some amazing shaders generated in graph editors. But I have also seen some abominations. It's all dependent on the skill of the artist.

theinfomercial said:

Yes!

The only things I would actually change are to make the linear node links turned into ease in/out links, and have a node property preview displayed on the node (like how the unreal engine mat editor does it). Can't wait for the open beta, you're saving us from shader coding hell.

Click to expand...

I want to use bezier handles for the lines, it's something I still have to add in though.

I currently don't have plans to display the default texture / color on the node. This could be added pretty easily but I think it's a bit confusing. Unlike unreal in unity shader textures / inputs are frequently overridden (via a material or the preview node in this case). I think it adds a level of complexity that I was trying to avoid. I could be convinced otherwise though.

CC: The Unreal Engine has a mat editor that uses node based shader programming. It's because of this that games like Unreal Tournament 3 have such incredible shaders. Because they're so easy to make. I played around with the editor in Unreal and was able to edit the shaders and make new, completely different ones on my first try using it. Couldn't have done that to save my life in shaderlab.

Needless to say, I want this in Unity.

Click to expand...

It think the reason that unreal's shaders look so good isn't because of the material editor per se, but by the number of people using it / it's use in AAA games.

P.S. Please be sure the beta (in whatever stage it's in) actually does come out. So that way we at least have something to extend should you cease to work on it (for whatever reason). I only say this because Kurt's shader editor is stuck in development hell (like zjp points out) and he never posted a beta for us to continue. :?

Click to expand...

The code for the beta is done, unless I come across any crazy show stoppers. I haven't released it yet because there is no documentation. I don't think I will write too much, but a simple tutorial and some other simple stuff would be nice!

I currently don't have plans to display the default texture / color on the node. This could be added pretty easily but I think it's a bit confusing. Unlike unreal in unity shader textures / inputs are frequently overridden (via a material or the preview node in this case). I think it adds a level of complexity that I was trying to avoid. I could be convinced otherwise though.

Click to expand...

I don't think it would confusing, and personally it would be very helpful in debugging. Once shaders become fairly complex, it may sometimes be difficult to keep track of what is going on, especially if you're making changes to an older shader. Its nice to see which texture is coming in where, as well as. Even nice would be to have small icons for representation of each node. Just for the sake of getting a quick overview of the shader. That would probably be some more work however. Simple shaders it really doesn't matter, just a thought for once they start filling up.

That is very nice work, especially for the time you've put into it. If you like, I have a color correction matrix constructor that could be a nice addition, basically a component that gives you a bunch of color correction options that end up just one matrix multiply in the shader. It's quite useful in conjunction with Unity's animation system.

Unity Technologies

I think optimally, also for performance, would be if you had a second (toggle) button on the node which either shows the previous as overlay or expands the node to include the preview.

I agree that having all on preview mode can be very confusing especially as it means that you need to provide input textures too to make any sense.

Click to expand...

That's a good approach to it if I was to implement a preview for input types. The problem I have is that I consider the generated shaders to not be 'game specific' so if you set a default texture to be 'my customtexture' what happens if you then share this shader with another developer or the resource is deleted. There is no way for the unity shader system to know about this (it will default to black) but this isn't desirable I do not want the shaders that are generated to be dependent on content.

There has to be a comfortable mid ground on this issue and I'm still mentally trying to reconcile a few other things to support in this area as well. I do think something needs to be done, I just want to do the right thing from a usability perspective.

Unity Technologies

That is very nice work, especially for the time you've put into it. If you like, I have a color correction matrix constructor that could be a nice addition, basically a component that gives you a bunch of color correction options that end up just one matrix multiply in the shader. It's quite useful in conjunction with Unity's animation system.

Click to expand...

Thats really cool. What I think a better idea is then me just going and creating a node for it is that when I release this you have a go with the given API's to create the node. It will give me some valuable feedback in that area so that I can improve it! (Currently there is no matrix input node / type support, I have that planned for Beta2).

That's a good approach to it if I was to implement a preview for input types. The problem I have is that I consider the generated shaders to not be 'game specific' so if you set a default texture to be 'my customtexture' what happens if you then share this shader with another developer or the resource is deleted. There is no way for the unity shader system to know about this (it will default to black) but this isn't desirable I do not want the shaders that are generated to be dependent on content.

Click to expand...

Thats the problem I see too.
On the other hand, shaders are always kind of task specific so comparable textures should lead to a comparable result unless the shaders had hard color inputs so that should be of a smaller concern.

stramit said:

There has to be a comfortable mid ground on this issue and I'm still mentally trying to reconcile a few other things to support in this area as well. I do think something needs to be done, I just want to do the right thing from a usability perspective.

Unity Technologies

3 demo graphs are included (I will add more as time goes on). You should have a look at these to see how everything hooks up. There is currently:
-A rim lighting shader
-A normal map shader
-A UV pan shader

This will only work with unity3, and there are a few known issues, which I will list in a minute.

Installation
1)Download the unity package attached to this post
2)Open a fresh unity3 project (it should work in a non frosh project as well, but back it up first!)
3)Import the package into unity. Ensure you import ALL the assets (assets->import package)
4) In the windows menu there will be a new entry: 'Shader Editor'. Click this to launch the editor
5)I strongly recommend that you run the shader editor in docked mode with the window maximized. This gets around 1 or 2 small issues with the unity windowing system focusing the wrong window after selecting a value from a texture / color / other popup.

What I would like from you is any bugs / feedback / feature requests. If you update / generate a shader and it turns out to be invalid (the preview will turn purple). Please save the shader graph and post it here, or PM it to me. I do not know of any cases outside of the known issues where this can currently happen.

Before you lodge a feature request / bug please check the list of known issues and the roadmap for the editor.

Known issuesIf you set the preview mesh to be none, the editor will throw an exception
Workaround: Do not set the preview mesh to null. If you do; close the shader editor window and reopen it this will restore the default preview.

If I dock / undock / maximize / minimize the editor window the preview goes back to it's defaults
Unity windowing is a tricksy beast. Sometimes the editor window decides it needs to recreate it self (demaximizing the window is an example). This means that the preview node is lost and needs to be recreated. I am working on manually serializing the preview node on window destruction so that it can be restored and not lose state. This is scheduled as part of the beta 2 work.

If I name a node _LightColor0 / LightColor0 / _SpecColor / SpecColor the shader will not compile / update
Unity has internally predefined these names in it's lighing CG file. You can not use these names for an input property of a shader or it will fail to compile. Validation has been added to error the shader graph if you do this; but it did not make the beta1 release

I'm sure there are lots of questions. Please watch my preview video (http://www.vimeo.com/13825713) to get an idea of how to use the shader editor. Sometime in the next week I will release some short API documentation and user documentation which will detail how to add new nodes / extend existing nodes.

Unity Technologies

Is there any way to support you? Like donations or so.... I would like to make sure you like to keep working on this and make it worth your while...

Click to expand...

Well as unity 3 isn't out yet I have only tested it with the beta (i.e pro version). This graph editing should work with the non pro version when it is released but the preview may need some severe wrangling as it utilizes drawmesh and rendertextures. I might lodge some support tickets to get some preview functionality exposed into the non pro API's so that I can do this without doing anything too hacky... but I'm not sure if anything will come of it.