Unity 2018.3 project source for completed Outline Shader Tutorial from the site roystan.net.
Uses the depth and normals buffers to generate outlines of variable thickness and color.
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
License: The Unlicense
Unity 2018.3 project source for completed Outline Shader Tutorial from the site roystan.net.
Uses the depth and normals buffers to generate outlines of variable thickness and color.
Hi there, thanks for building and sharing this!
I was able to get the effect I want (silhouette outline) by increasing the Depth Threshold to 5 as shown in this image;
However, once I play, the interior lines show up.
I would love to have the silhouette effect, but not sure how to get it to work properly.
The outline is visible in play mode in Unity, but when I build the project for iOS, it doesn't show up in the built version. Is there any way to fix this?
Thanks.
Whenever I build to Windows the edges do not show properly. I think this is the normal edge section.
is it possible to use this as a shader by itself?
Importing the SteamVR plugin causes the screen to be entirely black upon playing.
I tried your tutorial, but the depth based part wasn't working. It was neccessary to set the camera depthTextureMode to DepthTextureMode.Depth
before I got good results.
NB: You can probably use DepthTextureMode.DepthNormals
to avoid needing a secondary camera.
@IronWarrior Thank your tutorial first! But I found we can draw outlines only with depth buffer.
float4 Frag(VaryingsDefault i) : SV_Target
{
float halfScaleFloor = floor(_Scale * .5);
float halfScaleCeil = ceil(_Scale * .5);
float2 bottomLeftUV = i.texcoord - float2(_MainTex_TexelSize.x, _MainTex_TexelSize.y) * halfScaleFloor;
float2 topRightUV = i.texcoord + float2(_MainTex_TexelSize.x , _MainTex_TexelSize.y) * halfScaleCeil;
float2 bottomRightUV = i.texcoord + float2(_MainTex_TexelSize.x * halfScaleCeil, - _MainTex_TexelSize.y * halfScaleFloor);
float2 topLeftUV = i.texcoord + float2(-_MainTex_TexelSize.x * halfScaleFloor, _MainTex_TexelSize.y * halfScaleCeil);
float depth0 = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, bottomLeftUV).r;
float depth1 = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, topRightUV).r;
float depth2 = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, bottomRightUV).r;
float depth3 = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, topLeftUV).r;
float depthFiniteDifference0 = depth1 - depth0;
float depthFiniteDifference1 = depth3 - depth2;
float edgeDepth = sqrt(pow(depthFiniteDifference0, 2) + pow(depthFiniteDifference1, 2)) * 100;
// edgeDepth = step( _DepthThreshold, edgeDepth); // Actullay, it will eliminate the material color
return edgeDepth;
}
And I'm using unity 2019.3.3f1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.