207 lines
6.8 KiB
Plaintext
207 lines
6.8 KiB
Plaintext
// ***********************************************************************
|
|
// Author : Kimch
|
|
// Created : 2018-7-1
|
|
// Description : 角色Shader
|
|
// Last Modified By : Kimch
|
|
// Last Modified On : 2019-7-1
|
|
// ***********************************************************************
|
|
// <copyright file= "MY_PBS_PlayerV3" company="kk"></copyright>
|
|
// ***********************************************************************
|
|
Shader "MY/PBS/PlayerV3"
|
|
{
|
|
Properties
|
|
{
|
|
[HDR]_Color("Color", Color) = (1,1,1,1)
|
|
_MainTex("Albedo (RGB)", 2D) = "white" {}
|
|
|
|
[NoScaleOffset]_MetalTex("Metallic", 2D) = "black" {}
|
|
_MetalColor("Metallic Color", Color) = (0,0,0,1)
|
|
_GlossColor("Smoothness Color", Color) = (0,0,0,1)
|
|
|
|
// 立方体贴图属性
|
|
_Cube("Cubemap", CUBE) = "" {}
|
|
|
|
[Header(Detail)]
|
|
_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
|
|
_DetailNormalMapScale("Scale", Float) = 1.0
|
|
_DetailNormalMap("Normal Map", 2D) = "bump" {}
|
|
|
|
_DetailColor("花纹颜色", Color) = (0,0,0,1)
|
|
_DetailPower("花纹强度", Range(-10,10)) = 1
|
|
[Header(Rim)]
|
|
_RimColor("边光颜色", Color) = (0,0,0,1)
|
|
_RimPower("边光强度", Range(-10,10)) = 1
|
|
_RimRange("边光范围", Range(1,10)) = 1.8
|
|
[Header(Emission)]
|
|
_EmissionColor("自发光颜色", Color) = (0,0,0)
|
|
_EmissionPower("自发光强度", Range(-10,10)) = 0
|
|
[Header(Scroll)]
|
|
_ScrollTex("流光贴图(RGB)", 2D) = "black" {}
|
|
_ScrollPower("流光强度", Range(-10, 10)) = 1
|
|
_ScrollSpeedX("X流光速度", Range(-10, 10)) = 0
|
|
_ScrollSpeedY("Y流光速度", Range(-10, 10)) = 0
|
|
|
|
[Header(ColorMask)]
|
|
[NoScaleOffset]_ColorMaskTex("换色贴图", 2D) = "white" { }
|
|
[HDR]_RColorMaskColor("区域一(红色部分控制)", Color) = (0,0,0,1)
|
|
[HDR]_GColorMaskColor("区域二(绿色部分控制)", Color) = (0,0,0,1)
|
|
[HDR]_BColorMaskColor("区域三(蓝色部分控制)", Color) = (0,0,0,1)
|
|
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "RenderType" = "Opaque" }
|
|
LOD 200
|
|
|
|
CGPROGRAM
|
|
// Physically based Standard lighting model, and enable shadows on all light types
|
|
#pragma surface surf Standard fullforwardshadows vertex:myvert finalcolor:mycolor nometa nolightmap nofog noinstancing keepalpha exclude_path:deferred exclude_path:prepass
|
|
|
|
// Use shader model 3.0 target, to get nicer looking lighting
|
|
#pragma target 3.0
|
|
|
|
samplerCUBE _Cube;
|
|
|
|
sampler2D _MainTex;
|
|
fixed4 _Color;
|
|
|
|
sampler2D _MetalTex;
|
|
fixed4 _MetalColor;
|
|
fixed4 _GlossColor;
|
|
|
|
fixed3 _RimColor;
|
|
half _RimPower;
|
|
half _RimRange;
|
|
|
|
#if _DETAIL
|
|
sampler2D _DetailAlbedoMap;
|
|
sampler2D _DetailNormalMap;
|
|
half _DetailNormalMapScale;
|
|
#endif
|
|
fixed3 _DetailColor;
|
|
half _DetailPower;
|
|
|
|
fixed3 _EmissionColor;
|
|
half _EmissionPower;
|
|
|
|
// Color Mask
|
|
sampler2D _ColorMaskTex;
|
|
fixed4 _RColorMaskColor;
|
|
fixed4 _GColorMaskColor;
|
|
fixed4 _BColorMaskColor;
|
|
|
|
// Scroll
|
|
sampler2D _ScrollTex;
|
|
half _ScrollPower;
|
|
half _ScrollSpeedX;
|
|
half _ScrollSpeedY;
|
|
|
|
struct Input
|
|
{
|
|
float2 uv_MainTex;
|
|
float2 uv_ScrollTex;
|
|
float2 uv_DetailAlbedoMap;
|
|
float2 uv_DetailNormalMap;
|
|
float3 viewDir;
|
|
float3 worldNormal;
|
|
float3 worldRefl;
|
|
float2 scrollAdd;
|
|
INTERNAL_DATA
|
|
};
|
|
|
|
//struct SurfaceOutputStandardSpecular
|
|
//{
|
|
// fixed3 Albedo; // diffuse color
|
|
// fixed3 Specular; // specular color
|
|
// float3 Normal; // tangent space normal, if written
|
|
// half3 Emission;
|
|
// half Smoothness; // 0=rough, 1=smooth
|
|
// half Occlusion; // occlusion (default 1)
|
|
// fixed Alpha; // alpha for transparencies
|
|
//};
|
|
|
|
//struct SurfaceOutputStandard
|
|
//{
|
|
// fixed3 Albedo; // base (diffuse or specular) color
|
|
// float3 Normal; // tangent space normal, if written
|
|
// half3 Emission;
|
|
// half Metallic; // 0=non-metal, 1=metal
|
|
// // Smoothness is the user facing name, it should be perceptual smoothness but user should not have to deal with it.
|
|
// // Everywhere in the code you meet smoothness it is perceptual smoothness
|
|
// half Smoothness; // 0=rough, 1=smooth
|
|
// half Occlusion; // occlusion (default 1)
|
|
// fixed Alpha; // alpha for transparencies
|
|
//};
|
|
|
|
void myvert(inout appdata_full v, out Input o)
|
|
{
|
|
UNITY_INITIALIZE_OUTPUT(Input, o);
|
|
|
|
o.scrollAdd.xy = float2(_ScrollSpeedX, _ScrollSpeedY)*_Time.y;
|
|
}
|
|
|
|
void surf(Input IN, inout SurfaceOutputStandard o)
|
|
{
|
|
// Albedo comes from a texture tinted by color
|
|
fixed4 cm = tex2D(_ColorMaskTex, IN.uv_MainTex);
|
|
fixed4 specGloss = tex2D(_MetalTex, IN.uv_MainTex);
|
|
fixed4 scroll = tex2D(_ScrollTex, IN.scrollAdd + IN.uv_ScrollTex);
|
|
|
|
//half h = specGloss.b - 0.5;
|
|
//float2 offset = ParallaxOffset(h, _Parallax, IN.viewDir);
|
|
//IN.uv_MainTex += offset;
|
|
|
|
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
|
|
|
|
fixed4 cmc = cm.r * _RColorMaskColor + cm.g * _GColorMaskColor + cm.b*_BColorMaskColor;
|
|
o.Albedo = ((1 - specGloss.g - specGloss.r) * cmc + specGloss.g + specGloss.r)* c.rgb + (1- specGloss.r)* specGloss.b*_DetailPower*_DetailColor.rgb;
|
|
|
|
// Specular and smoothness come from slider variables
|
|
o.Metallic = saturate(sign(specGloss.r - 0.1))*_MetalColor.a + cm.r*_MetalColor.r + cm.g*_MetalColor.g + cm.b *_MetalColor.b;
|
|
o.Smoothness = _GlossColor.a*specGloss.r + _GlossColor.r*cm.r + _GlossColor.g*cm.g + _GlossColor.b*cm.b;
|
|
o.Emission = /*saturate(o.Smoothness - 0.3) * texCUBE(_Cube, IN.worldRefl).rgb*/ /*+ _EmissionPower * _EmissionColor.rgb*/ +specGloss.a *_ScrollPower *scroll.rgb + specGloss.b*_DetailPower*saturate(_DetailColor.rgb - 0.1f);
|
|
|
|
#if _DETAIL
|
|
half mask = 1 - saturate(cm.g - 0.2);
|
|
half3 detailAlbedo = tex2D(_DetailAlbedoMap, IN.uv_DetailAlbedoMap).rgb;
|
|
#if _DETAIL_MULX2
|
|
o.Albedo *= LerpWhiteTo(detailAlbedo * unity_ColorSpaceDouble.rgb, mask);
|
|
#elif _DETAIL_MUL
|
|
o.Albedo *= LerpWhiteTo(detailAlbedo, mask);
|
|
#elif _DETAIL_ADD
|
|
o.Albedo += detailAlbedo * mask;
|
|
#elif _DETAIL_LERP
|
|
o.Albedo = lerp(albedo, detailAlbedo, mask);
|
|
#endif
|
|
half3 normalTangent = IN.worldNormal;
|
|
|
|
|
|
half3 detailNormalTangent = UnpackScaleNormal(tex2D(_DetailNormalMap, IN.uv_DetailNormalMap), _DetailNormalMapScale);
|
|
#if _DETAIL_LERP
|
|
normalTangent = lerp(
|
|
normalTangent,
|
|
detailNormalTangent,
|
|
mask);
|
|
#else
|
|
normalTangent = lerp(
|
|
normalTangent,
|
|
BlendNormals(normalTangent, detailNormalTangent),
|
|
mask);
|
|
#endif
|
|
o.Normal = normalTangent;
|
|
#endif
|
|
o.Alpha = c.a;
|
|
}
|
|
|
|
void mycolor(Input IN, SurfaceOutputStandard o, inout fixed4 color)
|
|
{
|
|
fixed3 rim = saturate(1 - saturate(dot(IN.worldNormal, IN.viewDir)) * _RimRange) *_RimPower * _RimColor;
|
|
color.rgb += rim;
|
|
}
|
|
|
|
ENDCG
|
|
}
|
|
FallBack "Diffuse"
|
|
}
|