Hey there, Artist here with no programming experience. I really like the look of the basic Unity Toon Shader, but I’ve got shadows in the environment that it doesn’t take into account. Is there any way to do this with this Shader in particular? I’ve experimented with other Toon Shaders that have custom ramps but they just don’t look quite as good as the one that uses the Cubemap.
If you create an example scene with two shaders (good one which has problem with shadows) and bad one in one scene, I’ll try to look into it and understand if it’s possible to fix shadow issue
Hey! Thanks for getting back to me. I can set that up, but it’s not so much an error in the Unity Basic Toon shader it’s just that it doesn’t receive shadows at all, I was hoping there was an easy way to turn that on. I’d like it to use the cubemap it has by default but also receive shadows.
It would be easier to hijack an existing shader and modifying it to have the correct behavior. Generally shader do their stuff and send the result to a final gather, with one line of code you can pick that final gather and transform it into ramped toon lighting.
That’s all I can say now, sorry. I hope someone else pick from there !
Haha, thanks for the post neoshaman. I hear what you’re saying, but I’m I can’t code. This is the code for Unity’s Basic Toon Shader that I like. Any idea what I would add to this so it’ll receive shadows? Is this even possible?
I have never dabble with shadow directly that’s the problem, I do have modified shader who receive shadow, so the idea was to start with a shader that receive shadow and modify it, now this one don’t seem to have it so I a first glance I can’t help.
There is many varient of teh toon shader
Use code tag to display code please
What I can tell you is that the vert part is doing a bunch of conversion of reference I always forget which one but it’s only a pick away from the doc The vert is basically doing some operation at EACH vertex.
Then the GPU automatically interpolate those data across a triangle and for EACH pixel the frag part process its code.
The first line of the frag is multiplying the color field with the texture.
the second is using the normal at the pixel to sample the cubemap
the third multiply the sampled cubemap (from the second line) by the result of the first line and multiply that by 2 again, and put it in the final gather (c)
the fourth line apply fog to the final gather
the fifth simply return the result the final gather for displaying on the screen
Observation.:
it has no concept of light, light direction or presence will do nothing, normally it shouldn’t respond to ambient light either.
the light is entirely dependent on the cubemap and its orientation.
it doesnt react to normal map, there is no hook for it.
It’s only toon shader if the cubemap is using a step drawing, it can be any image or lighting drawn on the cubemap.
You should start with a shader that already have lighting and mix it with this one.
Now Looking at that code you can see it has a custom lighting part, but there isn’t a vert part. I don’t remember how unity handle lack of vert part (I’m sure it’s automated when not mentioned) So I need to check that, though just adding it shouldn’t be a problem. It should be trivial to add normal map too.
This shader work differently, it takes ONE light and use a texture to replace the light gradient by your own. So it beg the question what kind of rendering you really want! If I have full specification I can help you more.
Now you must understand how light work, it takes the direction of the light relative to the point and then the normal of the surface, it does an operation (dot product) and return the value of light. Now this isn’t a full shader, it’s a surface shader, it mean unity already do a lot of stuff behind the curtain.
Now I see the code I remember where the shadow are they are automatically put within the atten variable (which is the light attenuation). Attenuation store 2 things in a single value, it has the occlusion from light (shadow) and the distance attenuation (ie light is less bright the further away from the light point). Of course this shader only use directional light so it only has shadow. Given that it is a gradient, you might need to process this to have toon shadow on top.
You can buy one from the asset store like Toony Colors Pro, or you can try to add shadows on your own as you’ve already started attempting to. This page has examples on how to add shadow receiving and casting to a vertex / fragment shader:
But there is many issue, it’s never a quickfix lol
Both shader use different coding paragdim so I can’t easily port one to the other, without checking stuff in doc.
The second one use surface shader (ie write to a surface structure) while the second is mostly a typical shader. The main problem is to document what’s the equivalence to make modification. The main thing is to convert the first one to a surface shader, it will make everything simpler, however I don’t know about the use of vert data necessary for environment within surface method
I haven’t that down by heart
wrong answer
Okay I’ll try something:
I think I was wrong it’s about the shader only receiving one light
You can have a quick version by modifier the first shader
a. add the to the pragma list
Thanks for that, it’s great. I’ve tried looking into some tutorials but they don’t ease into it enough. I have plenty of 3D content creation experience but zero coding, so this is great. Thanks again.