Toon shader with orthographic camera

well ive been working on the assets for a small 2d game for a while now, and not being on the bright side i didn’t test if unitys toon shader worked with orthographic cameras

it apparently doesn’t, im sure there is a reason why but i know nothing of shaders.

what im doing is i have a white background, and i was planning on having my models be pure white so it looked like they were see through and you would only see there outlines from the toon shader

is this a simple fix?? or am i going to have to spend a bunch of time learning shaders before i can continue??

if its the latter, where should i start?

This has come up before and I can’t remember if it was resolved or not… Anyway I decided to have a go at it and got it working by taking out one variable (the Z postion) in the Shader and bumping up the max width of the Outline. This is totally untested besides just getting it to work with Unity’s primitives…

Shader "Toon/Basic Outline Orthographic" {
	Properties {
		_Color ("Main Color", Color) = (.5,.5,.5,1)
		_OutlineColor ("Outline Color", Color) = (0,0,0,1)
		_Outline ("Outline width", Range (.01, 0.5)) = .25
		_MainTex ("Base (RGB)", 2D) = "white" { }
		_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal }
	}

	SubShader {
		UsePass "Toon/Basic/BASE"
		Pass {
			Name "OUTLINE"
			Tags { "LightMode" = "Always" }
CGPROGRAM
#pragma vertex vert

struct appdata {
    float4 vertex;
    float3 normal;
};

struct v2f {
	float4 pos : POSITION;
	float4 color : COLOR;
};
uniform float _Outline;
uniform float4 _OutlineColor;

v2f vert(appdata v) {
	v2f o;
	o.pos = mul(glstate.matrix.mvp, v.vertex);
	float3 norm = mul ((float3x3)glstate.matrix.modelview[0], v.normal);
	norm.x *= glstate.matrix.projection[0][0];
	norm.y *= glstate.matrix.projection[1][1];
	o.pos.xy += norm.xy * _Outline;
	
	o.color = _OutlineColor;
	return o;
}
ENDCG
			//Color (0,0,0,0)
			Cull Front
			ZWrite On
			ColorMask RGB
			Blend SrcAlpha OneMinusSrcAlpha
			SetTexture [_MainTex] { combine primary }
		}
	}
	
	Fallback "Toon/Basic"
}

HTH,
Ethan

[Edit] A better way to get this effect is to do it in your 3D program by taking your meshes, selecting all the faces, duplicating/extruding them outwards, flipping the normals, and coloring them whatever color you want. This is basically what the Toon Shader does, but if you do it in your 3D app you will get a much better contiguos looking outline.

thank you VERY much

im at work right now and ill try it when i get home, ill also give the 3d app extrusion thing a try

thank you for your help

this does not work in iOS.;;

It doesn’t work on anything now because it was written for Unity four years ago. Unity iPhone didn’t even exist then, and there have been a lot of changes to Shaderlab in the mean time.

You will probably have better luck looking at the source for the current version of the toon shader.