setDepthOffset.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. return {
  2. tag = 'pipeline',
  3. summary = 'Configure the depth offset.',
  4. description = [[
  5. Set the depth offset. This is a constant offset added to the depth value of pixels, as well as
  6. a "sloped" depth offset that is scaled based on the "slope" of the depth at the pixel.
  7. This can be used to fix Z fighting when rendering decals or other nearly-overlapping objects,
  8. and is also useful for shadow biasing when implementing shadow mapping.
  9. ]],
  10. arguments = {
  11. offset = {
  12. type = 'number',
  13. default = '0.0',
  14. description = 'The depth offset.'
  15. },
  16. sloped = {
  17. type = 'number',
  18. default = '0.0',
  19. description = 'The sloped depth offset.'
  20. }
  21. },
  22. returns = {},
  23. variants = {
  24. {
  25. arguments = { 'offset', 'sloped' },
  26. returns = {}
  27. }
  28. },
  29. notes = [[
  30. The default depth offset is zero for both values.
  31. This only applies to triangles, not points or lines.
  32. The units for these offsets aren't specified very well -- they depend on the format of the depth
  33. texture, and the GPU can use them slightly differently for its depth calculations. However, an
  34. `offset` of 1 will roughly correspond to the smallest-possible depth difference (e.g. 2^-16 for
  35. a `d16` depth texture).
  36. The sloped depth scale is multiplied by the slope of the depth of the triangle. For example,
  37. if pixels in the triangle all have the same depth (i.e. the triangle is facing the camera), then
  38. the slope of the depth will be zero and the sloped depth offset won't have any effect. As the
  39. triangle starts to face away from the camera, the slope of the depth will increase and the
  40. sloped depth offset will begin to apply. This can also be thought of corresponding to the
  41. normal vector of the triangle relative to the camera.
  42. Note that the offsets can be negative. With LÖVR's default projection matrix, depth values of
  43. zero are far away and one are close up, so positive depth offsets will push depth values
  44. "closer" to the viewer. With flipped projection matrices (a depth test of `lequal`), negative
  45. depth offsets would be used instead.
  46. ]],
  47. related = {
  48. 'Pass:setDepthTest',
  49. 'Pass:setDepthWrite'
  50. }
  51. }