Shader各种Shader效果的合集
Posted stalendp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shader各种Shader效果的合集相关的知识,希望对你有一定的参考价值。
1. The Fresnel Effect
参考: https://www.dorian-iten.com/fresnel/
实用的shader:
Shader "HeroShader/Character"
Properties
_Tint ("Tint", Color) = (1, 1, 1, 0.2) // a通道用来控制halfLambert的参数,用来提亮
_MainTex ("Texture, Flag", 2D) = "white" // A通道标记阵营区域, 1 表示有阵营颜色区域,0 表示非阵营颜色区域
// _Emission("Emission", Range(0, 1)) = 0 // 自发光
_ShadowLevel("Shadow Level", Range(0, 10)) = 2.5 // 模拟AO
_RimRange("Rim Range", Range(0, 1)) = 0 // Rim范围
_RimColor ("Rim color", Color) = (1, 1, 1, 1) // Rim相关
_FlagColor("Flag Color, Intensity", Color) = (0.5,0.5,0.5, 0) // 阵营信息,a通道控制阵营颜色强度
SubShader
Tags "RenderType" = "Opaque"
CGPROGRAM
#pragma surface surf Character nolightmap nodirlightmap
sampler2D _MainTex;
half4 _Tint;
half4 _RimColor;
half4 _FlagColor;
half _RimRange;
// half _Emission;
half _ShadowLevel;
struct Input
float2 uv_MainTex;
float3 worldPos;
;
// 漫反射 + ShadowLevel(模拟AO)+ 自发光
void surf (Input IN, inout SurfaceOutput o)
half4 col = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = lerp(col.rgb * _Tint.rgb, _FlagColor.rgb, _FlagColor.a * col.a) // 阵营信息
* lerp(0, 1, saturate(IN.worldPos.y + 1 - _ShadowLevel * 0.2)); // shadow level, 模拟AO
o.Emission = 0; //_Emission;
o.Gloss = _Tint.a; // 临时用来存放halfLambert的提亮参数
// 参考dota2 shader的实现方案
half4 LightingCharacter (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
half NdotL = saturate(dot(s.Normal, lightDir));
half NdotV = max(0, dot(s.Normal, viewDir));
half halfLambert = (1 - s.Gloss) * NdotL + s.Gloss;
return half4(s.Albedo * _LightColor0.rgb * halfLambert * atten
+ saturate(_RimRange * 1.5 - NdotV) * _RimColor.rgb, s.Alpha);
ENDCG
Fallback "Diffuse"
Shader "HeroShader/Character_NoLight"
Properties
_Tint ("Tint", Color) = (1, 1, 1, 0)
_MainTex ("Texture, Flag", 2D) = "white" // A通道标记阵营区域
_Emission("Emission", Range(0, 1)) = 0 // 自发光
_ShadowLevel("Shadow Level", Range(0, 10)) = 0 // 模拟AO
_FlagColor("Flag Color, Intensity", Color) = (0.5,0.5,0.5,1) // 阵营信息
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
half4 _Tint;
half4 _FlagColor;
half _Emission;
half _ShadowLevel;
struct appdata
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
;
struct v2f
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 worldPos : TEXCOORD1;
;
v2f vert (appdata v)
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
return o;
// 阵营信息 + ShadowLevel(模拟AO)+ 自发光
float4 frag (v2f i) : SV_Target
half4 col = tex2D (_MainTex, i.uv);
col.rgb = lerp(col.rgb * _Tint.rgb, _FlagColor.rgb, _FlagColor.a * col.a) // 处理阵营信息
* lerp(0, 1, saturate(i.worldPos.y + 1 - _ShadowLevel * 0.2)); // shadow level, 模拟AO
col.rgb += _Emission;
return col;
ENDCG
SubShader
Tags
"Queue"="Geometry"
"RenderType"="Opaque"
Pass
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
Fallback "Diffuse"
以上是关于Shader各种Shader效果的合集的主要内容,如果未能解决你的问题,请参考以下文章