Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "DecalMRT" {
- Properties {
- [Toggle] _ZWrite ("ZWrite", Range(0,1)) = 0
- [Space]
- _MainTex ("Texture", 2D) = "gray" {}
- [Space]
- _BumpScale(" Bump Scale", Range (0, 3)) = 1
- [Normal] _BumpTex ("Normal", 2D) = "gray" {}
- [Space]
- _Color ("Color", Color) = (1,1,1,1)
- _Contrast ("Contrast", Range (0, 10)) = 1
- _Albedo ("Albedo", Range (0, 1)) = 1
- _SpecularClr ("Specular Color", Range (0, 1)) = 1
- _SpecularAlp ("Specular Alpha", Range (0, 1)) = 1
- _BrightToAlpha ("BrightToAlpha", Range (0, 1)) = 0
- [Space]
- _Overlay ("Influence", Range (-2, 2)) = .2
- _OverlayTex ("Overlay", 2D) = "gray" {}
- [Space]
- [Toggle(MASK)] _Mask ("Use mask", Float) = 0
- [Enum(Alpha,0,Brightness,1)] _MaskType ("Type", Float) = 0
- _MaskTex ("Texture", 2D) = "gray" {}
- _MaskSoft ("Smoothness", Range (0, 1)) = .05
- [Space]
- _MaskOffset ("Offset", Vector) = (0,0,0,0)
- }
- Subshader {
- Pass {
- Fog { Mode Off }
- ZWrite Off
- CGPROGRAM
- #pragma target 3.0
- #pragma vertex vert
- #pragma fragment frag
- #pragma exclude_renderers d3d11
- #pragma shader_feature __ MASK
- #include "UnityCG.cginc"
- #include "UnityStandardUtils.cginc"
- struct v2f
- {
- float2 uv : TEXCOORD0; // texture coordinate
- float4 vertex : SV_POSITION; // clip space position
- float2 worldPosition: TEXCOORD1;
- float4 color : COLOR;
- half3 orTang : TEXCOORD3;
- half3 orBinorm : TEXCOORD4;
- half3 orNorm : TEXCOORD5;
- };
- struct appdata
- {
- float4 vertex : POSITION; // vertex position
- float2 uv : TEXCOORD0; // texture coordinate
- float4 color : COLOR;
- // float3 normal : NORMAL;
- // float4 tangent : TANGENT;
- };
- uniform half _Brightness, _Contrast, _MaskSoft, _MaskType, _Albedo, _SpecularClr, _SpecularAlp, _Overlay, _BrightToAlpha, _BumpScale;
- uniform half4 _Color, _MaskOffset;
- // vertex shader
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- // o.vertex.z -= .001;
- o.worldPosition =
- // mul(UNITY_MATRIX_IT_MV, v.vertex.xy).xy
- mul(unity_ObjectToWorld, float4(v.vertex.xyz,1)).xy
- // mul(unity_ObjectToWorld, v.vertex.xyz).xy
- - _MaskOffset;
- o.orNorm = normalize(UnityObjectToWorldDir(half3(0,0,-1)));
- o.orTang = float4(UnityObjectToWorldDir(half3(1,0,0)), -1);
- o.orBinorm = cross(o.orNorm, o.orTang) * -unity_WorldTransformParams.w;
- o.uv = v.uv;
- o.color = half4(pow(v.color.rgb,_Contrast),v.color.a);
- return o;
- }
- sampler2D _MainTex,_OverlayTex,_BumpTex;
- sampler2D _MaskTex;
- half4 _MaskTex_ST, _OverlayTex_ST;
- float calculateMask(half m, half ia){
- half _MaskThrs = frac((ia-.001)*2)+.001;
- half mm = _MaskThrs + _MaskThrs*_MaskSoft;
- return smoothstep(mm, mm-_MaskSoft, m);
- }
- fixed4 fragAlbedo(v2f i, fixed2 txr, half a, half b, half overlay)
- {
- half3 col = b * max( lerp(txr.x, 1-txr.x, step(i.color.a*_Color.a,.5)), i.color.rgb*_Color.rgb) ;
- half4 fin = half4( col*_Albedo, a);
- return fin * overlay;
- }
- fixed4 fragSpecular(v2f i, fixed2 txr, half a, half b, half overlay)
- {
- half3 col = b * max( lerp(txr.x, 1-txr.x, step(i.color.a*_Color.a,.5)), i.color.rgb*_Color.rgb) ;
- half4 fin = half4( col*_SpecularClr, a*_SpecularAlp);
- return fin * overlay;
- }
- void frag(v2f i, out half4 outDiffuse : COLOR0, out half4 outSpecular : COLOR1, out half4 outNormal : COLOR2)
- {
- fixed2 txr = tex2D(_MainTex, i.uv).ra;
- half a = lerp(txr.y, txr.x, _BrightToAlpha);
- half b = 1;
- #if MASK
- half m = calculateMask(tex2D(_MaskTex, i.worldPosition.xy/_MaskTex_ST.xy + _MaskTex_ST.zw).r, i.color.a);
- a *= lerp(m, 1, _MaskType);
- b = max(m, 1-_MaskType);
- #endif
- clip(a-.01);
- half overlay = tex2D(_OverlayTex, i.worldPosition.xy/_OverlayTex_ST.xy + _OverlayTex_ST.zw).r;
- overlay = 1 + (overlay-.5)*_Overlay;
- outDiffuse = _Color; //fragAlbedo(i, txr, a, b, overlay);
- outSpecular = _SpecularClr;//fragSpecular(i, txr, a, b, overlay);
- outSpecular.a = _SpecularAlp;
- half3 normalTangent = UnpackScaleNormal(tex2D (_BumpTex, i.uv), _BumpScale);
- half3 normalWorld = i.orTang*normalTangent.x + i.orBinorm*normalTangent.y + i.orNorm*normalTangent.z;
- outNormal = half4(normalWorld*.5+.5, 1);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement