Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/DepthSpriteNoShear"
- {
- Properties
- {
- _MainTex ("Sprite Texture", 2D) = "white" {}
- _Color ("Tint Color", Color) = (1,1,1,1)
- _Tilt ("Tilt Angle (Degrees)", Float) = 50.0
- }
- SubShader
- {
- // Render in the Geometry queue for proper depth testing.
- Tags { "Queue"="Geometry" "RenderType"="Opaque" }
- LOD 100
- Pass
- {
- // Ensure the sprite writes depth and is double-sided.
- ZWrite On
- Cull Off
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- fixed4 _Color;
- float _Tilt;
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- float2 uv : TEXCOORD0;
- };
- /// <summary>
- /// Vertex shader applies a shear transformation to achieve the tilt.
- /// It assumes that the mesh is a quad centered at the origin.
- /// </summary>
- v2f vert(appdata v)
- {
- v2f o;
- // Convert the tilt angle from degrees to radians.
- float tiltRadians = radians(_Tilt);
- // Apply a shear: offset the x coordinate proportional to the y coordinate.
- // This simulates a perspective deformation that gives the sprite a 50° angled appearance.
- // It assumes the quad is defined with local vertex coordinates (e.g., from -0.5 to 0.5).
- v.vertex.z += v.vertex.y * tan(tiltRadians);
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 texColor = tex2D(_MainTex, i.uv) * _Color;
- // Clip pixels with very low alpha for proper transparency.
- clip(texColor.a - 0.01);
- return texColor;
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement