I wrote a hatching shader for Unity Beta 6 although it may work for earlier versions as well, since it is not written as a new "surface shader". The shader takes two images and displays one of the 6 RGB channels based on the amount of diffuse light it receives. I included two sets of hatching textures, a pencil sketch version and a duotone version. Additionally, I included a slot for a diffuse texture that can be used as a base color. I included a "Tile Factor" which you can use to tile the main hatching. The shader currently relies on your imported UV's so if they are really clean (mine are not) you get really nice results. The textures are setup so that each channel has a different black and white texture, from lightest to darkest: (This is apparent in the included PSD files in the package) Tex_1.Red = Lightest texture Tex_1.Green = Lighter texture Tex_1.Blue = Light texture Tex_2.Red = Dark texture Tex_2.Green = Darker texture Tex_2.Blue = Darkest texture Here's a video of what it looks like on moving objects: http://www.youtube.com/v/nlDxZ6n_Bs8?hd=1 And a picture: Click to download: https://docs.google.com/leaf?id=0B_BYe3L2yjJ3N2VjYzcwZTktNTA3Mi00NmVjLTk1YmYtN2M4YTI4NWRlYTFk&hl=en ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have a question. How difficult would it be to swap the texture of the shader. As in, instead of hatch lines have it display screen tone dots? Can you alter the thickness and frequency of the hatch lines/dots or is it based on the distance from the light source?
I'm new to Unity and just learning how to use shaders. I want to implement an effect just like this, so this was really encouraging to know that what I want to achieve is already out there! Unfortunately the link to the download seems to be broken, so I can't check it out. Would you be able to post a new one please?
This shader looks great. I am having an issue with it though. Turning the camera is effecting how light or dark the areas are shaded and I can never get plain white. Here is a fraps http://www.youtube.com/watch?v=l_qUDicL4Qg
I reduced the issue by changing a few lines. I added the tag Code (csharp): "LightMode" = "Vertex" then changed Code (csharp): float3 normalWorld = normalize(mul((float3x3)UNITY_MATRIX_MV ,v.normal)); float diffuse = min(1.0,max(0,dot(_WorldLightPos0,normalWorld)));//cant remember the light pos var he used exactly diffuse *= diffuse; diffuse *= diffuse; to the following Code (csharp): float3 normalWorld = normalize(mul((float3x3)UNITY_MATRIX_IT_MV ,v.normal)); float3 L = normalize(unity_LightPosition[0] - posWorld); float diff = min(1.0,max(0,dot(normalWorld,L))); diff *= unity_LightColor[0]*n;//n is a var to individually change the light intensity This seemed to fix it mostly. Its doing it more now depending on the camera distance to the object. I think it may just be a mip mapping issue. It reduced again when i used a higher res texture. I'd love to hear other input on this.
I know this is an older thread, but I'm having some problems getting this shader to work. I had the exact same problems as glacius3000, so I tried using your code changes. Unfortunately I received the following errors: Shader error in 'Custom/Hatch Texture UV': GLSL vertex shader: ERROR: 0:330: 'n' : undeclared identifier at line 17 Shader warning in 'Custom/Hatch Texture UV': Program 'vert', implicit cast from "float4" to "float3" at line 67 Shader error in 'Custom/Hatch Texture UV': Program 'vert', undefined variable "n" at line 73 Shader error in 'Custom/Hatch Texture UV': Program 'vert', unable to find compatible overloaded function "clamp(error, float, int)" at line 75 I made no other changes... as it looks like your code is dependent on certain variables and functions, I'm wondering if something about Unity changed since this was written? Any suggestions on making the shader work in Unity 3.5.7? Thanks in advance!
Looks great.I know this is an old post, but Im just checking in to see if there is a chance for a re-up ? Link has died