IronWarrior / UnityOutlineShader

Source code for Outline Shader tutorial for Unity. Detects edges in a scene using the depth and normals buffers.

Home Page:https://roystan.net/articles/outline-shader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Orthographic camera has some artifacts

oden3d opened this issue · 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

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.

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

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

Yes, run in Play mode.