# depth bias,how to set "Offset Factor, Units"

Discussion in 'General Discussion' started by chineseoldghost, Jul 12, 2019.

1. ### chineseoldghost

Joined:
Nov 28, 2017
Posts:
4
i had confused with Offset Factor, Units in shader,now i test some scene i add ,and i found someting,maybe useful
depth bias is a useful thing in render,"Offset Factor, Units " in unity shader ,i think it is most like glploygonoffset in opengl.i got some picture like this.
the first parameter factor is a offset factor used to offset depth ,but if the camera near plane is more parallel to the face ,this will be less effect.

this is when set factor -0.15,units 0,when camera near plane is not parallel the road

if change camera to parallel to road face,you will seen Ghosting

now we change unit to -5 ,the ghost ghone,when the near plane is more parallel face ,the unit is working more effect.

if the camera near plane is not parallel face ,the factor is more useful,but buf the scale value will be effected then the camera is far to the road face we rendered;next picture show that.

when the camera is near road ,every thing is ok,we use factor -0.15,unit -1

as the camera move far away ,some ghost in the edge is seen. factor and unit the same value.

hope may be helpful

2. ### SunnySunshine

Joined:
May 18, 2009
Posts:
669
I remember encountering this problem way back. The easiest solution is to offset the vertices so they're actually above the terrain. However, if that is not an option (which it wasn't in our case), you can always write to depth using the SV_Depth shader semantic for the fragment shader. This is supported by Unity.

Here's some random example I found when searching.

Unfortunately, AFAIK there's no way to make this compile into a surface shader other than modifying the surface shader output manually. What we ended up doing was creating a small python program that simply search and replaced the surface shader output to make the depth behave as desired.

3. ### chineseoldghost

Joined:
Nov 28, 2017
Posts:
4
yes ,you can do this. if you covert terrain to mesh,and calculate the polygon of the road,and remove the face of terrain under road,but if you render the terrain not like mesh,depth bias may the only way.