标签:遮罩 高光 1.0 MainTex uv fixed3 xy MaskTexture nDirTS
高光遮罩的原理可以简单的理解为:漫反射叠加上一个采样过遮罩纹理的高光次幂
Shader "Unlit/UnlitShader_MaskTexture"
{
Properties
{
_MainTex ("Texture" ,2D) = "white" {}
_NormalMap ("NormalMap" ,2D) = "bump"{}
_SpecularMask ("SpecularMask" ,2D) = "white"{}
_Color ("Color" ,Color) = (1.0,1.0,1.0,1.0)
_Specular ("Specular" ,Color) = (1.0,1.0,1.0,1.0)
_BumpScale ("BumpScale" ,Range(0.0,20.0)) = 1.0
_SpecularScale ("_SpecularScale",Range(0.0,10.0)) = 1.0
_Gloss ("Gloss" ,Range(0.0,256.0)) = 20
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _SpecularMask;
fixed4 _Color;
fixed4 _Specular;
fixed4 _MainTex_ST;
float _BumpScale;
float _SpecularScale;
float _Gloss;
struct VertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 lDir : TEXCOORD1;
float3 vDir : TEXCOORD2;
};
VertexOutput vert (VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv.xy = v.uv.xy * _MainTex_ST.xy + _MainTex_ST.zw;
TANGENT_SPACE_ROTATION;
o.lDir = mul(rotation,ObjSpaceLightDir(v.vertex)).xyz;
o.vDir = mul(rotation,ObjSpaceViewDir(v.vertex)).xyz;
return o;
}
fixed4 frag (VertexOutput i) : SV_Target
{
fixed3 lDirTS = normalize(i.lDir);
fixed3 vDirTS = normalize(i.vDir);
fixed3 nDirTS = UnpackNormal(tex2D(_NormalMap ,i.uv));
fixed3 hDir = normalize(lDirTS + vDirTS);
fixed3 ndotlTS = dot(nDirTS,lDirTS);
fixed3 ndoth = dot(nDirTS,hDir);
nDirTS.xy *= _BumpScale;
nDirTS.z = sqrt(1.0 - saturate(dot(nDirTS.xy,nDirTS.xy)));
fixed3 albedo = tex2D(_MainTex,i.uv).rgb * _Color.rgb;
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
fixed3 diffuse = _LightColor0.rgb * albedo * max(0.0,ndotlTS);
fixed specularMask = tex2D(_SpecularMask,i.uv).r * _SpecularScale;
fixed3 specular = _LightColor0.rgb * _Specular.rgb * pow(max(0,ndoth) , _Gloss) * specularMask;
return fixed4(ambient + diffuse + specular ,1.0);
}
ENDCG
}
}
FallBack"Specular"
}
标签:遮罩,高光,1.0,MainTex,uv,fixed3,xy,MaskTexture,nDirTS 来源: https://blog.csdn.net/qq_43933700/article/details/120788837
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。