-
-
Save sergebat/d36136dcc4b52dcd3f32103b4579e37a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/ACNH_SewingCloth" | |
{ | |
Properties | |
{ | |
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {} | |
[NoScaleOffset] _BumpMap ("Normal Map", 2D) = "bump" {} | |
[NoScaleOffset] _EdgeAlpha ("Alpha", 2D) = "white" {} | |
_Cutoff ("Alpha Test Cutoff", Range(0,1)) = 0.5 | |
_Offset ("Offset (XY)", Vector) = (0,0,0,0) | |
_Rotation ("Rotation", Range(-360,360)) = 0.0 | |
} | |
SubShader | |
{ | |
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" } | |
LOD 200 | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows alphatest:_Cutoff | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
sampler2D _BumpMap; | |
sampler2D _EdgeAlpha; | |
struct Input | |
{ | |
// using [NoScaleOffset] above so this is the unmodified mesh UVs | |
float2 uv_MainTex; | |
}; | |
// using a custof offset instead of the built in scale offset | |
// so I can apply it after the rotation instead of before | |
float2 _Offset; | |
// using a rotation in degrees for ease of animation. | |
// would be cheaper to calculate the sine & cosine on CPU but | |
// I'm being lazy and didn't want to write an extra script. | |
float _Rotation; | |
void surf (Input IN, inout SurfaceOutputStandard o) | |
{ | |
// generate rotation matrix | |
float s, c; | |
sincos(_Rotation * (UNITY_PI/180.0), s, c); | |
float2x2 rotMatrix = float2x2(c, s, -s, c); | |
// rotate and offset uv | |
float2 uv = mul(rotMatrix, IN.uv_MainTex) + _Offset; | |
// sample textures with modified uv | |
o.Albedo = tex2D(_MainTex, uv).rgb; | |
o.Alpha = tex2D(_EdgeAlpha, uv).a; | |
o.Normal = UnpackNormal(tex2D(_BumpMap, uv)); | |
// counter-rotate tangent space normal | |
o.Normal.xy = mul(o.Normal.xy, rotMatrix); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment