Advertisement
Guest User

Untitled

a guest
Apr 16th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. Shader "Custom/DepthSpriteNoShear"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Sprite Texture", 2D) = "white" {}
  6. _Color ("Tint Color", Color) = (1,1,1,1)
  7. _Tilt ("Tilt Angle (Degrees)", Float) = 50.0
  8. }
  9. SubShader
  10. {
  11. // Render in the Geometry queue for proper depth testing.
  12. Tags { "Queue"="Geometry" "RenderType"="Opaque" }
  13. LOD 100
  14.  
  15. Pass
  16. {
  17. // Ensure the sprite writes depth and is double-sided.
  18. ZWrite On
  19. Cull Off
  20.  
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #include "UnityCG.cginc"
  25.  
  26. sampler2D _MainTex;
  27. fixed4 _Color;
  28. float _Tilt;
  29.  
  30. struct appdata
  31. {
  32. float4 vertex : POSITION;
  33. float2 uv : TEXCOORD0;
  34. };
  35.  
  36. struct v2f
  37. {
  38. float4 vertex : SV_POSITION;
  39. float2 uv : TEXCOORD0;
  40. };
  41.  
  42. /// <summary>
  43. /// Vertex shader applies a shear transformation to achieve the tilt.
  44. /// It assumes that the mesh is a quad centered at the origin.
  45. /// </summary>
  46. v2f vert(appdata v)
  47. {
  48. v2f o;
  49. // Convert the tilt angle from degrees to radians.
  50. float tiltRadians = radians(_Tilt);
  51. // Apply a shear: offset the x coordinate proportional to the y coordinate.
  52. // This simulates a perspective deformation that gives the sprite a 50° angled appearance.
  53. // It assumes the quad is defined with local vertex coordinates (e.g., from -0.5 to 0.5).
  54. v.vertex.z += v.vertex.y * tan(tiltRadians);
  55. o.vertex = UnityObjectToClipPos(v.vertex);
  56. o.uv = v.uv;
  57. return o;
  58. }
  59.  
  60. fixed4 frag(v2f i) : SV_Target
  61. {
  62. fixed4 texColor = tex2D(_MainTex, i.uv) * _Color;
  63. // Clip pixels with very low alpha for proper transparency.
  64. clip(texColor.a - 0.01);
  65. return texColor;
  66. }
  67. ENDCG
  68. }
  69. }
  70. FallBack "Diffuse"
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement