DepthOverwrite.shader 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
  4. https://developer.oculus.com/licenses/oculussdk/
  5. Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
  6. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  7. ANY KIND, either express or implied. See the License for the specific language governing
  8. permissions and limitations under the License.
  9. ************************************************************************************/
  10. Shader "Hidden/DepthOverwrite" {
  11. Properties {
  12. _Offset ("Offset (m)", Float) = 0.1
  13. }
  14. SubShader {
  15. Tags { "Queue"="Transparent+2000" "RenderType"="Opaque" }
  16. LOD 100
  17. Cull Off
  18. ColorMask 0
  19. Pass {
  20. CGPROGRAM
  21. #pragma vertex vert
  22. #pragma fragment frag
  23. #include "UnityCG.cginc"
  24. struct appdata {
  25. float4 vertex : POSITION;
  26. };
  27. struct v2f {
  28. float4 vertex : SV_POSITION;
  29. };
  30. sampler2D _MainTex;
  31. float4 _MainTex_ST;
  32. float _Offset;
  33. v2f vert (appdata v) {
  34. v2f o;
  35. float3 worldPos = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1.0));
  36. float3 toCamera = normalize(_WorldSpaceCameraPos - worldPos);
  37. float3 adjustedPos = worldPos + toCamera * _Offset;
  38. o.vertex = mul(UNITY_MATRIX_VP, float4(adjustedPos, 1.0));
  39. return o;
  40. }
  41. fixed4 frag (v2f i) : SV_Target {
  42. return float4(1, 0, 0, 1);
  43. }
  44. ENDCG
  45. }
  46. }
  47. }