UnityOutlineShader icon indicating copy to clipboard operation
UnityOutlineShader copied to clipboard

Orthographic camera has some artifacts

Open oden3d opened this issue 6 years ago • 4 comments

Hello, First of all you did a great job, brilliant solution! I found some artifacts with orthographic camera. See picture below: image

And the same camera transform but Perspective projection: image

oden3d avatar Feb 18 '19 21:02 oden3d

Hey Den, this is caused by some issues with the view direction. The line below helps to influence the strength of the depth buffer, by increasing the amount of depth required on sharp edges (see section 3. Resolving surface artifacts of the tutorial).

float NdotV = 1 - dot(viewNormal, -i.viewSpaceDir);

Unfortunately, in ortho mode, as the projection is parallel, viewSpaceDir does not correctly work. This can be resolved by replacing the line with

float NdotV = 1 - dot(viewNormal, float3(0,0,1));

Where the view direction to each vertex is directly forward.

image

There's still some missing edges, such as along the teapot's rim, but those could be fixed by tweaking the parameters I'd assume. The above is using the default settings, except Depth Threshold is set to 0.01.

IronWarrior avatar Feb 19 '19 17:02 IronWarrior

Thank you for help! Tried your solution but seems did not really work well for me. Still have missing edges on stairs and other. Set Depth Threshold to 0.01 helps for better result.

Also found but did not tried yet other solution also based on normal map. https://gamedev.stackexchange.com/questions/68401/how-can-i-draw-outlines-around-3d-models

oden3d avatar Feb 20 '19 12:02 oden3d

Are you making sure to run the scene in Play mode? This ensures that the normals buffer is rendered out and is accessible.

IronWarrior avatar Feb 24 '19 05:02 IronWarrior

Yes, run in Play mode.

oden3d avatar Feb 25 '19 18:02 oden3d