shaoxiadiablo/Assets/AGame/Res/Shaders/MYPBS/MY_PBS_PlayerV2.shader

148 lines
4.1 KiB
Plaintext
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Author : Kimch
// Created : 2018-7-1
// Description : 角色Shader
// Last Modified By : Kimch
// Last Modified On : 2019-7-1
// ***********************************************************************
// <copyright file= "MY_PBS_PlayerV2" company="kk"></copyright>
// ***********************************************************************
Shader "MY/PBS/PlayerV2"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_BumpMap("Bumpmap", 2D) = "bump" {}
_Detail("Detail", 2D) = "gray" {}
_Control("R(metallic)G(Smooth)B(liuguang)", 2D) = "white" { }
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGINCLUDE
ENDCG
Pass
{
Name "Glow"
ColorMask RGB
Blend One One
ZWrite Off
ZTest Greater
Fog {Mode Off}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _FresnelColor;
fixed _FresnelExp;
struct VertexInput
{
half4 vertex : POSITION;
half3 normal : NORMAL;
};
struct VertexOutput
{
half4 pos : SV_POSITION;
half3 color : TEXCOORD0;
//half4 posWorld : TEXCOORD0;
//half3 normalDir : TEXCOORD1;
};
VertexOutput vert(VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos(v.vertex);
half3 normalDir = mul(v.normal, unity_WorldToObject);
normalDir = normalize(normalDir);
half3 viewDir = mul(unity_ObjectToWorld, v.vertex);
viewDir = normalize(_WorldSpaceCameraPos - viewDir);
o.color = _FresnelColor.rgb * pow(1.0 - max(0, dot(normalDir, viewDir)), _FresnelExp);
//o.normalDir = normalize(mul(half4(v.normal,0), unity_WorldToObject).xyz);
//o.posWorld = mul(unity_ObjectToWorld, v.vertex);
//o.posWorld.xyz = normalize(_WorldSpaceCameraPos.xyz - o.posWorld.xyz);
//o.posWorld.x = pow(1.0 - max(0, dot(o.normalDir, o.posWorld.xyz)), _FresnelExp);
return o;
}
fixed4 frag(VertexOutput i) : COLOR
{
//half3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
//half3 normalDirection = normalize(i.normalDir);
//fixed3 finalColor = _FresnelColor.rgb * pow(1.0 - max(0,dot(normalDirection, viewDirection)) , _FresnelExp);
return fixed4(i.color,1);
}
ENDCG
}
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows nometa nolightmap nofog nolppv noinstancing exclude_path:deferred exclude_path:prepass
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Detail;
sampler2D _Control;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_Detail;
};
//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
//};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
//o.Albedo *= tex2D(_Detail, IN.uv_Detail).rgb * 2;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
fixed4 control = tex2D(_Control, IN.uv_MainTex);
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic * control.r;
o.Smoothness = _Glossiness * control.g;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}