├── .gitattributes ├── Anti-Aliasing └── SSAA │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ └── SSAA 1-2-3-4.shader ├── Human skin realtime rendering ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── HumanSkin.shader ├── plus effect │ ├── Blood Effect │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ └── HumanSkinWithBlood.shader │ └── Water Drop Effect │ │ ├── 1 (1).png │ │ ├── 1 (2).png │ │ └── HumanSkinWithWaterDrop.shader └── superaddition │ ├── 1 (1).png │ ├── 1 (2).png │ ├── 1 (3).png │ ├── 1 (4).png │ ├── 1 (5).png │ ├── 1 (6).png │ └── HumanSkin_plus.shader ├── Post processing ├── Computerfault │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── ComputerFault.cs │ └── ComputerFault.shader ├── Depth Of Field │ ├── DOF add noise │ │ └── DOF_add_noise.shader │ ├── DOF_PP.cs │ ├── DOF_post_process.shader │ ├── dof1.png │ ├── dof2.png │ ├── dof3.png │ ├── dof4.png │ ├── dof5.png │ └── dof6.png ├── Distortion │ ├── Barrel.png │ ├── Barrel │ │ └── Barrel.shader │ ├── Fisheye.png │ ├── fisheye │ │ └── fasheye.shader │ └── pincushion.png ├── HDR&Bloom │ ├── HDRGlow.cs │ └── HDRGlow.shader ├── Real-Time Denoising in games │ ├── Conventional geometry-aware filtering.shader │ ├── Specular Lobe-Aware Filtering and Upsampling.shader │ ├── c 3.jpg │ ├── cds.jpg │ ├── d2.jpg │ ├── s 2.jpg │ └── s 3.jpg └── shaders from ppsspp used in Unity3d │ ├── FXAA.shader │ ├── Retroc_CRT.shader │ ├── aacolor.shader │ ├── bloom.shader │ ├── cartoon.shader │ ├── grayscale.shader │ ├── inversecolors.shader │ ├── natural.shader │ ├── scanlines.shader │ ├── sharpen.shader │ ├── test in ppsspp │ ├── 4xHQHLSL.png │ ├── AAColor.png │ ├── Bloom.png │ ├── CRT.png │ ├── FXAA.png │ ├── FXAA未开.png │ ├── cartoon.png │ ├── grayscale.png │ ├── inversecolors.png │ ├── natural.png │ ├── scanlines.png │ ├── sharpen.png │ ├── upscale_spline36.png │ ├── upscale_spline36—关.png │ ├── upscale_spline36—开.png │ └── vignette.png │ ├── test in ppsspp2 │ ├── 4xHQGLSL.png │ ├── AAColor.png │ ├── BLoom.png │ ├── FXAA.png │ ├── cartoon.png │ ├── natural.png │ ├── 原图.png │ ├── 放大-关.png │ ├── 放大-关2.png │ ├── 放大-开.png │ └── 放大-开2.png │ ├── test in unity │ ├── AAColor.png │ ├── CRT.png │ ├── bloom.png │ ├── cartoon.png │ ├── fxaa.png │ ├── grayscale.png │ ├── natural.png │ ├── scanlines.png │ ├── sharpen.png │ └── vignette.png │ ├── upscale_spline36.shader │ └── vignette.shader ├── Realistic eye shading ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── eye Shading.shader └── eye no detial Spec Shading.shader ├── Realistic plant shading ├── 1 (1).png ├── 1 (2).png ├── 1 (3).png ├── 1 (4).png ├── 1 (5).png ├── plant1.shader └── plant2.shader ├── fur ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png └── fur.shader ├── random generation terrain based on fractal noise ├── Noise.cs ├── NoiseMethod.cs ├── terrain.shader ├── terrain_g.cs └── test │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 7.png │ ├── 8.png │ ├── 9.png │ ├── Fractal.png │ └── Fractal2.png └── snow and sand ├── send big 3.png ├── send2.png ├── snow big3.png ├── snow.png ├── snow.shader └── snow2.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Anti-Aliasing/SSAA/1.png -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Anti-Aliasing/SSAA/2.png -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Anti-Aliasing/SSAA/3.png -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Anti-Aliasing/SSAA/4.png -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Anti-Aliasing/SSAA/5.png -------------------------------------------------------------------------------- /Anti-Aliasing/SSAA/SSAA 1-2-3-4.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about Super Sampling Anti-Aliasing in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/SSAA1" { 7 | Properties{ 8 | _MainTex("MainTex", 2D) = "white" {} 9 | _Size("Size", range(1, 2048)) = 512 10 | 11 | } 12 | SubShader{ 13 | pass{ 14 | Tags{ "LightMode" = "ForwardBase" } 15 | Cull off 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | #include "UnityCG.cginc" 20 | 21 | float _Size; 22 | sampler2D _MainTex; 23 | float4 _MainTex_ST; 24 | struct v2f { 25 | float4 pos : SV_POSITION; 26 | float2 uv_MainTex : TEXCOORD0; 27 | 28 | }; 29 | 30 | v2f vert(appdata_full v) { 31 | v2f o; 32 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 33 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 34 | return o; 35 | } 36 | float4 frag(v2f i) :COLOR 37 | { 38 | /* 39 | *this part is about edge detection algorithms used Sobel operator 40 | */ 41 | float3 lum = float3(0.2125, 0.7154, 0.0721); 42 | float mc00 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(1, 1) / _Size).rgb, lum); 43 | float mc10 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(0, 1) / _Size).rgb, lum); 44 | float mc20 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 1) / _Size).rgb, lum); 45 | float mc01 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(1, 0) / _Size).rgb, lum); 46 | float mc11mc = dot(tex2D(_MainTex, i.uv_MainTex).rgb, lum); 47 | float mc21 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 0) / _Size).rgb, lum); 48 | float mc02 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(1, -1) / _Size).rgb, lum); 49 | float mc12 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(0, -1) / _Size).rgb, lum); 50 | float mc22 = dot(tex2D(_MainTex, i.uv_MainTex - fixed2(-1, -1) / _Size).rgb, lum); 51 | float GX = -1 * mc00 + mc20 + -2 * mc01 + 2 * mc21 - mc02 + mc22; 52 | float GY = mc00 + 2 * mc10 + mc20 - mc02 - 2 * mc12 - mc22; 53 | float G = abs(GX) + abs(GY); 54 | float4 c = 0; 55 | c = length(float2(GX, GY)); 56 | /* 57 | *this part is about blur edge 58 | */ 59 | float4 cc = tex2D(_MainTex, i.uv_MainTex); 60 | if (c.x < 0.2) 61 | { 62 | return cc; 63 | } 64 | else 65 | { 66 | float2 n = float2(GX, GY); 67 | n *= 1 / _Size / c.x; 68 | //roated 69 | float4 c0 = tex2D(_MainTex, i.uv_MainTex + fixed2(0.2 / 2, 0.8) / _Size); 70 | float4 c1 = tex2D(_MainTex, i.uv_MainTex + fixed2(0.8 / 2, -0.2) / _Size); 71 | float4 c2 = tex2D(_MainTex, i.uv_MainTex + fixed2(-0.2 / 2, -0.8) / _Size); 72 | float4 c3 = tex2D(_MainTex, i.uv_MainTex + fixed2(-0.8 / 2, 0.2) / _Size); 73 | 74 | //random 75 | float2 randUV = 0; 76 | randUV = rand(float2(n.x, n.y)); 77 | float4 c0 = tex2D(_MainTex, i.uv_MainTex + float2(randUV.x / 2, randUV.y) / _Size); 78 | randUV = rand(float2(-n.x, n.y)); 79 | float4 c1 = tex2D(_MainTex, i.uv_MainTex + float2(randUV.x / 2, randUV.y) / _Size); 80 | randUV = rand(float2(n.x, -n.y)); 81 | float4 c2 = tex2D(_MainTex, i.uv_MainTex + float2(randUV.x / 2, randUV.y) / _Size); 82 | randUV = rand(float2(-n.x, -n.y)); 83 | float4 c3 = tex2D(_MainTex, i.uv_MainTex + float2(randUV.x / 2, randUV.y) / _Size); 84 | 85 | //Gird 86 | 87 | float4 c0 = tex2D(_MainTex, i.uv_MainTex + fixed2(0.5, 1) / _Size); 88 | float4 c1 = tex2D(_MainTex, i.uv_MainTex + fixed2(-0.5, 1) / _Size); 89 | float4 c2 = tex2D(_MainTex, i.uv_MainTex + fixed2(0.5, -1) / _Size); 90 | float4 c3 = tex2D(_MainTex, i.uv_MainTex + fixed2(-0.5, -1) / _Size); 91 | cc = (cc + c0 + c1 + c2 + c3) *0.2; 92 | return cc; 93 | } 94 | 95 | } 96 | ENDCG 97 | } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Human skin realtime rendering/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/1.png -------------------------------------------------------------------------------- /Human skin realtime rendering/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/2.png -------------------------------------------------------------------------------- /Human skin realtime rendering/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/3.png -------------------------------------------------------------------------------- /Human skin realtime rendering/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/4.png -------------------------------------------------------------------------------- /Human skin realtime rendering/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/5.png -------------------------------------------------------------------------------- /Human skin realtime rendering/HumanSkin.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about human skin's real time rendering in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/HumanSkin" { 7 | Properties{ 8 | _MainTex("Base (RGB)", 2D) = "white" {} 9 | _SpecularTex("Specular (RGB)", 2D) = "white" {} 10 | _SpecularPower("Specular Power", Range(0.04, 1)) = 1 11 | 12 | _AlbedoTex("Albedo (RGB)", 2D) = "white" {} 13 | _AlbedoPower("Albedo Power", Range(0, 20)) = 1 14 | _AlbedoDistance("Albedo Distance", Range(0.1, 2)) = 1 15 | 16 | _BRDFTex("BRDF (RGB)", 2D) = "white" {} 17 | _CurveScale("Curvature Scale", Range(0.001, 0.09)) = 0.01 18 | 19 | _BlurTex1("Blur Tex 1 (RGB)", 2D) = "white" {} 20 | _BlurTex2("Blur Tex 2 (RGB)", 2D) = "white" {} 21 | _BlurTex3("Blur Tex 3 (RGB)", 2D) = "white" {} 22 | _BlurTex4("Blur Tex 4 (RGB)", 2D) = "white" {} 23 | _BlurTex5("Blur Tex 5 (RGB)", 2D) = "white" {} 24 | _BlurTex6("Blur Tex 6 (RGB)", 2D) = "white" {} 25 | 26 | _DetailTex("Detail (RGB)", 2D) = "white" {} 27 | _BumpBias("Normal Map Blur", Range(0, 5)) = 2.0 28 | _Maintint("Main Color", Color) = (1, 1, 1, 1) 29 | _Cubemap("CubeMap", CUBE) = ""{} 30 | _SC("Specular Color", Color) = (1, 1, 1, 1) 31 | _GL("gloss", Range(0, 0.1)) = 0.05 32 | _nMips("nMipsF", Range(0, 5)) = 0.5 33 | _ReflAmount("Reflection Amount", Range(0.01, 1)) = 0.5 34 | 35 | 36 | _RimPower("RimPower", Range(0.1, 0.8)) = 0.5 37 | _RimColor("Rim Color", Color) = (1, 1, 1, 1) 38 | _RimTex("Rim (RGB)", 2D) = "white" {} 39 | 40 | _FrontRimPower("Front RimPower", Range(0.1, 0.8)) = 0.5 41 | _FrontRimColor("Front Rim Color", Color) = (1, 1, 1, 1) 42 | _FrontRimTex("Front Rim (RGB)", 2D) = "white" {} 43 | 44 | _SSSPower("SSSPower", Range(0.1, 15)) = 0.5 45 | _SSSFrontTex("Front SSS (RGB)", 2D) = "white" {} 46 | _SSSBackTex("Back SSS (RGB)", 2D) = "white" {} 47 | } 48 | SubShader{ 49 | pass{ 50 | Tags{ "LightMode" = "ForwardBase" } 51 | ZWrite on 52 | Cull Back 53 | 54 | CGPROGRAM 55 | #pragma vertex vert 56 | #pragma fragment frag 57 | #include "UnityCG.cginc" 58 | #include "AutoLight.cginc" 59 | 60 | float4x4 _World2Light; 61 | float4 _LightColor0; 62 | samplerCUBE _Cubemap; 63 | float _SpecularPower; 64 | float4 _SC; 65 | float _GL; 66 | float4 _Maintint; 67 | float _nMips; 68 | float _ReflAmount; 69 | 70 | uniform sampler2D _AlbedoTex; 71 | float _AlbedoPower; 72 | float _AlbedoDistance; 73 | 74 | uniform sampler2D _BRDFTex; 75 | float _CurveScale; 76 | 77 | float _RimPower; 78 | float4 _RimColor; 79 | uniform sampler2D _RimTex; 80 | 81 | float _FrontRimPower; 82 | float4 _FrontRimColor; 83 | uniform sampler2D _FrontRimTex; 84 | 85 | float _SSSPower; 86 | uniform sampler2D _SSSFrontTex; 87 | uniform sampler2D _SSSBackTex; 88 | 89 | uniform sampler2D _BlurTex1; 90 | uniform sampler2D _BlurTex2; 91 | uniform sampler2D _BlurTex3; 92 | uniform sampler2D _BlurTex4; 93 | uniform sampler2D _BlurTex5; 94 | uniform sampler2D _BlurTex6; 95 | 96 | uniform sampler2D _SpecularTex; 97 | uniform sampler2D _MainTex; 98 | uniform sampler2D _DetailTex; 99 | float4 _MainTex_ST; 100 | float4 _DetailTex_ST; 101 | float _BumpBias; 102 | struct v2f { 103 | float4 pos : SV_POSITION; 104 | float2 uv_MainTex : TEXCOORD0; 105 | float3 lightDir : TEXCOORD1; 106 | float3 viewDir : TEXCOORD2; 107 | float3 normal : TEXCOORD3; 108 | float4 worldpos : TEXCOORD4; 109 | float2 uv_DetailTex : TEXCOORD5; 110 | }; 111 | struct appdata { 112 | float4 vertex : POSITION; 113 | float4 tangent : TANGENT; 114 | float3 normal : NORMAL; 115 | float2 texcoord : TEXCOORD0; 116 | fixed4 color : COLOR; 117 | }; 118 | v2f vert(appdata_full v) { 119 | v2f o; 120 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 121 | o.uv_DetailTex = TRANSFORM_TEX(v.texcoord, _DetailTex); 122 | 123 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 124 | 125 | o.worldpos = mul(_Object2World, v.vertex); 126 | o.normal = v.normal; 127 | o.lightDir = ObjSpaceLightDir(v.vertex); 128 | o.viewDir = ObjSpaceViewDir(v.vertex); 129 | 130 | 131 | return o; 132 | } 133 | #define PIE 3.1415926535 134 | 135 | 136 | float4 frag(v2f i) :COLOR 137 | { 138 | float3 viewDir = normalize(i.viewDir); 139 | float3 lightDir = normalize(i.lightDir); 140 | float3 H = normalize(lightDir + viewDir); 141 | /* 142 | *this part is about blend normal, normal map and detail map 143 | *and the nomal blur also in here 144 | *this blend method is from internet 145 | */ 146 | float3 n1 = tex2Dbias(_DetailTex, float4(i.uv_MainTex, 0.0, _BumpBias)) * 2 - 1;//normalBlur 147 | float3 n2 = normalize(i.normal) * 2 - 1; 148 | 149 | float a = 1 / (1 + n1.z); 150 | float b = -n1.x*n1.y*a; 151 | 152 | float3 b1 = float3(1 - n1.x*n1.x*a, b, -n1.x); 153 | float3 b2 = float3(b, 1 - n1.y*n1.y*a, -n1.y); 154 | float3 b3 = n1; 155 | 156 | if (n1.z < -0.9999999) 157 | { 158 | b1 = float3(0, -1, 0); 159 | b2 = float3(-1, 0, 0); 160 | } 161 | 162 | float3 r = n2.x*b1 + n2.y*b2 + n2.z*b3; 163 | 164 | n2 = r*0.5 + 0.5; 165 | 166 | n2 *= 3; 167 | n2 += n1; 168 | n2 /= 4; 169 | n2 = normalize(n2); 170 | 171 | /* 172 | *this part is compute Physically-Based Rendering 173 | *the method is in the ppt about "ops2" 174 | */ 175 | 176 | float _SP = pow(8192, _GL); 177 | float d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 178 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 179 | float k = min(1, _GL + 0.545); 180 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 181 | 182 | float all = d*f*v; 183 | float3 refDir = reflect(-viewDir, n2); 184 | float3 ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _GL*_nMips)).rgb; 185 | 186 | float3 c = tex2D(_MainTex, i.uv_MainTex) * 128; 187 | c += tex2D(_BlurTex1, i.uv_MainTex) * 64; 188 | c += tex2D(_BlurTex2, i.uv_MainTex) * 32; 189 | c += tex2D(_BlurTex3, i.uv_MainTex) * 16; 190 | c += tex2D(_BlurTex4, i.uv_MainTex) * 8; 191 | c += tex2D(_BlurTex5, i.uv_MainTex) * 4; 192 | c += tex2D(_BlurTex6, i.uv_MainTex) * 2; 193 | c /= 256; 194 | 195 | float3 diff = dot(lightDir, n2); 196 | all = saturate(all);; 197 | diff = (1 - all)*diff; 198 | diff = saturate(diff); 199 | /* 200 | *this part is supplement the specular 201 | *to add the oil's feel 202 | */ 203 | float specBase = max(0, dot(n2, H)); 204 | float spec = pow(specBase, 10) *(_GL + 0.2); 205 | spec = lerp(0, 1.2, spec); 206 | float3 spec3 = spec * (tex2D(_SpecularTex, i.uv_MainTex) - 0.1); 207 | spec3 *= Luminance(diff); 208 | spec3 = saturate(spec3); 209 | spec3 *= _SpecularPower; 210 | 211 | /* 212 | *this part is to add the sss 213 | *used front rim,back rim and BRDF 214 | */ 215 | 216 | float3 rim = (1 - dot(viewDir, n2))*_RimPower * _RimColor *tex2D(_RimTex, i.uv_MainTex); 217 | float3 frontrim = (dot(viewDir, n2))*_FrontRimPower * _FrontRimColor *tex2D(_FrontRimTex, i.uv_MainTex); 218 | 219 | float3 sss = (1 - dot(viewDir, n2)) / 50 * _SSSPower; 220 | sss = lerp(tex2D(_SSSFrontTex, i.uv_MainTex), tex2D(_SSSBackTex, i.uv_MainTex), sss * 20)*sss; 221 | 222 | fixed atten = LIGHT_ATTENUATION(i); 223 | float curvature = length(fwidth(mul(_Object2World, float4(normalize(i.normal), 0)))) / 224 | length(fwidth(i.worldpos)) * _CurveScale; 225 | 226 | float3 brdf = tex2D(_BRDFTex, float2((dot(normalize(i.normal), lightDir) * 0.5 + 0.5)* atten, curvature)).rgb; 227 | 228 | float4 c2 = float4(lerp(c, ref, _ReflAmount) *(diff*_Maintint+ (all*_SC)/2)*brdf + rim + frontrim + spec3 + sss + all*_SC, 1); 229 | if (_WorldSpaceLightPos0.w != 0) 230 | { 231 | float dis = distance(_WorldSpaceLightPos0, i.worldpos); 232 | dis *= _AlbedoDistance; 233 | if (1 - dis > 0) 234 | c2 += tex2D(_AlbedoTex, float2(0.5, 1 - dis))*_AlbedoPower; 235 | } 236 | 237 | c2 *= atten; 238 | return c2; 239 | } 240 | ENDCG 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/1.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/2.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/3.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/4.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/5.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Blood Effect/6.png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Blood Effect/HumanSkinWithBlood.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about human skin's real time rendering in unity3d 4 | *add some blood effect that can ctrl the blood coverd area and blood clotting time 5 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 6 | */ 7 | Shader "Custom/HumanSkinWithBlood" { 8 | Properties{ 9 | _BloodTex("Blood (RGB)", 2D) = "white" {} 10 | _BloodColor("Blood color", Color) = (1, 1, 1, 1) 11 | _ClottingBloodTime("Clotting Blood Time", Range(0.1, 0.9)) = 0.3 12 | _BloodCoverArea("BloodCoverArea", Range(0.1, 1)) = 0.3 13 | _BloodReflAmount("Blood Reflect Amount", Range(0, 1)) = 0.3 14 | _BloodSC("Blood Specular Color", Color) = (1, 1, 1, 1) 15 | 16 | _MainTex("Base (RGB)", 2D) = "white" {} 17 | _SpecularTex("Specular (RGB)", 2D) = "white" {} 18 | _SpecularPower("Specular Power", Range(0.04, 1)) = 1 19 | 20 | _AlbedoTex("Albedo (RGB)", 2D) = "white" {} 21 | _AlbedoPower("Albedo Power", Range(0, 20)) = 1 22 | _AlbedoDistance("Albedo Distance", Range(0.1, 2)) = 1 23 | 24 | _BRDFTex("BRDF (RGB)", 2D) = "white" {} 25 | _CurveScale("Curvature Scale", Range(0.001, 0.09)) = 0.01 26 | 27 | _BlurTex1("Blur Tex 1 (RGB)", 2D) = "white" {} 28 | _BlurTex2("Blur Tex 2 (RGB)", 2D) = "white" {} 29 | _BlurTex3("Blur Tex 3 (RGB)", 2D) = "white" {} 30 | _BlurTex4("Blur Tex 4 (RGB)", 2D) = "white" {} 31 | _BlurTex5("Blur Tex 5 (RGB)", 2D) = "white" {} 32 | _BlurTex6("Blur Tex 6 (RGB)", 2D) = "white" {} 33 | 34 | _DetailTex("Detail (RGB)", 2D) = "white" {} 35 | _BumpBias("Normal Map Blur", Range(0, 5)) = 2.0 36 | _Maintint("Main Color", Color) = (1, 1, 1, 1) 37 | _Cubemap("CubeMap", CUBE) = ""{} 38 | _SC("Specular Color", Color) = (1, 1, 1, 1) 39 | _GL("gloss", Range(0, 0.1)) = 0.05 40 | _nMips("nMipsF", Range(0, 5)) = 0.5 41 | _ReflAmount("Reflection Amount", Range(0.01, 1)) = 0.5 42 | 43 | 44 | _RimPower("RimPower", Range(0.1, 0.8)) = 0.5 45 | _RimColor("Rim Color", Color) = (1, 1, 1, 1) 46 | _RimTex("Rim (RGB)", 2D) = "white" {} 47 | 48 | _FrontRimPower("Front RimPower", Range(0.1, 0.8)) = 0.5 49 | _FrontRimColor("Front Rim Color", Color) = (1, 1, 1, 1) 50 | _FrontRimTex("Front Rim (RGB)", 2D) = "white" {} 51 | } 52 | SubShader{ 53 | pass{ 54 | Tags{ "LightMode" = "ForwardBase" } 55 | ZWrite on 56 | Cull Back 57 | 58 | CGPROGRAM 59 | #pragma vertex vert 60 | #pragma fragment frag 61 | #include "UnityCG.cginc" 62 | #include "AutoLight.cginc" 63 | sampler2D _BloodTex; 64 | float4 _BloodColor; 65 | float _ClottingBloodTime; 66 | float _BloodCoverArea; 67 | float _BloodReflAmount; 68 | float4 _BloodSC; 69 | 70 | float4x4 _World2Light; 71 | float4 _LightColor0; 72 | samplerCUBE _Cubemap; 73 | float _SpecularPower; 74 | float4 _SC; 75 | float _GL; 76 | float4 _Maintint; 77 | float _nMips; 78 | float _ReflAmount; 79 | 80 | sampler2D _AlbedoTex; 81 | float _AlbedoPower; 82 | float _AlbedoDistance; 83 | 84 | sampler2D _BRDFTex; 85 | float _CurveScale; 86 | 87 | float _RimPower; 88 | float4 _RimColor; 89 | sampler2D _RimTex; 90 | 91 | float _FrontRimPower; 92 | float4 _FrontRimColor; 93 | sampler2D _FrontRimTex; 94 | 95 | sampler2D _BlurTex1; 96 | sampler2D _BlurTex2; 97 | sampler2D _BlurTex3; 98 | sampler2D _BlurTex4; 99 | sampler2D _BlurTex5; 100 | sampler2D _BlurTex6; 101 | 102 | sampler2D _SpecularTex; 103 | sampler2D _MainTex; 104 | sampler2D _DetailTex; 105 | float4 _MainTex_ST; 106 | float4 _DetailTex_ST; 107 | float _BumpBias; 108 | struct v2f { 109 | float4 pos : SV_POSITION; 110 | float2 uv_MainTex : TEXCOORD0; 111 | float3 lightDir : TEXCOORD1; 112 | float3 viewDir : TEXCOORD2; 113 | float3 normal : TEXCOORD3; 114 | float4 worldpos : TEXCOORD4; 115 | float2 uv_DetailTex : TEXCOORD5; 116 | }; 117 | struct appdata { 118 | float4 vertex : POSITION; 119 | float4 tangent : TANGENT; 120 | float3 normal : NORMAL; 121 | float2 texcoord : TEXCOORD0; 122 | fixed4 color : COLOR; 123 | }; 124 | v2f vert(appdata_full v) { 125 | v2f o; 126 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 127 | o.uv_DetailTex = TRANSFORM_TEX(v.texcoord, _DetailTex); 128 | 129 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 130 | 131 | o.worldpos = mul(_Object2World, v.vertex); 132 | o.normal = v.normal; 133 | o.lightDir = ObjSpaceLightDir(v.vertex); 134 | o.viewDir = ObjSpaceViewDir(v.vertex); 135 | 136 | 137 | return o; 138 | } 139 | #define PIE 3.1415926535 140 | 141 | 142 | float4 frag(v2f i) :COLOR 143 | { 144 | float3 viewDir = normalize(i.viewDir); 145 | float3 lightDir = normalize(i.lightDir); 146 | float3 H = normalize(lightDir + viewDir); 147 | /* 148 | *this part is about blend normal, normal map and detail map 149 | *and the nomal blur also in here 150 | *this blend method is from internet 151 | */ 152 | float3 n1 = tex2Dbias(_DetailTex, float4(i.uv_MainTex, 0.0, _BumpBias)) * 2 - 1;//normalBlur 153 | float3 n2 = normalize(i.normal) * 2 - 1; 154 | 155 | float a = 1 / (1 + n1.z); 156 | float b = -n1.x*n1.y*a; 157 | 158 | float3 b1 = float3(1 - n1.x*n1.x*a, b, -n1.x); 159 | float3 b2 = float3(b, 1 - n1.y*n1.y*a, -n1.y); 160 | float3 b3 = n1; 161 | 162 | if (n1.z < -0.9999999) 163 | { 164 | b1 = float3(0, -1, 0); 165 | b2 = float3(-1, 0, 0); 166 | } 167 | 168 | float3 r = n2.x*b1 + n2.y*b2 + n2.z*b3; 169 | 170 | n2 = r*0.5 + 0.5; 171 | 172 | n2 *= 3; 173 | n2 += n1; 174 | n2 /= 4; 175 | n2 = normalize(n2); 176 | 177 | /* 178 | *this part is compute Physically-Based Rendering 179 | *the method is in the ppt about "ops2" 180 | */ 181 | 182 | float _SP = pow(8192, _GL); 183 | float d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 184 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 185 | float k = min(1, _GL + 0.545); 186 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 187 | 188 | float all = d*f*v; 189 | float3 refDir = reflect(-viewDir, n2); 190 | float3 ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _GL*_nMips)).rgb; 191 | 192 | float3 c = tex2D(_MainTex, i.uv_MainTex) * 128; 193 | c += tex2D(_BlurTex1, i.uv_MainTex) * 64; 194 | c += tex2D(_BlurTex2, i.uv_MainTex) * 32; 195 | c += tex2D(_BlurTex3, i.uv_MainTex) * 16; 196 | c += tex2D(_BlurTex4, i.uv_MainTex) * 8; 197 | c += tex2D(_BlurTex5, i.uv_MainTex) * 4; 198 | c += tex2D(_BlurTex6, i.uv_MainTex) * 2; 199 | c /= 256; 200 | 201 | float3 diff = dot(lightDir, n2); 202 | all = saturate(all);; 203 | diff = (1 - all)*diff; 204 | diff = saturate(diff); 205 | /* 206 | *this part is supplement the specular 207 | *to add the oil's feel 208 | */ 209 | float specBase = max(0, dot(n2, H)); 210 | float spec = pow(specBase, 10) *(_GL + 0.2); 211 | spec = lerp(0, 1.2, spec); 212 | float3 spec3 = spec * (tex2D(_SpecularTex, i.uv_MainTex) - 0.1); 213 | spec3 *= Luminance(diff); 214 | spec3 = saturate(spec3); 215 | spec3 *= _SpecularPower; 216 | 217 | /* 218 | *this part is to add the sss 219 | *used front rim,back rim and BRDF 220 | */ 221 | 222 | float3 rim = (1 - dot(viewDir, n2))*_RimPower * _RimColor *tex2D(_RimTex, i.uv_MainTex); 223 | float3 frontrim = (dot(viewDir, n2))*_FrontRimPower * _FrontRimColor *tex2D(_FrontRimTex, i.uv_MainTex); 224 | 225 | fixed atten = LIGHT_ATTENUATION(i); 226 | float curvature = length(fwidth(mul(_Object2World, float4(normalize(i.normal), 0)))) / 227 | length(fwidth(i.worldpos)) * _CurveScale; 228 | 229 | float3 brdf = tex2D(_BRDFTex, float2((dot(normalize(i.normal), lightDir) * 0.5 + 0.5)* atten, curvature)).rgb; 230 | 231 | float4 c2 = float4(lerp(c, ref, _ReflAmount) *(diff*_Maintint + (all*_SC) / 2)*brdf + rim + frontrim + spec3 + (all*_SC) / 2, 1); 232 | if (_WorldSpaceLightPos0.w != 0) 233 | { 234 | float dis = distance(_WorldSpaceLightPos0, i.worldpos); 235 | dis *= _AlbedoDistance; 236 | if (1 - dis > 0) 237 | c2 += tex2D(_AlbedoTex, float2(0.5, 1 - dis))*_AlbedoPower; 238 | } 239 | 240 | /* 241 | *this part is add the blood effect 242 | *compute the PBR of the blood and add to skin 243 | */ 244 | float3 bl = tex2D(_BloodTex, i.uv_MainTex).rgb; 245 | if (Luminance(bl) < _BloodCoverArea) 246 | { 247 | float4 c3 = c2 * (lerp(-0.1, 1, float4(lightDir * n2 * bl, 0)) + _ClottingBloodTime)* _BloodColor; 248 | 249 | _SP = pow(8192, _ClottingBloodTime); 250 | d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 251 | f = _BloodSC + (1 - _BloodSC)*pow(2, -10 * dot(H, lightDir)); 252 | k = min(1, _ClottingBloodTime + 0.545); 253 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 254 | all = d*f*v; 255 | ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _ClottingBloodTime*_nMips)).rgb; 256 | 257 | if (_ClottingBloodTime<0.7&&_ClottingBloodTime>0.3) 258 | _ClottingBloodTime -= 0.1; 259 | /* 260 | *ratio can measure the edge of a piece of blood 261 | *make this part a bit transparency 262 | *that looks more realistic 263 | */ 264 | float ratio = 0; 265 | if (_BloodCoverArea < 0.6) 266 | { 267 | ratio = smoothstep(0.2, 0.8, Luminance(bl)); 268 | c2 = lerp(c3, c2, ratio); 269 | c2 = lerp(c2, float4(ref, 1), _BloodReflAmount) + all*_BloodSC* _ClottingBloodTime*(1 - ratio); 270 | } 271 | else 272 | { 273 | ratio = smoothstep(0.1, 0.9, Luminance(bl) - _BloodCoverArea / 3); 274 | c2 = lerp(c3, c2, ratio); 275 | c2 = lerp(c2, float4(ref, 1), _BloodReflAmount) + all*_BloodSC* _ClottingBloodTime*(1 - ratio); 276 | } 277 | } 278 | c2 *= atten; 279 | return c2; 280 | } 281 | ENDCG 282 | } 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Water Drop Effect/1 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Water Drop Effect/1 (1).png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Water Drop Effect/1 (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/plus effect/Water Drop Effect/1 (2).png -------------------------------------------------------------------------------- /Human skin realtime rendering/plus effect/Water Drop Effect/HumanSkinWithWaterDrop.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about human skin's real time rendering in unity3d 4 | *add some water drop effect that is dynamic state 5 | *looks like the model perspiration or take a bath 6 | *you can ctrl the color of the water, and the drop speed, drop direction etc. 7 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 8 | */ 9 | Shader "Custom/blood" { 10 | Properties{ 11 | _SpeedStrength("Speed (XY), Strength (ZW)", Vector) = (1, 1, 1, 1) 12 | _RefractTexTiling("Refraction Tilefac", Range(0.1, 6)) = 1 13 | _RefractTex("Refraction (RG), Colormask (B)", 2D) = "white" {} 14 | _Color("Color (RGB)", Color) = (1, 1, 1, 1) 15 | _WaterColor("Water Color (RGBA)", Color) = (1, 1, 1, 1) 16 | _NonTex("DON`T TOUCH IT! :)", RECT) = "white" {} 17 | _WaterNormalTex("WaterNormalTex", 2D) = "white" {} 18 | _WaterGL("gloss", Range(0, 1)) = 0.5 19 | _WaterReflAmount("WaterReflAmount", Range(0, 1)) = 0.5 20 | 21 | _MainTex("Base (RGB)", 2D) = "white" {} 22 | _SpecularTex("Specular (RGB)", 2D) = "white" {} 23 | _SpecularPower("Specular Power", Range(0.04, 1)) = 1 24 | 25 | _AlbedoTex("Albedo (RGB)", 2D) = "white" {} 26 | _AlbedoPower("Albedo Power", Range(0, 20)) = 1 27 | _AlbedoDistance("Albedo Distance", Range(0.1, 2)) = 1 28 | 29 | _BRDFTex("BRDF (RGB)", 2D) = "white" {} 30 | _CurveScale("Curvature Scale", Range(0.001, 0.09)) = 0.01 31 | 32 | _BlurTex1("Blur Tex 1 (RGB)", 2D) = "white" {} 33 | _BlurTex2("Blur Tex 2 (RGB)", 2D) = "white" {} 34 | _BlurTex3("Blur Tex 3 (RGB)", 2D) = "white" {} 35 | _BlurTex4("Blur Tex 4 (RGB)", 2D) = "white" {} 36 | _BlurTex5("Blur Tex 5 (RGB)", 2D) = "white" {} 37 | _BlurTex6("Blur Tex 6 (RGB)", 2D) = "white" {} 38 | 39 | _DetailTex("Detail (RGB)", 2D) = "white" {} 40 | _BumpBias("Normal Map Blur", Range(0, 5)) = 2.0 41 | _Maintint("Main Color", Color) = (1, 1, 1, 1) 42 | _Cubemap("CubeMap", CUBE) = ""{} 43 | _SC("Specular Color", Color) = (1, 1, 1, 1) 44 | _GL("gloss", Range(0, 0.1)) = 0.05 45 | _nMips("nMipsF", Range(0, 5)) = 0.5 46 | _ReflAmount("Reflection Amount", Range(0.01, 1)) = 0.5 47 | 48 | 49 | _RimPower("RimPower", Range(0.1, 0.8)) = 0.5 50 | _RimColor("Rim Color", Color) = (1, 1, 1, 1) 51 | 52 | _FrontRimPower("Front RimPower", Range(0.1, 0.8)) = 0.5 53 | _FrontRimColor("Front Rim Color", Color) = (1, 1, 1, 1) 54 | _FrontRimTex("Front Rim (RGB)", 2D) = "white" {} 55 | 56 | } 57 | SubShader{ 58 | pass{ 59 | Tags{ "LightMode" = "ForwardBase" } 60 | ZWrite on 61 | Cull Back 62 | 63 | CGPROGRAM 64 | #pragma vertex vert 65 | #pragma fragment frag 66 | #include "UnityCG.cginc" 67 | #include "AutoLight.cginc" 68 | sampler2D _NonTex; 69 | sampler2D _RefractTex; 70 | float4 _SpeedStrength; 71 | float4 _WaterColor; 72 | float _RefractTexTiling; 73 | float4 _Color; 74 | sampler2D _WaterNormalTex; 75 | float _WaterGL; 76 | float _WaterReflAmount; 77 | 78 | float4x4 _World2Light; 79 | float4 _LightColor0; 80 | samplerCUBE _Cubemap; 81 | float _SpecularPower; 82 | float4 _SC; 83 | float _GL; 84 | float4 _Maintint; 85 | float _nMips; 86 | float _ReflAmount; 87 | 88 | sampler2D _AlbedoTex; 89 | float _AlbedoPower; 90 | float _AlbedoDistance; 91 | 92 | sampler2D _BRDFTex; 93 | float _CurveScale; 94 | 95 | float _RimPower; 96 | float4 _RimColor; 97 | 98 | float _FrontRimPower; 99 | float4 _FrontRimColor; 100 | sampler2D _FrontRimTex; 101 | 102 | sampler2D _BlurTex1; 103 | sampler2D _BlurTex2; 104 | sampler2D _BlurTex3; 105 | sampler2D _BlurTex4; 106 | sampler2D _BlurTex5; 107 | sampler2D _BlurTex6; 108 | 109 | sampler2D _SpecularTex; 110 | sampler2D _MainTex; 111 | sampler2D _DetailTex; 112 | float4 _MainTex_ST; 113 | float4 _DetailTex_ST; 114 | float _BumpBias; 115 | struct v2f { 116 | float4 pos : SV_POSITION; 117 | float2 uv_MainTex : TEXCOORD0; 118 | float3 lightDir : TEXCOORD1; 119 | float3 viewDir : TEXCOORD2; 120 | float3 normal : TEXCOORD3; 121 | float4 worldpos : TEXCOORD4; 122 | float2 uv_DetailTex : TEXCOORD5; 123 | }; 124 | struct appdata { 125 | float4 vertex : POSITION; 126 | float4 tangent : TANGENT; 127 | float3 normal : NORMAL; 128 | float2 texcoord : TEXCOORD0; 129 | fixed4 color : COLOR; 130 | }; 131 | v2f vert(appdata_full v) { 132 | v2f o; 133 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 134 | o.uv_DetailTex = TRANSFORM_TEX(v.texcoord, _DetailTex); 135 | 136 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 137 | 138 | o.worldpos = mul(_Object2World, v.vertex); 139 | o.normal = v.normal; 140 | o.lightDir = ObjSpaceLightDir(v.vertex); 141 | o.viewDir = ObjSpaceViewDir(v.vertex); 142 | 143 | 144 | return o; 145 | } 146 | #define PIE 3.1415926535 147 | 148 | 149 | float4 frag(v2f i) :COLOR 150 | { 151 | float3 viewDir = normalize(i.viewDir); 152 | float3 lightDir = normalize(i.lightDir); 153 | float3 H = normalize(lightDir + viewDir); 154 | /* 155 | *this part is about blend normal, normal map and detail map 156 | *and the nomal blur also in here 157 | *this blend method is from internet 158 | */ 159 | float3 n1 = tex2Dbias(_DetailTex, float4(i.uv_MainTex, 0.0, _BumpBias)) * 2 - 1;//normalBlur 160 | float3 n2 = normalize(i.normal) * 2 - 1; 161 | 162 | float a = 1 / (1 + n1.z); 163 | float b = -n1.x*n1.y*a; 164 | 165 | float3 b1 = float3(1 - n1.x*n1.x*a, b, -n1.x); 166 | float3 b2 = float3(b, 1 - n1.y*n1.y*a, -n1.y); 167 | float3 b3 = n1; 168 | 169 | if (n1.z < -0.9999999) 170 | { 171 | b1 = float3(0, -1, 0); 172 | b2 = float3(-1, 0, 0); 173 | } 174 | 175 | float3 r = n2.x*b1 + n2.y*b2 + n2.z*b3; 176 | 177 | n2 = r*0.5 + 0.5; 178 | 179 | n2 *= 3; 180 | n2 += n1; 181 | n2 /= 4; 182 | n2 = normalize(n2); 183 | 184 | /* 185 | *this part is compute Physically-Based Rendering 186 | *the method is in the ppt about "ops2" 187 | */ 188 | 189 | float _SP = pow(8192, _GL); 190 | float d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 191 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 192 | float k = min(1, _GL + 0.545); 193 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 194 | 195 | float all = d*f*v; 196 | float3 refDir = reflect(-viewDir, n2); 197 | float3 ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _GL*_nMips)).rgb; 198 | 199 | float3 c = tex2D(_MainTex, i.uv_MainTex) * 128; 200 | c += tex2D(_BlurTex1, i.uv_MainTex) * 64; 201 | c += tex2D(_BlurTex2, i.uv_MainTex) * 32; 202 | c += tex2D(_BlurTex3, i.uv_MainTex) * 16; 203 | c += tex2D(_BlurTex4, i.uv_MainTex) * 8; 204 | c += tex2D(_BlurTex5, i.uv_MainTex) * 4; 205 | c += tex2D(_BlurTex6, i.uv_MainTex) * 2; 206 | c /= 256; 207 | 208 | float3 diff = dot(lightDir, n2); 209 | all = saturate(all);; 210 | diff = (1 - all)*diff; 211 | diff = saturate(diff); 212 | /* 213 | *this part is supplement the specular 214 | *to add the oil's feel 215 | */ 216 | float specBase = max(0, dot(n2, H)); 217 | float spec = pow(specBase, 10) *(_GL + 0.2); 218 | spec = lerp(0, 1.2, spec); 219 | float3 spec3 = spec * (tex2D(_SpecularTex, i.uv_MainTex) - 0.1); 220 | spec3 *= Luminance(diff); 221 | spec3 = saturate(spec3); 222 | spec3 *= _SpecularPower; 223 | 224 | /* 225 | *this part is to add the sss 226 | *used front rim,back rim and BRDF 227 | */ 228 | 229 | float3 rim = (1 - dot(viewDir, n2))*_RimPower * _RimColor; 230 | float3 frontrim = (dot(viewDir, n2))*_FrontRimPower * _FrontRimColor *tex2D(_FrontRimTex, i.uv_MainTex); 231 | 232 | fixed atten = LIGHT_ATTENUATION(i); 233 | float curvature = length(fwidth(mul(_Object2World, float4(normalize(i.normal), 0)))) / 234 | length(fwidth(i.worldpos)) * _CurveScale; 235 | 236 | float3 brdf = tex2D(_BRDFTex, float2((dot(normalize(i.normal), lightDir) * 0.5 + 0.5)* atten, curvature)).rgb; 237 | 238 | float4 c2 = float4(lerp(c, ref, _ReflAmount) *(diff*_Maintint + (all*_SC) / 2)*brdf + rim + frontrim + spec3 + (all*_SC) / 2, 1); 239 | if (_WorldSpaceLightPos0.w != 0) 240 | { 241 | float dis = distance(_WorldSpaceLightPos0, i.worldpos); 242 | dis *= _AlbedoDistance; 243 | if (1 - dis > 0) 244 | c2 += tex2D(_AlbedoTex, float2(0.5, 1 - dis))*_AlbedoPower; 245 | } 246 | 247 | /* 248 | *this part add the water drop effect 249 | *the method is in the unity wiki 250 | * I add some PBR things make the water drop more sparkling and more stereoscopic,looks realistic 251 | */ 252 | float2 refrtc = i.uv_MainTex*_RefractTexTiling;//_RefractTexTiling is scale for uv 253 | float4 refract = tex2D(_RefractTex, refrtc + _SpeedStrength.xy*_Time.x); 254 | if (refract.a > 0.3) 255 | { 256 | refract.rg = refract.rg*2.0 - 1.0; 257 | 258 | float4 original = tex2D(_NonTex, i.uv_MainTex + refract.rg*_SpeedStrength.zw); 259 | 260 | n2 = UnpackNormal(tex2D(_WaterNormalTex, refrtc + _SpeedStrength.xy*_Time.x)); 261 | _SP = pow(8192, _WaterGL); 262 | d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 263 | f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 264 | k = min(1, _WaterGL + 0.545); 265 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 266 | 267 | all = d*f*v; 268 | float3 refDir = reflect(-viewDir, n2); 269 | float3 ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _WaterGL*_nMips)).rgb; 270 | 271 | original = lerp(original, float4(ref, 1), _WaterReflAmount); 272 | 273 | float4 output = lerp(original, original*_Color, refract.b); 274 | output.a = original.a; 275 | c2 += (output + all*_WaterColor / 4)* _WaterColor.a*dot(lightDir, n2); 276 | } 277 | 278 | c2 *= atten; 279 | return c2; 280 | } 281 | ENDCG 282 | } 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (1).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (2).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (3).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (4).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (5).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (5).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/1 (6).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Human skin realtime rendering/superaddition/1 (6).png -------------------------------------------------------------------------------- /Human skin realtime rendering/superaddition/HumanSkin_plus.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about human skin's real time rendering's superaddition in unity3d 4 | *add the Oren–Nayar reflectance model and Subsurface Scattering 5 | *delete rim light and the fake BRDF 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/HumanSkin_plus" { 9 | Properties{ 10 | _MainTex("Base (RGB)", 2D) = "white" {} 11 | _SpecularTex("Specular (RGB)", 2D) = "white" {} 12 | _SpecularPower("Specular Power", Range(0.04, 1)) = 1 13 | 14 | _AlbedoTex("Albedo (RGB)", 2D) = "white" {} 15 | _AlbedoPower("Albedo Power", Range(0, 20)) = 1 16 | _AlbedoDistance("Albedo Distance", Range(0.1, 2)) = 1 17 | 18 | _BlurTex1("Blur Tex 1 (RGB)", 2D) = "white" {} 19 | _BlurTex2("Blur Tex 2 (RGB)", 2D) = "white" {} 20 | _BlurTex3("Blur Tex 3 (RGB)", 2D) = "white" {} 21 | _BlurTex4("Blur Tex 4 (RGB)", 2D) = "white" {} 22 | _BlurTex5("Blur Tex 5 (RGB)", 2D) = "white" {} 23 | _BlurTex6("Blur Tex 6 (RGB)", 2D) = "white" {} 24 | 25 | _DetailTex("Detail (RGB)", 2D) = "white" {} 26 | _BumpBias("Normal Map Blur", Range(0, 5)) = 2.0 27 | _Maintint("Main Color", Color) = (1, 1, 1, 1) 28 | _SC("Specular Color", Color) = (1, 1, 1, 1) 29 | _GL("gloss", Range(0, 1)) = 0.05 30 | _nMips("nMipsF", Range(0, 5)) = 0.5 31 | 32 | 33 | _LumPow("Lum Power", Range(0, 30)) = 1 34 | _LumPow_D("Lum Power D", Range(0, 200)) = 1 35 | _G("G", Range(-1, 1)) = 0.5 36 | _Sigma_A("Sigma_A", Vector) = (1, 1, 1, 1) 37 | _Sigma_S("Sigma_S", Vector) = (1, 1, 1, 1) 38 | _DaoSanJiao("Nabla", Color) = (1, 1, 1, 1) 39 | _Eta("Eta", Range(0.5, 2)) = 1.3 40 | 41 | } 42 | SubShader{ 43 | pass{ 44 | Tags{ "LightMode" = "ForwardBase" } 45 | ZWrite on 46 | Cull Back 47 | 48 | CGPROGRAM 49 | #pragma vertex vert 50 | #pragma fragment frag 51 | #pragma target 5.0 52 | #include "UnityCG.cginc" 53 | #include "MyFunc.cginc" 54 | float _Albedo; 55 | float _LumPow; 56 | float _LumPow_D; 57 | float _Rough; 58 | float _G; 59 | float3 _Sigma_A; 60 | float3 _Sigma_S; 61 | float _Eta; 62 | float4 _SC; 63 | float _GL; 64 | float3 _DaoSanJiao; 65 | 66 | float4x4 _World2Light; 67 | float4 _LightColor0; 68 | float _SpecularPower; 69 | float4 _Maintint; 70 | float _nMips; 71 | 72 | uniform sampler2D _AlbedoTex; 73 | float _AlbedoPower; 74 | float _AlbedoDistance; 75 | 76 | uniform sampler2D _BlurTex1; 77 | uniform sampler2D _BlurTex2; 78 | uniform sampler2D _BlurTex3; 79 | uniform sampler2D _BlurTex4; 80 | uniform sampler2D _BlurTex5; 81 | uniform sampler2D _BlurTex6; 82 | 83 | uniform sampler2D _SpecularTex; 84 | uniform sampler2D _MainTex; 85 | uniform sampler2D _DetailTex; 86 | float4 _MainTex_ST; 87 | float4 _DetailTex_ST; 88 | float _BumpBias; 89 | struct v2f { 90 | float4 pos : SV_POSITION; 91 | float2 uv_MainTex : TEXCOORD0; 92 | float3 lightDir : TEXCOORD1; 93 | float3 viewDir : TEXCOORD2; 94 | float3 normal : TEXCOORD3; 95 | float4 worldPos : TEXCOORD4; 96 | float2 uv_DetailTex : TEXCOORD5; 97 | }; 98 | struct appdata { 99 | float4 vertex : POSITION; 100 | float4 tangent : TANGENT; 101 | float3 normal : NORMAL; 102 | float2 texcoord : TEXCOORD0; 103 | fixed4 color : COLOR; 104 | }; 105 | v2f vert(appdata_full v) { 106 | v2f o; 107 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 108 | o.uv_DetailTex = TRANSFORM_TEX(v.texcoord, _DetailTex); 109 | 110 | o.worldPos = mul(_Object2World, v.vertex); 111 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 112 | 113 | 114 | o.normal = v.normal; 115 | o.lightDir = ObjSpaceLightDir(v.vertex); 116 | o.viewDir = ObjSpaceViewDir(v.vertex); 117 | 118 | return o; 119 | } 120 | 121 | #define PIE 3.1415926535 122 | #define E 2.718281828459 123 | float phase(float cos_t) 124 | { 125 | return 1 / (4 * PIE)*(1 - _G*_G) / pow(1 + _G*_G - 2 * _G *cos_t, 1.5); 126 | 127 | } 128 | float Lri(float3 w_P, float phi_x, float p_L_Dist, float D) 129 | { 130 | float _Sigma_t = _Sigma_A + _Sigma_S; 131 | float L = 1 / (4 * PIE) * phi_x + 3 / (4 * PIE) * dot(w_P, -D*_DaoSanJiao * phi_x); 132 | 133 | float Lri = L * pow(E, -_Sigma_t* p_L_Dist); 134 | return Lri; 135 | } 136 | half OrenNayarDiffuse(half3 light, half3 view, half3 norm, half roughness) 137 | { 138 | half VdotN = dot(view, norm); 139 | half LdotN = dot(light, norm); 140 | half cos_theta_i = LdotN; 141 | half theta_r = acos(VdotN); 142 | half theta_i = acos(cos_theta_i); 143 | half cos_phi_diff = dot(normalize(view - norm * VdotN), 144 | normalize(light - norm * LdotN)); 145 | half alpha = max(theta_i, theta_r); 146 | half beta = min(theta_i, theta_r); 147 | half sigma2 = roughness * roughness; 148 | half A = 1.0 - 0.5 * sigma2 / (sigma2 + 0.33); 149 | half B = 0.45 * sigma2 / (sigma2 + 0.09); 150 | return saturate(cos_theta_i) *(A + (B * saturate(cos_phi_diff) * sin(alpha) * tan(beta))); 151 | } 152 | float4 frag(v2f i) :COLOR 153 | { 154 | 155 | float dis = distance(_WorldSpaceLightPos0, i.worldPos); 156 | float3 c = tex2D(_MainTex, i.uv_MainTex) * 128; 157 | c += tex2D(_BlurTex1, i.uv_MainTex) * 64; 158 | c += tex2D(_BlurTex2, i.uv_MainTex) * 32; 159 | c += tex2D(_BlurTex3, i.uv_MainTex) * 16; 160 | c += tex2D(_BlurTex4, i.uv_MainTex) * 8; 161 | c += tex2D(_BlurTex5, i.uv_MainTex) * 4; 162 | c += tex2D(_BlurTex6, i.uv_MainTex) * 2; 163 | c /= 256; 164 | 165 | float3 viewDir = normalize(i.viewDir); 166 | float3 lightDir = normalize(i.lightDir); 167 | float3 H = normalize(lightDir + viewDir); 168 | /* 169 | *this part is about blend normal, normal map and detail map 170 | *and the nomal blur also in here 171 | *this blend method is from internet 172 | */ 173 | float3 n1 = tex2Dbias(_DetailTex, float4(i.uv_MainTex, 0.0, _BumpBias)) * 2 - 1;//normalBlur 174 | float3 n2 = normalize(i.normal) * 2 - 1; 175 | 176 | float a = 1 / (1 + n1.z); 177 | float b = -n1.x*n1.y*a; 178 | 179 | float3 b1 = float3(1 - n1.x*n1.x*a, b, -n1.x); 180 | float3 b2 = float3(b, 1 - n1.y*n1.y*a, -n1.y); 181 | float3 b3 = n1; 182 | 183 | if (n1.z < -0.9999999) 184 | { 185 | b1 = float3(0, -1, 0); 186 | b2 = float3(-1, 0, 0); 187 | } 188 | 189 | float3 r = n2.x*b1 + n2.y*b2 + n2.z*b3; 190 | 191 | n2 = r*0.5 + 0.5; 192 | 193 | n2 *= 3; 194 | n2 += n1; 195 | n2 /= 4; 196 | n2 = normalize(n2); 197 | 198 | float specBase = max(0, dot(n2, H)); 199 | float spec = pow(specBase, 10) *(_GL + 0.2); 200 | spec = lerp(0, 1.2, spec); 201 | float3 spec3 = spec * (tex2D(_SpecularTex, i.uv_MainTex) - 0.1); 202 | 203 | 204 | /* 205 | *this part is compute the Subsurface Scattering 206 | */ 207 | 208 | float3 _Sigma_S_P = _Sigma_S *(1 - _G); 209 | float3 _Sigma_T_P = _Sigma_S_P + _Sigma_A; 210 | float3 _Sigma_TR = sqrt(3 * _Sigma_A * _Sigma_T_P); 211 | float3 _Sigma_t = _Sigma_A + _Sigma_S; 212 | float D = 1 / (3 * _Sigma_T_P); 213 | float p_L_Dist = 1; 214 | if (_WorldSpaceLightPos0.w != 0) 215 | { 216 | p_L_Dist = distance(_WorldSpaceLightPos0, i.worldPos); 217 | } 218 | float v_C_Dist = distance(_WorldSpaceCameraPos, i.worldPos)*0.04; 219 | v_C_Dist = v_C_Dist > 1.5 ? 1.5 : v_C_Dist; 220 | float3 phi_x = _LumPow_D / (4 * PIE*D)*pow(E, _Sigma_TR*p_L_Dist) / p_L_Dist; 221 | 222 | 223 | float Q = 0; 224 | float3 Q1 = 0; 225 | float3 w_P = 0; 226 | for (int i = 0; i < 30; i++) 227 | { 228 | w_P = normalize(float3(n2.x + rand(fixed2(i*0.05, i*0.05)), n2.y + rand(fixed2(-i*0.05, i*0.05)), n2.z + rand(fixed2(i*0.05, -i*0.05)))); 229 | 230 | Q += phase(dot(-lightDir, w_P))*Lri(w_P, phi_x, p_L_Dist, D); 231 | Q *= _Sigma_S; 232 | Q1 += Q*w_P; 233 | 234 | } 235 | 236 | float3 diff = _Sigma_A - Q - 3 * D *dot(_DaoSanJiao, Q1); 237 | 238 | float fdr = -1.440 / (_Eta*_Eta) + 0.710 / _Eta + 0.668 + 0.0636*_Eta; 239 | 240 | float A = (1 + fdr) / (1 - fdr); 241 | 242 | 243 | phi_x = _LumPow_D / (4 * PIE*D)*(pow(E, -_Sigma_TR * p_L_Dist) / p_L_Dist - pow(E, -_Sigma_TR * v_C_Dist) / v_C_Dist); 244 | 245 | float phi_x_S = 2 * A * D * dot(n2, _DaoSanJiao) * phi_x; 246 | 247 | float3 ref = -D * (dot(n2, _DaoSanJiao*phi_x_S)) / (diff*_LumPow_D); 248 | 249 | /* 250 | *this part is compute Physically-Based Rendering 251 | *the method is in the ppt about "ops2" 252 | */ 253 | float _SP = pow(8192, _GL); 254 | float d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 255 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 256 | float k = min(1, _GL + 0.545); 257 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 258 | 259 | float all = d*f*v; 260 | 261 | 262 | all = saturate(all); 263 | diff = (1 - all)*diff; 264 | diff = saturate(diff); 265 | 266 | 267 | spec3 *= Luminance(diff); 268 | spec3 = saturate(spec3); 269 | spec3 *= _SpecularPower; 270 | /* 271 | *this part is used Oren–Nayar reflectance model 272 | */ 273 | float _Albedo = saturate( OrenNayarDiffuse(lightDir, viewDir, n2, _Rough)); 274 | 275 | float4 c2 = float4(c *((diff *_Albedo + ref)*_Maintint + (all*_SC) / 2) + spec3 + (all*_SC) / 2 , 1); 276 | 277 | if (_WorldSpaceLightPos0.w != 0) 278 | { 279 | 280 | dis *= _AlbedoDistance; 281 | if (1 - dis > 0) 282 | c2 += tex2D(_AlbedoTex, float2(0.5, 1 - dis))*_AlbedoPower; 283 | } 284 | 285 | return c2; 286 | } 287 | ENDCG 288 | } 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /Post processing/Computerfault/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Computerfault/1.png -------------------------------------------------------------------------------- /Post processing/Computerfault/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Computerfault/2.png -------------------------------------------------------------------------------- /Post processing/Computerfault/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Computerfault/3.png -------------------------------------------------------------------------------- /Post processing/Computerfault/ComputerFault.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | [ExecuteInEditMode] 4 | public class ComputerFault : MonoBehaviour 5 | { 6 | public Shader curShader; 7 | private Material curMaterial; 8 | public int Step = 50; 9 | public int Speed = 1; 10 | public int Black = 0;//0/1 11 | #region Properties 12 | Material material 13 | { 14 | get 15 | { 16 | if (curMaterial == null) 17 | { 18 | curMaterial = new Material(curShader); 19 | curMaterial.hideFlags = HideFlags.HideAndDontSave; 20 | } 21 | return curMaterial; 22 | } 23 | } 24 | #endregion 25 | 26 | void Start() 27 | { 28 | if (!SystemInfo.supportsImageEffects) 29 | { 30 | enabled = false; 31 | return; 32 | } 33 | 34 | if (!curShader && !curShader.isSupported) 35 | { 36 | enabled = false; 37 | } 38 | } 39 | void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture) 40 | { 41 | if (curShader != null) 42 | { 43 | Graphics.Blit(sourceTexture, destTexture, material); 44 | } 45 | else 46 | { 47 | Graphics.Blit(sourceTexture, destTexture); 48 | } 49 | } 50 | void Update() 51 | { 52 | material.SetFloat("_Step", Step); 53 | material.SetFloat("_Speed", Speed); 54 | material.SetFloat("_Black", Black); 55 | } 56 | void OnDisable() 57 | { 58 | if (curMaterial) 59 | { 60 | DestroyImmediate(curMaterial); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Post processing/Computerfault/ComputerFault.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about when the computer is fault , the screen's effect rendering shader in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/ComputerFault" { 7 | Properties{ 8 | _MainTex("MainTex", 2D) = "white" {} 9 | _Step("Step", range(10, 100)) = 50 10 | _Speed("Speed", range(1, 10)) = 10 11 | _Black("Black", range(0, 1)) = 0 12 | } 13 | SubShader{ 14 | pass{ 15 | Tags{ "LightMode" = "ForwardBase" } 16 | Cull off 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma target 3.0 21 | #include "UnityCG.cginc" 22 | int _Step; 23 | int _Speed; 24 | int _Black; 25 | sampler2D _MainTex; 26 | float4 _MainTex_ST; 27 | struct v2f { 28 | float4 pos : SV_POSITION; 29 | float2 uv_MainTex : TEXCOORD0; 30 | }; 31 | 32 | v2f vert(appdata_full v) { 33 | v2f o; 34 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 35 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 36 | return o; 37 | } 38 | #define PIE 3.1415926535 39 | float4 frag(v2f i) :COLOR 40 | { 41 | /* 42 | *this part is compute the black noise 43 | */ 44 | float2 uv_steps = float2(_Step, _Step - _Step * i.uv_MainTex.y* _SinTime.x); 45 | float2 newUV = (floor(i.uv_MainTex * uv_steps) / uv_steps); 46 | float k = newUV.x*_Step + newUV.y*_Step; 47 | k = floor(k); 48 | k = k - floor(k / 2) * 2; 49 | 50 | /* 51 | *this part is compute the uv's warp 52 | */ 53 | float2 finUV = i.uv_MainTex + float2(sin(i.uv_MainTex.y*PIE / 2)* sin(_Time.z*_Speed * 2) / 10, 0); 54 | finUV *= 0.9; 55 | 56 | /* 57 | *this part is compute color shift 58 | */ 59 | float4 tex1 = tex2D(_MainTex, finUV); 60 | float4 tex2 = tex2D(_MainTex, finUV + float2(sin(_Time.z * _Speed) / 180, 0)); 61 | 62 | if (_Black == 1) 63 | return float4(tex1.r, tex2.g, tex1.b, 1)*k; 64 | else 65 | return float4(tex1.r, tex2.g, tex1.b, 1); 66 | 67 | } 68 | ENDCG 69 | }// 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Post processing/Depth Of Field/DOF add noise/DOF_add_noise.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about Depth Of Field with noise in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/DOF_A_N" { 7 | Properties{ 8 | _MainTex("MainTex", 2D) = "white" {} 9 | _Radius("Radius", range(2, 8)) = 3 10 | _Pixel("_Pixel", range(0.0001, 0.01)) = 0.002 11 | _Depth("Depth", range(0, 1)) = 1 12 | _DepthClip("DepthClip", range(-1, 1)) = 0 13 | _Foward_back("Foward_back", range(0, 1)) = 1 14 | } 15 | SubShader{ 16 | pass{ 17 | Tags{ "LightMode" = "ForwardBase" } 18 | Cull off 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | #pragma target 4.0 23 | #include "UnityCG.cginc" 24 | #include "MyFunc.cginc" 25 | 26 | sampler2D _CameraDepthTexture; 27 | fixed4 _CameraDepthTexture_ST; 28 | 29 | int _Foward_back; 30 | fixed _Depth; 31 | fixed _DepthClip; 32 | int _Radius; 33 | float _Pixel; 34 | sampler2D _MainTex; 35 | fixed4 _MainTex_ST; 36 | #define PI 3.1415926535 37 | struct v2f { 38 | fixed4 pos : SV_POSITION; 39 | fixed2 uv_MainTex : TEXCOORD0; 40 | 41 | }; 42 | 43 | v2f vert(appdata_full v) { 44 | v2f o; 45 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 46 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 47 | return o; 48 | } 49 | inline fixed GetDepth(fixed2 depth_uv) 50 | { 51 | fixed d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv)*0.8; 52 | return d; 53 | 54 | } 55 | fixed4 frag(v2f i) :COLOR 56 | { 57 | 58 | 59 | fixed2 uv = i.uv_MainTex; 60 | fixed depth = GetDepth(uv); 61 | fixed sigma = _Radius / 3.0; 62 | fixed sigma2 = 2.0 * sigma * sigma; 63 | fixed sigmap = sigma2 * PI; 64 | 65 | fixed4 cc = tex2D(_MainTex, i.uv_MainTex); 66 | 67 | fixed linshi = 0; 68 | 69 | int times = 6; 70 | 71 | 72 | float2 positionMod_x = 0; 73 | float checkerboard_x = 0; 74 | float2 positionMod_y = 0; 75 | float checkerboard_y = 0; 76 | float scale = 0.25; 77 | 78 | for (int n = 0, i = -times; i <= times; ++i) 79 | { 80 | int i2 = i * i; 81 | for (int j = -times; j <= times; ++j, ++n) 82 | { 83 | //checkerboard 84 | positionMod_x = float2(uint2(uv * 800) & 1); 85 | checkerboard_x = (-scale + 2.0 * scale * positionMod_x.x) * 86 | (-1.0 + 2.0 * positionMod_x.y) + 87 | 0.5 * scale * (-1.0 + 2.0 * 0.5); 88 | 89 | positionMod_y = float2(uint2(fixed2(uv.y, uv.x) * 40) & 1); 90 | checkerboard_y = (-scale + 2.0 * scale * positionMod_y.x) * 91 | (-1.0 + 2.0 * positionMod_y.y) + 92 | 0.5 * scale * (-1.0 + 2.0 * 0.5); 93 | // 94 | //rand 95 | // cc += (tex2D(_MainTex, uv + (fixed2(i*0.5, j) + fixed2(rand(uv), rand(fixed2(uv.y, uv.x))))*_Pixel)); 96 | cc += (tex2D(_MainTex, uv + (fixed2(i*0.5, j) + fixed2(checkerboard_x, checkerboard_y))*_Pixel)); 97 | } 98 | 99 | } 100 | cc /= 160; 101 | 102 | depth *= (saturate(((depth - 0.2) * 2)) + 0.01); 103 | fixed4 c = tex2D(_MainTex, uv); 104 | 105 | 106 | 107 | 108 | if (_Foward_back == 0) 109 | { 110 | cc = lerp(c, cc, lerp(0, 1, (depth + _DepthClip) * _Depth - 0.2)*1.4); 111 | 112 | } 113 | else 114 | { 115 | cc = lerp(cc, c, lerp(0, 1, (depth + _DepthClip) * _Depth - 0.3)*1.4); 116 | 117 | } 118 | 119 | return cc; 120 | } 121 | ENDCG 122 | }// 123 | 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Post processing/Depth Of Field/DOF_PP.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | [ExecuteInEditMode] 4 | public class DOF_PP : MonoBehaviour 5 | { 6 | #region Variables 7 | public Shader curShader; 8 | private Material curMaterial; 9 | public int _Radius = 3; 10 | public float _Pixel = 0.002f; 11 | public float _Depth = 0; 12 | public float _DepthClip = 0; 13 | public int _Foward_back = 1; 14 | 15 | public RenderTexture tempRtA = null; 16 | #endregion 17 | 18 | #region Properties 19 | Material material 20 | { 21 | get 22 | { 23 | if (curMaterial == null) 24 | { 25 | curMaterial = new Material(curShader); 26 | curMaterial.hideFlags = HideFlags.HideAndDontSave; 27 | } 28 | return curMaterial; 29 | } 30 | } 31 | #endregion 32 | 33 | void Start() 34 | { 35 | if (!SystemInfo.supportsImageEffects) 36 | { 37 | enabled = false; 38 | return; 39 | } 40 | 41 | if (!curShader && !curShader.isSupported) 42 | { 43 | enabled = false; 44 | } 45 | } 46 | 47 | void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture) 48 | { 49 | if (curShader != null) 50 | { 51 | tempRtA = new RenderTexture(Screen.width / 4, Screen.height / 4, 0); 52 | tempRtA.hideFlags = HideFlags.DontSave; 53 | Graphics.Blit(sourceTexture, destTexture, material); 54 | // Graphics.Blit(tempRtA, destTexture, material);//换 material 55 | // Graphics.Blit(destTexture, tempRtA, material);//换 material 56 | // Graphics.Blit(destTexture, material); 57 | } 58 | else 59 | { 60 | Graphics.Blit(sourceTexture, destTexture); 61 | } 62 | } 63 | void Update() 64 | { 65 | material.SetFloat("_Radius", _Radius); 66 | material.SetFloat("_Pixel", _Pixel); 67 | material.SetFloat("_Depth", _Depth); 68 | material.SetFloat("_DepthClip", _DepthClip); 69 | 70 | material.SetInt("_Foward_back", _Foward_back); 71 | 72 | } 73 | void OnDisable() 74 | { 75 | if (curMaterial) 76 | { 77 | DestroyImmediate(curMaterial); 78 | } 79 | } 80 | } 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /Post processing/Depth Of Field/DOF_post_process.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about Depth Of Field in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | 7 | Shader "Custom/DOF_P_P" { 8 | Properties{ 9 | _MainTex("MainTex", 2D) = "white" {} 10 | _Radius("Radius", range(2, 8)) = 3 11 | _Pixel("_Pixel", range(0.0001, 0.01)) = 0.002 12 | _Depth("Depth", range(0, 1)) = 0 13 | _DepthClip("DepthClip", range(-1, 1)) = 0 14 | _Foward_back("Foward_back", range(0, 1)) = 1 15 | } 16 | SubShader{ 17 | pass{ 18 | Tags{ "LightMode" = "ForwardBase" } 19 | Cull off 20 | CGPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | #pragma target 4.0 24 | #include "UnityCG.cginc" 25 | 26 | sampler2D _CameraDepthTexture; 27 | fixed4 _CameraDepthTexture_ST; 28 | 29 | int _Foward_back; 30 | fixed _Depth; 31 | fixed _DepthClip; 32 | int _Radius; 33 | float _Pixel; 34 | sampler2D _MainTex; 35 | fixed4 _MainTex_ST; 36 | #define PI 3.1415926535 37 | struct v2f { 38 | fixed4 pos : SV_POSITION; 39 | fixed2 uv_MainTex : TEXCOORD0; 40 | 41 | }; 42 | 43 | v2f vert(appdata_full v) { 44 | v2f o; 45 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 46 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 47 | return o; 48 | } 49 | inline fixed GetDepth(fixed2 depth_uv) 50 | { 51 | fixed d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv)*0.8; 52 | return d; 53 | 54 | } 55 | fixed4 frag(v2f i) :COLOR 56 | { 57 | 58 | 59 | fixed2 uv = i.uv_MainTex; 60 | fixed depth = GetDepth(uv); 61 | fixed sigma = _Radius / 3.0; 62 | fixed sigma2 = 2.0 * sigma * sigma; 63 | fixed sigmap = sigma2 * PI; 64 | 65 | fixed4 cc = tex2D(_MainTex, i.uv_MainTex); 66 | 67 | // fixed weight = 0; 68 | 69 | int times = 6; 70 | for (int n = 0, i = -times; i <= times; ++i) 71 | { 72 | int i2 = i * i; 73 | for (int j = -times; j <= times; ++j, ++n) 74 | { 75 | // weight = exp(-(i2 + j * j) / sigma2) / sigmap; 76 | cc += (tex2D(_MainTex, uv + fixed2(i*0.5, j)*_Pixel));//* weight); 77 | } 78 | 79 | } 80 | cc /= 160; 81 | 82 | 83 | depth *=(saturate( ((depth-0.2)*2))+0.01); 84 | fixed4 c = tex2D(_MainTex,uv); 85 | 86 | if (_Foward_back == 0) 87 | { 88 | cc = lerp(c, cc,lerp(0,1, (depth + _DepthClip) * _Depth-0.2)*1.4); 89 | 90 | } 91 | else 92 | { 93 | cc = lerp(cc, c, lerp(0,1,(depth + _DepthClip) * _Depth-0.3)*1.4); 94 | 95 | } 96 | 97 | return cc; 98 | } 99 | ENDCG 100 | }// 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof1.png -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof2.png -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof3.png -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof4.png -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof5.png -------------------------------------------------------------------------------- /Post processing/Depth Of Field/dof6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Depth Of Field/dof6.png -------------------------------------------------------------------------------- /Post processing/Distortion/Barrel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Distortion/Barrel.png -------------------------------------------------------------------------------- /Post processing/Distortion/Barrel/Barrel.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about Barrel distortion in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/Barrel" { 7 | Properties{ 8 | _MainTex("MainTex", 2D) = "white" {} 9 | _distortion("distortion", range(-3, 3)) = -0.7 10 | _cubicDistortion("cubicDistortion", range(0, 3)) = 0.4 11 | _scale("scale", range(0, 3)) = 1 12 | } 13 | SubShader{ 14 | pass{ 15 | Tags{ "LightMode" = "ForwardBase" } 16 | Cull off 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma target 4.0 21 | #include "UnityCG.cginc" 22 | float _Intensity_x; 23 | float _Intensity_y; 24 | float _P_x; 25 | float _P_y; 26 | float _distortion; 27 | float _cubicDistortion; 28 | float _scale; 29 | 30 | sampler2D _MainTex; 31 | fixed4 _MainTex_ST; 32 | struct v2f { 33 | fixed4 pos : SV_POSITION; 34 | fixed2 uv_MainTex : TEXCOORD0; 35 | 36 | }; 37 | 38 | v2f vert(appdata_full v) { 39 | v2f o; 40 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 41 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 42 | return o; 43 | } 44 | 45 | float2 barrel(float2 uv) 46 | { 47 | 48 | float2 h = uv.xy - float2(0.5, 0.5); 49 | float r2 = h.x * h.x + h.y * h.y; 50 | float f = 1.0 + r2 * (_distortion + _cubicDistortion * sqrt(r2)); 51 | 52 | return f * _scale * h + 0.5; 53 | } 54 | fixed4 frag(v2f i) :COLOR 55 | { 56 | 57 | return tex2D(_MainTex, barrel(i.uv_MainTex)); 58 | } 59 | ENDCG 60 | }// 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Post processing/Distortion/Fisheye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Distortion/Fisheye.png -------------------------------------------------------------------------------- /Post processing/Distortion/fisheye/fasheye.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about Fisheye distortion in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/fasheye" { 7 | Properties{ 8 | _MainTex("MainTex", 2D) = "white" {} 9 | _Intensity_x("Intensity x", range(0, 3)) = 0.12 10 | _Intensity_y("Intensity y", range(0, 3)) =0.12 11 | _P_x("offset x", range(-1, 1)) = 0 12 | _P_y("offset y", range(-1, 1)) = 0 13 | _scale("scale", range(0, 3)) = 1.07 14 | } 15 | SubShader{ 16 | pass{ 17 | Tags{ "LightMode" = "ForwardBase" } 18 | Cull off 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | #pragma target 4.0 23 | #include "UnityCG.cginc" 24 | float _Intensity_x; 25 | float _Intensity_y; 26 | float _P_x; 27 | float _P_y; 28 | float _scale; 29 | sampler2D _MainTex; 30 | fixed4 _MainTex_ST; 31 | struct v2f { 32 | fixed4 pos : SV_POSITION; 33 | fixed2 uv_MainTex : TEXCOORD0; 34 | 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float2 fisheye(float2 uv) 45 | { 46 | float2 n_uv = (uv - 0.5) * 2.0; 47 | 48 | float2 r_uv; 49 | r_uv.x = (1 - n_uv.y * n_uv.y) * _Intensity_y * (n_uv.x); 50 | r_uv.y = (1 - n_uv.x * n_uv.x) * _Intensity_x * (n_uv.y); 51 | return(uv* _scale - r_uv); 52 | } 53 | fixed4 frag(v2f i) :COLOR 54 | { 55 | 56 | return tex2D(_MainTex, fisheye(i.uv_MainTex)); 57 | } 58 | ENDCG 59 | }// 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Post processing/Distortion/pincushion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Distortion/pincushion.png -------------------------------------------------------------------------------- /Post processing/HDR&Bloom/HDRGlow.cs: -------------------------------------------------------------------------------- 1 | /*Hi ,I'm Lin Dong 2 | *this is an effect about HDR & Bloom 3 | *if you want to have a good vision, you can turn Color Space to the linear space 4 | *then hdr can have perfect effect 5 | * this .cs is used in camera 6 | */ 7 | 8 | 9 | using UnityEngine; 10 | using System.Collections; 11 | [ExecuteInEditMode] 12 | public class HDRGlow : MonoBehaviour { 13 | #region Variables 14 | public Shader curShader; 15 | private Material curMaterial; 16 | public float exp = 0.4f; 17 | public float bm = 0.4f; 18 | public int inten = 512; 19 | public float lum = 1f; 20 | #endregion 21 | 22 | #region Properties 23 | Material material 24 | { 25 | get 26 | { 27 | if (curMaterial == null) 28 | { 29 | curMaterial = new Material(curShader); 30 | curMaterial.hideFlags = HideFlags.HideAndDontSave; 31 | } 32 | return curMaterial; 33 | } 34 | } 35 | #endregion 36 | 37 | void Start() 38 | { 39 | if (!SystemInfo.supportsImageEffects) 40 | { 41 | enabled = false; 42 | return; 43 | } 44 | 45 | if (!curShader && !curShader.isSupported) 46 | { 47 | enabled = false; 48 | } 49 | } 50 | 51 | void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture) 52 | { 53 | if (curShader != null) 54 | { 55 | material.SetFloat("_Exp", exp); 56 | material.SetFloat("_BM", bm); 57 | material.SetFloat("_Inten", inten); 58 | material.SetFloat("_Lum", lum); 59 | Graphics.Blit(sourceTexture, destTexture, material); 60 | } 61 | else 62 | { 63 | Graphics.Blit(sourceTexture, destTexture); 64 | } 65 | } 66 | void OnDisable() 67 | { 68 | if (curMaterial) 69 | { 70 | DestroyImmediate(curMaterial); 71 | } 72 | } 73 | } 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Post processing/HDR&Bloom/HDRGlow.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/HDRGlow" { 2 | Properties{ 3 | _MainTex("base", 2D) = "white" {} 4 | _Exp("exposure", range(0, 4)) = 0.3 5 | _BM("bright Max", range(0, 4)) = 0.3 6 | _inten("intensity", range(4, 1024)) = 256//fuzzy level 7 | _Lum("Luminance", range(0, 4)) = 1 8 | } 9 | SubShader{ 10 | pass{ 11 | Tags{ "LightMode" = "ForwardBase" } 12 | Cull off 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | #include "UnityCG.cginc" 17 | 18 | float4 _LightColor0; 19 | sampler2D _MainTex; 20 | float4 _MainTex_ST; 21 | float _Exp; 22 | float _BM; 23 | float _inten; 24 | float _Lum; 25 | struct v2f { 26 | float4 pos : SV_POSITION; 27 | float2 uv_MainTex : TEXCOORD0; 28 | float3 lightDir : TEXCOORD1; 29 | float3 viewDir : TEXCOORD2; 30 | float3 normal : TEXCOORD3; 31 | 32 | }; 33 | 34 | v2f vert(appdata_full v) { 35 | v2f o; 36 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 37 | o.normal = v.normal; 38 | o.lightDir = ObjSpaceLightDir(v.vertex); 39 | o.viewDir = ObjSpaceViewDir(v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float4 frag(v2f i) :COLOR 45 | { 46 | //Bloom 47 | float3 mc00 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, 3) / _inten).rgb; 48 | float3 mc10 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, 3) / _inten).rgb; 49 | float3 mc20 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, 3) / _inten).rgb; 50 | float3 mc30 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, 3) / _inten).rgb; 51 | float3 mc40 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 3) / _inten).rgb; 52 | float3 mc50 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, 3) / _inten).rgb; 53 | float3 mc60 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, 3) / _inten).rgb; 54 | 55 | float3 mc01 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, 2) / _inten).rgb; 56 | float3 mc11 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, 2) / _inten).rgb; 57 | float3 mc21 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, 2) / _inten).rgb; 58 | float3 mc31 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, 2) / _inten).rgb; 59 | float3 mc41 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 2) / _inten).rgb; 60 | float3 mc51 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, 2) / _inten).rgb; 61 | float3 mc61 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, 2) / _inten).rgb; 62 | 63 | float3 mc02 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, 1) / _inten).rgb; 64 | float3 mc12 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, 1) / _inten).rgb; 65 | float3 mc22 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, 1) / _inten).rgb; 66 | float3 mc32 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, 1) / _inten).rgb; 67 | float3 mc42 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 1) / _inten).rgb; 68 | float3 mc52 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, 1) / _inten).rgb; 69 | float3 mc62 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, 1) / _inten).rgb; 70 | 71 | float3 mc03 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, 0) / _inten).rgb; 72 | float3 mc13 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, 0) / _inten).rgb; 73 | float3 mc23 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, 0) / _inten).rgb; 74 | float3 mc33mc = tex2D(_MainTex, i.uv_MainTex).rgb; 75 | float3 mc43 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, 0) / _inten).rgb; 76 | float3 mc53 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, 0) / _inten).rgb; 77 | float3 mc63 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, 0) / _inten).rgb; 78 | 79 | float3 mc04 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, -1) / _inten).rgb; 80 | float3 mc14 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, -1) / _inten).rgb; 81 | float3 mc24 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, -1) / _inten).rgb; 82 | float3 mc34 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, -1) / _inten).rgb; 83 | float3 mc44 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, -1) / _inten).rgb; 84 | float3 mc54 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, -1) / _inten).rgb; 85 | float3 mc64 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, -1) / _inten).rgb; 86 | 87 | float3 mc05 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, -2) / _inten).rgb; 88 | float3 mc15 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, -2) / _inten).rgb; 89 | float3 mc25 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, -2) / _inten).rgb; 90 | float3 mc35 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, -2) / _inten).rgb; 91 | float3 mc45 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, -2) / _inten).rgb; 92 | float3 mc55 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, -2) / _inten).rgb; 93 | float3 mc65 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, -2) / _inten).rgb; 94 | 95 | float3 mc06 = tex2D(_MainTex, i.uv_MainTex - fixed2(3, -3) / _inten).rgb; 96 | float3 mc16 = tex2D(_MainTex, i.uv_MainTex - fixed2(2, -3) / _inten).rgb; 97 | float3 mc26 = tex2D(_MainTex, i.uv_MainTex - fixed2(1, -3) / _inten).rgb; 98 | float3 mc36 = tex2D(_MainTex, i.uv_MainTex - fixed2(0, -3) / _inten).rgb; 99 | float3 mc46 = tex2D(_MainTex, i.uv_MainTex - fixed2(-1, -3) / _inten).rgb; 100 | float3 mc56 = tex2D(_MainTex, i.uv_MainTex - fixed2(-2, -3) / _inten).rgb; 101 | float3 mc66 = tex2D(_MainTex, i.uv_MainTex - fixed2(-3, -3) / _inten).rgb; 102 | float3 c = 0; 103 | 104 | c += (mc00 + mc60 + mc06 + mc66);//4 105 | c += 2 * (mc10 + mc50 + mc15 + mc56 + mc65 + mc01 + mc05 + mc16);//8 106 | c += 6 * (mc20 + mc11 + mc02 + mc40 + mc51 + mc62 + mc04 + mc15 + mc26 + mc64 + mc55 + mc46);//72 107 | c += 14 * (mc30 + mc03 + mc63 + mc36);//56 108 | c += 24 * (mc21 + mc12 + mc41 + mc52 + mc14 + mc25 + mc54 + mc45);//192 109 | c += 32 * (mc31 + mc13 + mc53 + mc35);//128 110 | c += 54 * (mc22 + mc42 + mc24 + mc44);//216 111 | c += 67 * (mc32 + mc23 + mc43 + mc34);//268 112 | c += 80 * mc33mc;//80 113 | c /= 1024; 114 | float lum = Luminance(c); 115 | 116 | 117 | c = mc33mc + c * (lum + 0.1) * _Lum; 118 | //HDR 119 | float y = dot(float4(0.3,0.59,0.11,1),c); 120 | float yd = _Exp * (_Exp / _BM + 1) / (_Exp + 1); 121 | float4 c2 = float4(c,1); 122 | return c2*yd; 123 | } 124 | ENDCG 125 | }// 126 | 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/Conventional geometry-aware filtering.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about denoise technique in Square Enix's paper 4 | *maybe something wrong, welcome to contect me 5 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 6 | */ 7 | Shader "Custom/Conventional geometry-aware filtering" { 8 | Properties{ 9 | _MainTex("Base (RGB)", 2D) = "white" {} 10 | _Color("color", Color) = (1, 1, 1, 1) 11 | _inten("intensity", range(4, 1024)) = 512 12 | // Gaussian 13 | _A("A", Range(0.001, 5)) = 1//amplitude 14 | _Sigma_x("SigmaX", Range(0.001, 5)) = 1// x spreads of the blob 15 | _Sigma_y("SigmaY", Range(0.001, 5)) = 1// y spreads of the blob 16 | _X0("X0", Range(-3, 3)) = 0 17 | _Y0("Y0", Range(-3, 3)) = 0 18 | //W 19 | _Sigma_z("SigmaZ", Range(0.001, 5)) = 1 20 | _Sigma_n("SigmaN", Range(0.001, 5)) = 1 21 | } 22 | SubShader{ 23 | pass{ 24 | Tags{ "RenderType" = "Opaque" } 25 | CGPROGRAM 26 | #pragma vertex vert 27 | #pragma fragment frag 28 | 29 | #include "UnityCG.cginc" 30 | #include "MyFunc.cginc" 31 | sampler2D _CameraNormalsTexture; 32 | sampler2D _CameraDepthNormalsTexture; 33 | float4 _CameraDepthNormalsTexture_ST; 34 | 35 | sampler2D _CameraDepthTexture; 36 | float4 _CameraDepthTexture_ST; 37 | float4 _Color; 38 | 39 | 40 | float _inten; 41 | float _A; 42 | float _Sigma_x; 43 | float _Sigma_y; 44 | float _X0; 45 | float _Y0; 46 | float _Sigma_z; 47 | float _Sigma_n; 48 | 49 | uniform sampler2D _MainTex; 50 | float4 _MainTex_ST; 51 | 52 | struct v2f { 53 | float4 pos : SV_POSITION; 54 | float2 uv_MainTex : TEXCOORD0; 55 | float2 uv_CN : TEXCOORD1; 56 | float4 screen : TEXCOORD4; 57 | }; 58 | v2f vert(appdata_full v) { 59 | v2f o; 60 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 61 | o.uv_CN = TRANSFORM_TEX(v.texcoord, _CameraDepthNormalsTexture); 62 | o.screen = ComputeScreenPos(o.pos); 63 | COMPUTE_EYEDEPTH(o.screen.z); 64 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 65 | return o; 66 | } 67 | inline float Gaussian(float x, float y) 68 | { 69 | return _A * exp(-(((pow((x - _X0), 2)) / (2 * _Sigma_x *_Sigma_x)) + 70 | ((pow((y - _Y0), 2)) / (2 * _Sigma_y *_Sigma_y)))); 71 | 72 | } 73 | inline float GetDepth(float2 depth_uv) 74 | { 75 | float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv)*0.8; 76 | return d; 77 | 78 | } 79 | inline float4 GetNormal(float2 depth_uv) 80 | { 81 | return tex2D(_CameraNormalsTexture, depth_uv); 82 | 83 | } 84 | float4 frag(v2f i) :COLOR 85 | { 86 | 87 | float2 i_ = i.uv_MainTex; 88 | 89 | float2 j1 = i.uv_MainTex + fixed2(1, -1) / _inten; 90 | float2 j2 = i.uv_MainTex + fixed2(1, 1) / _inten; 91 | 92 | float wz = Gaussian(GetDepth(i_) - GetDepth(i_), _Sigma_z); 93 | float wn = Gaussian(GetNormal(i_) - GetNormal(i_), _Sigma_z); 94 | 95 | float w = wz * wn; 96 | 97 | 98 | float wz1 = Gaussian(GetDepth(i_) - GetDepth(j1), _Sigma_z); 99 | float wn1 = Gaussian(GetNormal(i_) - GetNormal(j1), _Sigma_z); 100 | 101 | float w1 = wz1 * wn1; 102 | 103 | 104 | float wz2 = Gaussian(GetDepth(i_) - GetDepth(j2), _Sigma_z); 105 | float wn2 = Gaussian(GetNormal(i_) - GetNormal(j2), _Sigma_z); 106 | 107 | float w2 = wz2 * wn2; 108 | 109 | float4 c = tex2D(_MainTex, i_); 110 | float4 c1 = tex2D(_MainTex, j1); 111 | float4 c2 = tex2D(_MainTex, j2); 112 | 113 | float lum = Luminance(c); 114 | float lum1 = Luminance(c1); 115 | float lum2 = Luminance(c2); 116 | 117 | 118 | if (abs(lum - lum2)>0.1&&abs(lum - lum1)>0.1&& (abs(w - w2) < 0.2)) 119 | return c2; 120 | return c; 121 | 122 | } 123 | ENDCG 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/Specular Lobe-Aware Filtering and Upsampling.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about denoise technique in Square Enix's paper 4 | *maybe something wrong, welcome to contect me 5 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 6 | */ 7 | 8 | Shader "Custom/Specular Lobe-Aware Filtering and Upsampling" { 9 | Properties{ 10 | _MainTex("Base (RGB)", 2D) = "white" {} 11 | _Color("color", Color) = (1, 1, 1, 1) 12 | _inten("intensity", range(4, 1024)) = 512 13 | 14 | _Tau("Tau", Range(0.001, 5)) = 1 15 | _Beta("Beta", Range(-5, 5)) = 1 16 | 17 | _SC("Specular Color", Color) = (1, 1, 1, 1) 18 | _GL("gloss", Range(0, 2)) = 0.5 19 | } 20 | SubShader{ 21 | pass{ 22 | CGPROGRAM 23 | #pragma vertex vert 24 | #pragma fragment frag 25 | #include "UnityCG.cginc" 26 | #include "MyFunc.cginc" 27 | sampler2D _CameraNormalsTexture; 28 | sampler2D _CameraDepthNormalsTexture; 29 | fixed4 _CameraDepthNormalsTexture_ST; 30 | 31 | sampler2D _CameraDepthTexture; 32 | fixed4 _CameraDepthTexture_ST; 33 | fixed4 _Color; 34 | float4x4 _ViewProjectInverse; 35 | fixed _inten; 36 | fixed _Tau; 37 | fixed _Beta; 38 | float4 _SC; 39 | float _GL; 40 | 41 | 42 | uniform sampler2D _MainTex; 43 | fixed4 _MainTex_ST; 44 | #define PIE 3.1415926535 45 | #define E 2.718281828459 46 | struct v2f { 47 | fixed4 pos : SV_POSITION; 48 | fixed2 uv_MainTex : TEXCOORD0; 49 | fixed2 uv_CN : TEXCOORD1; 50 | float3 lightDir : TEXCOORD2; 51 | float3 viewDir : TEXCOORD3; 52 | fixed4 screen : TEXCOORD4; 53 | }; 54 | v2f vert(appdata_full v) { 55 | v2f o; 56 | o.lightDir = ObjSpaceLightDir(v.vertex); 57 | o.viewDir = WorldSpaceViewDir(v.vertex); 58 | fixed3 worldUp = fixed3(0, 1, 0); 59 | o.viewDir = o.viewDir - worldUp * dot(o.viewDir, worldUp); 60 | 61 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 62 | o.uv_CN = TRANSFORM_TEX(v.texcoord, _CameraDepthNormalsTexture); 63 | o.screen = ComputeScreenPos(o.pos); 64 | COMPUTE_EYEDEPTH(o.screen.z); 65 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 66 | 67 | return o; 68 | } 69 | 70 | 71 | fixed Ci(float ai, fixed Y, fixed x, fixed uv_now, fixed uv_tar) 72 | { 73 | fixed ci = 0; 74 | 75 | ++x; 76 | for (int i = 0 * x; i < 10 * x; i++) 77 | { 78 | x = i; 79 | ci += ai; 80 | } 81 | return ci; 82 | } 83 | fixed Pi(float ai, fixed Y, fixed x, fixed uv_now, fixed uv_tar) 84 | { 85 | return Ci(ai, Y, 1, uv_now, uv_tar); 86 | fixed pi = 0; 87 | 88 | ++x; 89 | fixed ci = Ci(ai, Y, x, uv_now, uv_tar); 90 | fixed ci_i = 0; 91 | for (int i = 0 * x; i < 10 * x; i++) 92 | { 93 | x = i; 94 | ci_i = Ci(ai, Y, x * 2, uv_now, uv_tar); 95 | pi += ci_i*ci_i; 96 | } 97 | pi = ci / (sqrt(pi) + 1); 98 | return pi; 99 | } 100 | fixed Qij(float ai, fixed Y, fixed uv_now_i, fixed uv_tar_i, fixed uv_now_j, fixed uv_tar_j) 101 | { 102 | return Pi(ai, Y, 1, uv_now_i, uv_tar_i)* Pi(ai, Y, 1, uv_now_j, uv_tar_j); 103 | fixed Qi = 0; 104 | fixed Qj = 0; 105 | fixed Qall = 0; 106 | for (int i = 1; i < 10; i++) 107 | { 108 | Qi += Pi(ai, Y, i, uv_now_i, uv_tar_i); 109 | Qj += Pi(ai, Y, i, uv_now_j, uv_tar_j); 110 | Qall += Qi* Qj; 111 | } 112 | return Qall; 113 | } 114 | fixed Delta_2(fixed x_a) 115 | { 116 | fixed del = 0; 117 | for (int i = -40; i < 40; i += 2) 118 | { 119 | del += pow(E, i*x_a); 120 | } 121 | del *= 2; 122 | del /= (2 * PIE); 123 | 124 | return del; 125 | 126 | } 127 | inline float4 GetNormal(float2 uv) 128 | { 129 | return tex2D(_CameraNormalsTexture, uv); 130 | 131 | } 132 | inline float GetDepth(float2 depth_uv) 133 | { 134 | float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv)*0.8; 135 | return d; 136 | 137 | } 138 | float4 SamplePositionMap(float2 uvCoord) { 139 | float depth = GetDepth(uvCoord); 140 | float4 H = float4((uvCoord.x) * 2 - 1, (uvCoord.y) * 2 - 1, depth, 1.0); 141 | float4 D = mul(_ViewProjectInverse, H); 142 | return D / D.w; 143 | } 144 | fixed4 frag(v2f i) :COLOR 145 | { 146 | float3 viewDir = _WorldSpaceCameraPos - SamplePositionMap(i.uv_MainTex).xyz; 147 | 148 | float3 lightDir = normalize(i.lightDir); 149 | float3 H = normalize(lightDir + viewDir); 150 | float3 N = normalize(GetNormal(i.uv_MainTex)); 151 | float _SP = pow(8192, _GL); 152 | float d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 153 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 154 | float k = min(1, _GL + 0.545); 155 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 156 | float all = d*f*v; 157 | 158 | float ai = v * max(dot(N, lightDir), 0); 159 | 160 | fixed2 j2 = i.uv_MainTex + fixed2(1, 1) / _inten; 161 | fixed2 j3 = i.uv_MainTex + fixed2(1, -1) / _inten; 162 | fixed2 j4 = i.uv_MainTex + fixed2(-1, 1) / _inten; 163 | fixed2 j5 = i.uv_MainTex + fixed2(-1, -1) / _inten; 164 | 165 | 166 | viewDir = _WorldSpaceCameraPos - SamplePositionMap(j2).xyz; 167 | 168 | H = normalize(lightDir + viewDir); 169 | N = normalize(GetNormal(j2)); 170 | d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 171 | f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 172 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 173 | 174 | float ai2 = v * max(dot(N, lightDir), 0); 175 | 176 | 177 | 178 | 179 | viewDir = _WorldSpaceCameraPos - SamplePositionMap(j3).xyz; 180 | 181 | H = normalize(lightDir + viewDir); 182 | N = normalize(GetNormal(j3)); 183 | d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 184 | f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 185 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 186 | 187 | float ai3 = v * max(dot(N, lightDir), 0); 188 | 189 | 190 | 191 | 192 | viewDir = _WorldSpaceCameraPos - SamplePositionMap(j4).xyz; 193 | 194 | H = normalize(lightDir + viewDir); 195 | N = normalize(GetNormal(j4)); 196 | d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 197 | f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 198 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 199 | 200 | float ai4 = v * max(dot(N, lightDir), 0); 201 | 202 | 203 | 204 | 205 | 206 | viewDir = _WorldSpaceCameraPos - SamplePositionMap(j5).xyz; 207 | 208 | H = normalize(lightDir + viewDir); 209 | N = normalize(GetNormal(j5)); 210 | d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 211 | f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 212 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 213 | 214 | float ai5 = v * max(dot(N, lightDir), 0); 215 | 216 | 217 | 218 | float4 c = tex2D(_MainTex, i.uv_MainTex); 219 | float4 c2 = tex2D(_MainTex, j2); 220 | float4 c3 = tex2D(_MainTex, j3); 221 | float4 c4 = tex2D(_MainTex, j4); 222 | float4 c5 = tex2D(_MainTex, j5); 223 | 224 | 225 | float lum = Luminance(c); 226 | float lum2 = Luminance(c2); 227 | float lum3 = Luminance(c3); 228 | float lum4 = Luminance(c4); 229 | float lum5 = Luminance(c5); 230 | 231 | float Lr = 0; 232 | 233 | Lr = (lum)*ai* Delta_2(-1 / _inten) * 2; 234 | Lr += (lum)*ai; 235 | 236 | float I = Lr; 237 | Lr = (lum2)*ai* Delta_2(-1 / _inten) * 2; 238 | Lr += (lum2)*ai; 239 | 240 | 241 | float I3 = 0; 242 | I3 = (lum3)*ai* Delta_2(-1 / _inten) * 2; 243 | I3 += (lum3)*ai; 244 | 245 | 246 | 247 | float I4 = 0; 248 | I4 = (lum4)*ai* Delta_2(-1 / _inten) * 2; 249 | I4 += (lum4)*ai; 250 | 251 | float I5 = 0; 252 | I5 = (lum5)*ai* Delta_2(-1 / _inten) * 2; 253 | I5 += (lum5)*ai; 254 | 255 | fixed w = pow(Qij(ai, I, i.uv_MainTex.x, i.uv_MainTex.x, i.uv_MainTex.y, i.uv_MainTex.y), _Beta); 256 | fixed w2 = pow(Qij(ai2, I, i.uv_MainTex.x, j2.x, i.uv_MainTex.y, j2.y), _Beta); 257 | // fixed w3 = pow(Qij(ai3, I, i.uv_MainTex.x, j3.x, i.uv_MainTex.y, j3.y), _Beta); 258 | 259 | // fixed w4 = pow(Qij(ai4, I, i.uv_MainTex.x, j4.x, i.uv_MainTex.y, j4.y), _Beta); 260 | // fixed w5 = pow(Qij(ai5, I, i.uv_MainTex.x, j5.x, i.uv_MainTex.y, j5.y), _Beta); 261 | 262 | 263 | if (GetDepth(i.uv_MainTex) > 0.74) 264 | { 265 | if (abs(lum - lum2) > 0.05&& abs(lum - lum3) > 0.05&& abs(lum - lum4) > 0.04 && abs(lum - lum5) > 0.04)// && (abs(w - w2)< 0.5)) 266 | return c2; 267 | return c; 268 | 269 | } 270 | 271 | 272 | if (abs(lum - lum2) > 0.06&& abs(lum - lum3) > 0.06&& abs(lum - lum4) > 0.06 && abs(lum - lum5) > 0.06 && (abs(w - w2)< 0.5)) 273 | return c2; 274 | return c; 275 | 276 | if ((I - Lr > 0.1 &&I - I3 > 0.1&&I - I4 > 0.1&&I - I5 > 0.1) || (I5 - I > 0.1&&I4 - I > 0.1&&I3 - I > 0.1&& Lr - I > 0.1) && (abs(w - w2) * 100 < 0.5)) 277 | return c2;// (c2 + c3 + c4 + c5)*0.25; 278 | else 279 | return c; 280 | 281 | } 282 | ENDCG 283 | } 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/c 3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Real-Time Denoising in games/c 3.jpg -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/cds.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Real-Time Denoising in games/cds.jpg -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/d2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Real-Time Denoising in games/d2.jpg -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/s 2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Real-Time Denoising in games/s 2.jpg -------------------------------------------------------------------------------- /Post processing/Real-Time Denoising in games/s 3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/Real-Time Denoising in games/s 3.jpg -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/FXAA.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about FXAA 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/FXAA" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(2, 2048)) = 512 12 | } 13 | SubShader{ 14 | pass{ 15 | Tags{ "LightMode" = "ForwardBase" } 16 | Cull off 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #include "UnityCG.cginc" 21 | #include "MyFunc.cginc" 22 | 23 | float _Size; 24 | 25 | float4 _LightColor0; 26 | sampler2D _MainTex; 27 | float4 _MainTex_TexelSize; 28 | float4 _MainTex_ST; 29 | struct v2f { 30 | float4 pos : SV_POSITION; 31 | float2 uv_MainTex : TEXCOORD0; 32 | 33 | }; 34 | 35 | v2f vert(appdata_full v) { 36 | v2f o; 37 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 38 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 39 | return o; 40 | } 41 | 42 | float4 frag(v2f i) :COLOR 43 | { 44 | 45 | float u_texelDelta = 1 / _Size; 46 | 47 | 48 | 49 | float FXAA_SPAN_MAX = 8.0; 50 | float FXAA_REDUCE_MUL = 1.0 / 8.0; 51 | float FXAA_REDUCE_MIN = (1.0 / 128.0); 52 | 53 | float3 rgbNW = tex2D(_MainTex, i.uv_MainTex + (float2(-1.0, -1.0) * u_texelDelta)).xyz; 54 | float3 rgbNE = tex2D(_MainTex, i.uv_MainTex + (float2(+1.0, -1.0) * u_texelDelta)).xyz; 55 | float3 rgbSW = tex2D(_MainTex, i.uv_MainTex + (float2(-1.0, +1.0) * u_texelDelta)).xyz; 56 | float3 rgbSE = tex2D(_MainTex, i.uv_MainTex + (float2(+1.0, +1.0) * u_texelDelta)).xyz; 57 | float3 rgbM = tex2D(_MainTex, i.uv_MainTex).xyz; 58 | 59 | float3 luma = float3(0.299, 0.587, 0.114); 60 | float lumaNW = dot(rgbNW, luma); 61 | float lumaNE = dot(rgbNE, luma); 62 | float lumaSW = dot(rgbSW, luma); 63 | float lumaSE = dot(rgbSE, luma); 64 | float lumaM = dot(rgbM, luma); 65 | 66 | float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); 67 | float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); 68 | 69 | float2 dir; 70 | dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); 71 | dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); 72 | 73 | float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); 74 | 75 | float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce); 76 | 77 | dir = min(float2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), 78 | max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * u_texelDelta; 79 | 80 | float3 rgbA = (1.0 / 2.0) * ( 81 | tex2D(_MainTex, i.uv_MainTex + dir * (1.0 / 3.0 - 0.5)).xyz + 82 | tex2D(_MainTex, i.uv_MainTex + dir * (2.0 / 3.0 - 0.5)).xyz); 83 | float3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * ( 84 | tex2D(_MainTex, i.uv_MainTex + dir * (0.0 / 3.0 - 0.5)).xyz + 85 | tex2D(_MainTex, i.uv_MainTex + dir * (3.0 / 3.0 - 0.5)).xyz); 86 | 87 | float lumaB = dot(rgbB, luma); 88 | 89 | if ((lumaB < lumaMin) || (lumaB > lumaMax)){ 90 | return float4( rgbA,1); 91 | } 92 | else { 93 | return float4(rgbB, 1); 94 | } 95 | //整体上是一个边缘检测,在边缘处进行采样模糊 96 | 97 | } 98 | ENDCG 99 | }// 100 | 101 | } 102 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/Retroc_CRT.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about CRT 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/Retroc_CRT" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(0.00005, 0.0008)) = 0.0001 12 | _Inten("Inten", range(0.5, 4)) = 2 13 | } 14 | SubShader{ 15 | pass{ 16 | Tags{ "LightMode" = "ForwardBase" } 17 | Cull off 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #include "UnityCG.cginc" 22 | #include "MyFunc.cginc" 23 | 24 | float _Size; 25 | float _Inten; 26 | 27 | float4 _LightColor0; 28 | sampler2D _MainTex; 29 | float4 _MainTex_TexelSize; 30 | float4 _MainTex_ST; 31 | struct v2f { 32 | float4 pos : SV_POSITION; 33 | float2 uv_MainTex : TEXCOORD0; 34 | 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float4 frag(v2f i) :COLOR 45 | { 46 | 47 | // scanlines 48 | float vPos = float((i.uv_MainTex.y + _Time.z * 0.5) * 272.0); 49 | float j = 2; 50 | float line_intensity = modf(float(vPos), j); 51 | 52 | // color shift 53 | float off = line_intensity *0.00001; 54 | float2 shift = float2(off, 0); 55 | 56 | // shift R and G channels to simulate NTSC color bleed 57 | float2 colorShift = float2(0.001, 0); 58 | float r = tex2D(_MainTex, i.uv_MainTex + colorShift + shift).x; 59 | float g = tex2D(_MainTex, i.uv_MainTex - colorShift + shift).y; 60 | float b = tex2D(_MainTex, i.uv_MainTex).z; 61 | 62 | float4 c = float4(r, g * 0.99, b, 1) * clamp(line_intensity, 0.85, 1); 63 | 64 | float rollbar = sin((i.uv_MainTex.y + _Time.z) * 30); 65 | 66 | return c + (rollbar * 0.02); 67 | } 68 | ENDCG 69 | }// 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/aacolor.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about aacolor 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/aacolor" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(2, 2048)) = 1024 12 | _A("saturation", range(0.1, 2)) = 1.20// saturation 13 | _B("brightness", range(0.1, 2)) = 1.00 // brightness 14 | _C("contrast", range(0.1, 2)) = 1.25 // contrast 15 | _C_ch("color channel intensity", Vector) = (1, 1, 1, 1)// rgb color channel intensity 16 | 17 | } 18 | SubShader{ 19 | pass{ 20 | Tags{ "LightMode" = "ForwardBase" } 21 | Cull off 22 | CGPROGRAM 23 | #pragma vertex vert 24 | #pragma fragment frag 25 | #include "UnityCG.cginc" 26 | #include "MyFunc.cginc" 27 | float _Size; 28 | float _A; 29 | float _B; 30 | float _C; 31 | float3 _C_ch; 32 | 33 | float4 _LightColor0; 34 | sampler2D _MainTex; 35 | float4 _MainTex_TexelSize; 36 | float4 _MainTex_ST; 37 | struct v2f { 38 | float4 pos : SV_POSITION; 39 | float2 uv_MainTex : TEXCOORD0; 40 | 41 | }; 42 | 43 | v2f vert(appdata_full v) { 44 | v2f o; 45 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 46 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 47 | return o; 48 | } 49 | 50 | 51 | float contrast0(float x) 52 | { 53 | return x; 54 | } 55 | 56 | float contrast1(float x) 57 | { 58 | x = x*1.1547 - 1.0; 59 | return sign(x)*pow(abs(x), 1.0 / _C)*0.86 + 0.86; 60 | } 61 | 62 | float contrast2(float x) 63 | { 64 | return normalize(float2(pow(x, _C), pow(0.86, _C))).x*1.72; 65 | } 66 | 67 | float contrast3(float x) 68 | { 69 | return 1.73*pow(0.57735*x, _C); 70 | } 71 | 72 | float contrast4(float x) 73 | { 74 | return clamp(0.866 + _C*(x - 0.866), 0.05, 1.73); 75 | } 76 | 77 | float4 frag(v2f i) :COLOR 78 | { 79 | 80 | 81 | float size = 1 / _Size; 82 | 83 | float3 c10 = tex2D(_MainTex, i.uv_MainTex + float2(0, -1)*size).rgb; 84 | float3 c01 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 0)*size).rgb; 85 | float3 c11 = tex2D(_MainTex, i.uv_MainTex).rgb; 86 | float3 c21 = tex2D(_MainTex, i.uv_MainTex + float2(1, 0)*size).rgb; 87 | float3 c12 = tex2D(_MainTex, i.uv_MainTex + float2(0, 1)*size).rgb; 88 | 89 | float3 dt = float3(1.0, 1.0, 1.0); 90 | float k1 = dot(abs(c01 - c21), dt); 91 | float k2 = dot(abs(c10 - c12), dt); 92 | 93 | float3 color = (k1*(c10 + c12) + k2*(c01 + c21) + 0.001*c11) / (2.0*(k1 + k2) + 0.001); 94 | 95 | float x = sqrt(dot(color, color)); 96 | 97 | color.r = pow(color.r + 0.001, _A); 98 | color.g = pow(color.g + 0.001, _A); 99 | color.b = pow(color.b + 0.001, _A); 100 | 101 | //饱和度,亮度,对比度,色调映射 102 | return float4(contrast4(x)*normalize(color*_C_ch)*_B,1); 103 | 104 | } 105 | ENDCG 106 | }// 107 | 108 | } 109 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/bloom.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about bloom 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/bloom " { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(2, 2048)) = 512 12 | _Amount("amount", range(0, 1)) = 0.6 13 | _Power("_Power", range(0, 1)) = 0.5 14 | } 15 | SubShader{ 16 | pass{ 17 | Tags{ "LightMode" = "ForwardBase" } 18 | Cull off 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | #include "UnityCG.cginc" 23 | #include "MyFunc.cginc" 24 | 25 | float _Size; 26 | float _Amount; 27 | float _Power; 28 | 29 | 30 | float4 _LightColor0; 31 | sampler2D _MainTex; 32 | float4 _MainTex_TexelSize; 33 | float4 _MainTex_ST; 34 | struct v2f { 35 | float4 pos : SV_POSITION; 36 | float2 uv_MainTex : TEXCOORD0; 37 | 38 | }; 39 | 40 | v2f vert(appdata_full v) { 41 | v2f o; 42 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 43 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 44 | return o; 45 | } 46 | 47 | float4 frag(v2f i) :COLOR 48 | { 49 | float size = 1 / _Size; 50 | float2 uv = i.uv_MainTex; 51 | 52 | 53 | float3 color = tex2D(_MainTex, i.uv_MainTex); 54 | float4 sum = 0; 55 | float3 bloom; 56 | 57 | 58 | for (int i = -3; i < 3; i++) 59 | { 60 | sum += tex2D(_MainTex, uv + float2(-1, i)*size) * _Amount; 61 | sum += tex2D(_MainTex, uv + float2(0, i)*size) * _Amount; 62 | sum += tex2D(_MainTex, uv + float2(1, i)*size) * _Amount; 63 | } 64 | 65 | if (color.r < 0.3 && color.g < 0.3 && color.b < 0.3) 66 | { 67 | bloom = sum.rgb*sum.rgb*0.012 + color; 68 | } 69 | else 70 | { 71 | if (color.r < 0.5 && color.g < 0.5 && color.b < 0.5) 72 | { 73 | bloom = sum.xyz*sum.xyz*0.009 + color; 74 | } 75 | else 76 | { 77 | bloom = sum.xyz*sum.xyz*0.0075 + color; 78 | } 79 | } 80 | 81 | bloom = mix(color, bloom, _Power); 82 | 83 | return float4(bloom, 1); 84 | } 85 | ENDCG 86 | }// 87 | 88 | } 89 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/cartoon.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about cartoon 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/cartoon" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(2, 2048)) = 512 12 | _Bb("bb", range(0, 1)) = 0.5//边缘线条粗细、 13 | } 14 | SubShader{ 15 | pass{ 16 | Tags{ "LightMode" = "ForwardBase" } 17 | Cull off 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #include "UnityCG.cginc" 22 | #include "MyFunc.cginc" 23 | 24 | float _Size; 25 | float _Bb; 26 | 27 | float4 _LightColor0; 28 | sampler2D _MainTex; 29 | float4 _MainTex_TexelSize; 30 | float4 _MainTex_ST; 31 | struct v2f { 32 | float4 pos : SV_POSITION; 33 | float2 uv_MainTex : TEXCOORD0; 34 | 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float4 frag(v2f i) :COLOR 45 | { 46 | float size = 1 / _Size; 47 | 48 | float3 c00 = tex2D(_MainTex, i.uv_MainTex + float2(-1, -1)*size).rgb; 49 | float3 c10 = tex2D(_MainTex, i.uv_MainTex + float2(0, -1)*size).rgb; 50 | float3 c20 = tex2D(_MainTex, i.uv_MainTex + float2(1, -1)*size).rgb; 51 | float3 c01 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 0)*size).rgb; 52 | float3 c11 = tex2D(_MainTex, i.uv_MainTex).rgb; 53 | float3 c21 = tex2D(_MainTex, i.uv_MainTex + float2(1, 0)*size).rgb; 54 | float3 c02 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 1)*size).rgb; 55 | float3 c12 = tex2D(_MainTex, i.uv_MainTex + float2(0, 1)*size).rgb; 56 | float3 c22 = tex2D(_MainTex, i.uv_MainTex + float2(1, 1)*size).rgb; 57 | float3 dt = float3(1.0, 1.0, 1.0); 58 | 59 | float d1 = dot(abs(c00 - c22), dt); 60 | float d2 = dot(abs(c20 - c02), dt); 61 | float hl = dot(abs(c01 - c21), dt); 62 | float vl = dot(abs(c10 - c12), dt); 63 | float d = _Bb*(d1 + d2 + hl + vl) / (dot(c11, dt) + 0.15); 64 | 65 | float lc = 4.0*length(c11); 66 | 67 | float f = frac(lc); 68 | f *= f; 69 | lc = 0.25*(floor(lc) + f*f) + 0.05; 70 | //颜色总共分为四层,把颜色灰度每层段数值再加上减到最少的小数部分,产生一些过渡效果 71 | 72 | c11 = 4.0*normalize(c11); 73 | float3 frct = frac(c11); 74 | frct *= frct; 75 | c11 = floor(c11) + 0.05*dt + frct*frct; 76 | return float4(0.25*lc*(1.1 - d*sqrt(d))*c11,1); 77 | //再用得出的灰度乘上原色值,保留了原来的颜色只是明暗分为四层,层之间有过度 78 | //通过边缘检测描边,着色道理与之前的一篇文章像似,但不完全相同, 79 | 80 | } 81 | ENDCG 82 | }// 83 | 84 | } 85 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/grayscale.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about grayscale 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/grayscale" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | } 12 | SubShader{ 13 | pass{ 14 | Tags{ "LightMode" = "ForwardBase" } 15 | Cull off 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | #include "UnityCG.cginc" 20 | #include "MyFunc.cginc" 21 | 22 | float4 _LightColor0; 23 | sampler2D _MainTex; 24 | float4 _MainTex_TexelSize; 25 | float4 _MainTex_ST; 26 | struct v2f { 27 | float4 pos : SV_POSITION; 28 | float2 uv_MainTex : TEXCOORD0; 29 | 30 | }; 31 | 32 | v2f vert(appdata_full v) { 33 | v2f o; 34 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 35 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 36 | return o; 37 | } 38 | 39 | float4 frag(v2f i) :COLOR 40 | { 41 | 42 | float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb; 43 | float luma = dot(rgb, float3(0.299, 0.587, 0.114)); 44 | 45 | return luma; 46 | 47 | } 48 | ENDCG 49 | }// 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/inversecolors.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about inversecolors 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/inversecolors" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | } 12 | SubShader{ 13 | pass{ 14 | Tags{ "LightMode" = "ForwardBase" } 15 | Cull off 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | #include "UnityCG.cginc" 20 | #include "MyFunc.cginc" 21 | 22 | float4 _LightColor0; 23 | sampler2D _MainTex; 24 | float4 _MainTex_TexelSize; 25 | float4 _MainTex_ST; 26 | struct v2f { 27 | float4 pos : SV_POSITION; 28 | float2 uv_MainTex : TEXCOORD0; 29 | 30 | }; 31 | 32 | v2f vert(appdata_full v) { 33 | v2f o; 34 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 35 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 36 | return o; 37 | } 38 | 39 | float4 frag(v2f i) :COLOR 40 | { 41 | 42 | float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb; 43 | float luma = dot(rgb, float3(0.299, 0.587, 0.114)); 44 | // luma = Luminance(rgb); 45 | float3 gray = float3(luma, luma, luma) - 0.5; 46 | rgb -= float3(0.5, 0.5, 0.5); 47 | 48 | return float4(mix(rgb, gray, 2.0) + 0.5, 1); 49 | 50 | } 51 | ENDCG 52 | }// 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/natural.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about natural 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/natural" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(0.00005, 0.0008)) = 0.0001 12 | _Inten("Inten", range(0.5, 4)) = 2 13 | } 14 | SubShader{ 15 | pass{ 16 | Tags{ "LightMode" = "ForwardBase" } 17 | Cull off 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #include "UnityCG.cginc" 22 | #include "MyFunc.cginc" 23 | 24 | float _Size; 25 | float _Inten; 26 | 27 | float4 _LightColor0; 28 | sampler2D _MainTex; 29 | float4 _MainTex_TexelSize; 30 | float4 _MainTex_ST; 31 | struct v2f { 32 | float4 pos : SV_POSITION; 33 | float2 uv_MainTex : TEXCOORD0; 34 | float4 vertex : TEXCOORD1; 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | o.vertex = v.vertex; 42 | return o; 43 | } 44 | 45 | float4 frag(v2f i) :COLOR 46 | { 47 | float3 val00 = float3(1.2, 1.2, 1.2); 48 | float3x3 RGBtoYIQ = float3x3(0.299, 0.596, 0.212, 49 | 0.587, -0.275, -0.523, 50 | 0.114, -0.321, 0.311); 51 | 52 | float3x3 YIQtoRGB = float3x3(1.0, 1.0, 1.0, 53 | 0.95568806036115671171, -0.27158179694405859326, -1.1081773266826619523, 54 | 0.61985809445637075388, -0.64687381613840131330, 1.7050645599191817149); 55 | 56 | float4 c = tex2D(_MainTex, i.uv_MainTex); 57 | float3 c1 =mul( RGBtoYIQ,c.rgb); 58 | 59 | c1 = float3(pow(c1.x, val00.x), c1.yz*val00.yz); 60 | //转换到YIQ色彩空间再加强GB颜色1.2倍 61 | return float4(mul(YIQtoRGB,c1), 1); 62 | } 63 | ENDCG 64 | }// 65 | 66 | } 67 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/scanlines.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about scanlines 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/scanlines" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Amount("Amount", range(0.3, 2)) = 1//越大线个数越少,线越宽 12 | _Inten("Inten", range(0.2, 1)) = 0.5//越大,背景色越深 13 | } 14 | SubShader{ 15 | pass{ 16 | Tags{ "LightMode" = "ForwardBase" } 17 | Cull off 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #include "UnityCG.cginc" 22 | #include "MyFunc.cginc" 23 | 24 | float _Amount; 25 | float _Inten; 26 | 27 | float4 _LightColor0; 28 | sampler2D _MainTex; 29 | float4 _MainTex_TexelSize; 30 | float4 _MainTex_ST; 31 | struct v2f { 32 | float4 pos : SV_POSITION; 33 | float2 uv_MainTex : TEXCOORD0; 34 | 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float4 frag(v2f i) :COLOR 45 | { 46 | 47 | float pos0 = ((i.uv_MainTex.y + 1.0) * 170.0*_Amount); 48 | float pos1 = cos((frac(pos0) - 0.5)*3.1415926*_Inten)*1.5; 49 | float4 rgb = tex2D(_MainTex, i.uv_MainTex); 50 | 51 | // slight contrast curve 52 | float4 color = rgb*0.5 + 0.5*rgb*rgb*1.2; 53 | 54 | // color tint 55 | color *= float4(0.9, 1.0, 0.7, 0.0); 56 | 57 | // vignette 58 | color *= 1.1 - 0.6 * (dot(i.uv_MainTex - 0.5, i.uv_MainTex - 0.5) * 2.0); 59 | 60 | return mix(float4(0, 0, 0, 0), color, pos1); 61 | } 62 | ENDCG 63 | }// 64 | 65 | } 66 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/sharpen.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about sharpen 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/sharpen" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _Size("Size", range(0.00005, 0.0008)) = 0.0001 12 | _Inten("Inten", range(0.5, 4)) = 2 13 | } 14 | SubShader{ 15 | pass{ 16 | Tags{ "LightMode" = "ForwardBase" } 17 | Cull off 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | #include "UnityCG.cginc" 22 | #include "MyFunc.cginc" 23 | 24 | float _Size; 25 | float _Inten; 26 | 27 | float4 _LightColor0; 28 | sampler2D _MainTex; 29 | float4 _MainTex_TexelSize; 30 | float4 _MainTex_ST; 31 | struct v2f { 32 | float4 pos : SV_POSITION; 33 | float2 uv_MainTex : TEXCOORD0; 34 | 35 | }; 36 | 37 | v2f vert(appdata_full v) { 38 | v2f o; 39 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 40 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 41 | return o; 42 | } 43 | 44 | float4 frag(v2f i) :COLOR 45 | { 46 | float4 c = tex2D(_MainTex, i.uv_MainTex); 47 | c -= tex2D(_MainTex, i.uv_MainTex + _Size)*7.0*_Inten; 48 | c += tex2D(_MainTex, i.uv_MainTex - _Size)*7.0*_Inten; 49 | //采样点之间的颜色差越大(边缘,色差大等处),sharp越明显 50 | return c; 51 | } 52 | ENDCG 53 | }// 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/4xHQHLSL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/4xHQHLSL.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/AAColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/AAColor.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/Bloom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/Bloom.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/CRT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/CRT.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/FXAA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/FXAA.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/FXAA未开.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/FXAA未开.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/cartoon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/cartoon.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/grayscale.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/grayscale.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/inversecolors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/inversecolors.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/natural.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/natural.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/scanlines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/scanlines.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/sharpen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/sharpen.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36—关.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36—关.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36—开.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/upscale_spline36—开.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/vignette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp/vignette.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/4xHQGLSL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/4xHQGLSL.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/AAColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/AAColor.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/BLoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/BLoom.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/FXAA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/FXAA.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/cartoon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/cartoon.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/natural.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/natural.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/原图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/原图.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-关.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-关.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-关2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-关2.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-开.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-开.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-开2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in ppsspp2/放大-开2.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/AAColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/AAColor.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/CRT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/CRT.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/bloom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/bloom.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/cartoon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/cartoon.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/fxaa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/fxaa.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/grayscale.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/grayscale.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/natural.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/natural.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/scanlines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/scanlines.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/sharpen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/sharpen.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/test in unity/vignette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Post processing/shaders from ppsspp used in Unity3d/test in unity/vignette.png -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/upscale_spline36.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about spline based resizers (spline36) 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/upscale_spline36" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | _TexelDelta_X("Texel Size X", range(0, 1)) = 0.0002//0.1->0.04->0.01->0.005 缩小//0.0002->0.000000 放大 12 | _TexelDelta_Y("Texel Size Y", range(0, 100)) = 0.0002//0.1->0.04->0.01->0.005 缩小//0.0002->0.000000 放大 13 | HALF_PIXEL("HALF PIXEL", Vector) = (0.5, 0.5, 0.5, 0.5) 14 | } 15 | SubShader{ 16 | pass{ 17 | Tags{ "LightMode" = "ForwardBase" } 18 | Cull off 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | #include "UnityCG.cginc" 23 | #include "MyFunc.cginc" 24 | float2 HALF_PIXEL; 25 | 26 | float _TexelDelta_X; 27 | float _TexelDelta_Y; 28 | // float2 u_pixelDelta; 29 | float _Size; 30 | 31 | float4 _LightColor0; 32 | sampler2D _MainTex; 33 | float4 _MainTex_TexelSize; 34 | float4 _MainTex_ST; 35 | struct v2f { 36 | float4 pos : SV_POSITION; 37 | float2 uv_MainTex : TEXCOORD0; 38 | 39 | }; 40 | 41 | v2f vert(appdata_full v) { 42 | v2f o; 43 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 44 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 45 | return o; 46 | } 47 | float spline36_0_1(float x) { 48 | return ((13.0 / 11.0 * x - 453.0 / 209.0) * x - 3.0 / 209.0) * x + 1.0; 49 | } 50 | 51 | float spline36_1_2(float x) { 52 | return ((-6.0 / 11.0 * x + 612.0 / 209.0) * x - 1038.0 / 209.0) * x + 540.0 / 209.0; 53 | } 54 | 55 | float spline36_2_3(float x) { 56 | return ((1.0 / 11.0 * x - 159.0 / 209.0) * x + 434.0 / 209.0) * x - 384.0 / 209.0; 57 | } 58 | 59 | float4 rgb(int inputX, int inputY) { 60 | // u_texelDelta = 1 / _Size; 61 | return tex2D(_MainTex, (float2(inputX, inputY) + HALF_PIXEL) *float2(_TexelDelta_X, _TexelDelta_Y)); 62 | } 63 | 64 | float4 interpolateHorizontally(float2 inputPos, int2 inputPosFloor, int dy) {//水平插入/插值 65 | float sumOfWeights = 0.0; 66 | float4 sumOfWeightedPixel = 0; 67 | 68 | float x; 69 | float weight; 70 | 71 | x = inputPos.x - float(inputPosFloor.x - 2); 72 | weight = spline36_2_3(x); 73 | sumOfWeights += weight; 74 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 2, inputPosFloor.y + dy); 75 | 76 | --x; 77 | weight = spline36_1_2(x); 78 | sumOfWeights += weight; 79 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy); 80 | 81 | --x; 82 | weight = spline36_0_1(x); 83 | sumOfWeights += weight; 84 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 0, inputPosFloor.y + dy); 85 | 86 | x = 1.0 - x; 87 | weight = spline36_0_1(x); 88 | sumOfWeights += weight; 89 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy); 90 | 91 | ++x; 92 | weight = spline36_1_2(x); 93 | sumOfWeights += weight; 94 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy); 95 | 96 | ++x; 97 | weight = spline36_2_3(x); 98 | sumOfWeights += weight; 99 | sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 3, inputPosFloor.y + dy); 100 | 101 | return sumOfWeightedPixel / sumOfWeights; 102 | } 103 | 104 | float4 process(float2 outputPos) { 105 | float2 inputPos = outputPos / float2(_TexelDelta_X, _TexelDelta_Y); 106 | int2 inputPosFloor = int2(inputPos); 107 | 108 | // Vertical interporation 109 | float sumOfWeights = 0.0; 110 | float4 sumOfWeightedPixel = 0; 111 | 112 | float weight; 113 | float y; 114 | 115 | y = inputPos.y - float(inputPosFloor.y - 2); 116 | weight = spline36_2_3(y); 117 | sumOfWeights += weight; 118 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -2); 119 | 120 | --y; 121 | weight = spline36_1_2(y); 122 | sumOfWeights += weight; 123 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -1); 124 | 125 | --y; 126 | weight = spline36_0_1(y); 127 | sumOfWeights += weight; 128 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +0); 129 | 130 | y = 1.0 - y; 131 | weight = spline36_0_1(y); 132 | sumOfWeights += weight; 133 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +1); 134 | 135 | ++y; 136 | weight = spline36_1_2(y); 137 | sumOfWeights += weight; 138 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +2); 139 | 140 | ++y; 141 | weight = spline36_2_3(y); 142 | sumOfWeights += weight; 143 | sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +3); 144 | 145 | return float4((sumOfWeightedPixel / sumOfWeights).xyz, 1.0); 146 | } 147 | float4 frag(v2f i) :COLOR 148 | { 149 | return process(i.uv_MainTex); //v_position 150 | } 151 | ENDCG 152 | }// 153 | 154 | } 155 | } -------------------------------------------------------------------------------- /Post processing/shaders from ppsspp used in Unity3d/vignette.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader's algorithm is from ppsspp 4 | *this is a shader about vignette 5 | *maybe something wrong, welcome to contect me 6 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 7 | */ 8 | Shader "Custom/vignette" { 9 | Properties{ 10 | _MainTex("Main", 2D) = "white" {} 11 | } 12 | SubShader{ 13 | pass{ 14 | Tags{ "LightMode" = "ForwardBase" } 15 | Cull off 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | #include "UnityCG.cginc" 20 | #include "MyFunc.cginc" 21 | 22 | float4 _LightColor0; 23 | sampler2D _MainTex; 24 | float4 _MainTex_TexelSize; 25 | float4 _MainTex_ST; 26 | struct v2f { 27 | float4 pos : SV_POSITION; 28 | float2 uv_MainTex : TEXCOORD0; 29 | 30 | }; 31 | 32 | v2f vert(appdata_full v) { 33 | v2f o; 34 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 35 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 36 | return o; 37 | } 38 | 39 | float4 frag(v2f i) :COLOR 40 | { 41 | 42 | float vignette = 1.1 - 0.6 * (dot(i.uv_MainTex - 0.5, i.uv_MainTex - 0.5) * 2.0); 43 | float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb; 44 | return float4(vignette * rgb, 1); 45 | 46 | } 47 | ENDCG 48 | }// 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /Realistic eye shading/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic eye shading/1.png -------------------------------------------------------------------------------- /Realistic eye shading/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic eye shading/2.png -------------------------------------------------------------------------------- /Realistic eye shading/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic eye shading/3.png -------------------------------------------------------------------------------- /Realistic eye shading/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic eye shading/4.png -------------------------------------------------------------------------------- /Realistic eye shading/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic eye shading/5.png -------------------------------------------------------------------------------- /Realistic eye shading/eye Shading.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about realistic eye rendering in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/eye Shading" { 7 | Properties{ 8 | //Cornea角膜 9 | //Iris虹膜 10 | //Sclera巩膜 11 | _Lum("Luminance", Range(0, 10)) = 4 12 | _MainTex("Base (RGB)", 2D) = "white" {} 13 | _IrisColor("cornea Color", Color) = (1, 1, 1, 1) 14 | _SCCornea("Specular Color", Color) = (1, 1, 1, 1) 15 | _SpecularTex("SpecularTex (RGB)", 2D) = "white" {} 16 | _NormalIrisTex("NormalIrisTex (RGB)", 2D) = "white" {} 17 | _MaskTex("MaskTex (RGB)", 2D) = "white" {} 18 | _NormalIrisDetialTex("Iris Detial Tex (RGB)", 2D) = "white" {} 19 | _GLCornea("gloss", Range(0, 2)) = 0.5 20 | _GLIris("Iris Gloss", Range(0, 2)) = 0.5 21 | _SPIris("Iris Specular Power", Range(1, 100)) = 20 22 | _SPScleraDetial("Sclera Detial Specular Color and Instance", Color) = (1, 1, 1, 1) 23 | 24 | _ReflAmount("ReflAmount", Range(0, 2)) = 1 25 | _Cubemap("CubeMap", CUBE) = ""{} 26 | } 27 | SubShader{ 28 | pass{ 29 | Tags{ "LightMode" = "ForwardBase" } 30 | Cull Back 31 | CGPROGRAM 32 | #pragma vertex vert 33 | #pragma fragment frag 34 | #include "UnityCG.cginc" 35 | float4 _SPScleraDetial; 36 | float _SPIris; 37 | float _Lum; 38 | float _ReflAmount; 39 | samplerCUBE _Cubemap; 40 | float4 _LightColor0; 41 | float4 _SCCornea; 42 | float4 _IrisColor; 43 | float _GLCornea; 44 | float _GLIris; 45 | sampler2D _MaskTex; 46 | sampler2D _MainTex; 47 | sampler2D _SpecularTex; 48 | sampler2D _NormalIrisTex; 49 | sampler2D _NormalIrisDetialTex; 50 | float4 _MainTex_ST; 51 | float4 _MaskTex_ST; 52 | struct v2f { 53 | float4 pos : SV_POSITION; 54 | float2 uv_MainTex : TEXCOORD0; 55 | float3 lightDir : TEXCOORD1; 56 | float3 viewDir : TEXCOORD2; 57 | float3 normal : TEXCOORD3; 58 | float2 uv_MaskTex : TEXCOORD4; 59 | }; 60 | 61 | v2f vert(appdata_full v) { 62 | v2f o; 63 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 64 | o.normal = v.normal; 65 | o.lightDir = ObjSpaceLightDir(v.vertex); 66 | o.viewDir = ObjSpaceViewDir(v.vertex); 67 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 68 | o.uv_MaskTex = TRANSFORM_TEX(v.texcoord, _MaskTex); 69 | return o; 70 | } 71 | #define PIE 3.1415926535 72 | 73 | 74 | float4 frag(v2f i) :COLOR 75 | { 76 | float3 viewDir = normalize(i.viewDir); 77 | float3 lightDir = normalize(i.lightDir); 78 | float3 H = normalize(lightDir + viewDir); 79 | float3 N = normalize(i.normal); 80 | float3 c = tex2D(_MainTex, i.uv_MainTex); 81 | /* 82 | *this part is about Iris's diffuse Color,just Color 83 | */ 84 | if (tex2D(_MaskTex, i.uv_MaskTex).a > 0.005) 85 | c = lerp(c, c*_IrisColor, tex2D(_MaskTex, i.uv_MainTex).a + 0.2); 86 | /* 87 | *this part is compute Cornea's PBR specular 88 | */ 89 | float _SP; 90 | _SP = lerp(pow(8192, lerp(0, 0.5, _GLCornea - 0.4)), pow(8192, _GLCornea), tex2D(_MaskTex, i.uv_MainTex).a + 0.005); 91 | float d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 92 | float f = _SCCornea + (1 - _SCCornea)*pow(2, -10 * dot(H, lightDir)); 93 | float k = min(1, _GLCornea + 0.545); 94 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 95 | 96 | float SpecIns = d*f*v; 97 | if (tex2D(_MaskTex, i.uv_MaskTex).a < 0.005) 98 | SpecIns *= tex2D(_SpecularTex, i.uv_MainTex); 99 | 100 | SpecIns = lerp(0, SpecIns, clamp(tex2D(_MaskTex, i.uv_MainTex).a - 0.3, 0, 1)); 101 | 102 | 103 | /* 104 | *this part is compute Iris and Sclera's PBR specular 105 | */ 106 | float3 n2; 107 | if (tex2D(_MaskTex, i.uv_MaskTex).a > 0.005) 108 | n2 = UnpackNormal(tex2D(_NormalIrisTex, i.uv_MainTex)); 109 | else 110 | n2 = UnpackNormal(tex2D(_NormalIrisDetialTex, i.uv_MainTex)); 111 | 112 | 113 | if (tex2D(_MaskTex, i.uv_MaskTex).a > 0.005) 114 | _SP = pow(8192, _GLIris); 115 | else 116 | _SP = pow(8192, lerp(1.05, 1.8, _GLIris + 0.1)); 117 | d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 118 | f = _SCCornea + (1 - _SCCornea)*pow(2, -10 * dot(H, lightDir)); 119 | k = min(1, _GLIris + 0.545); 120 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 121 | 122 | float3 refDir = reflect(-viewDir, N); 123 | float3 ref = texCUBElod(_Cubemap, float4(refDir, 0.5 - _GLCornea*0.5)).rgb; 124 | 125 | 126 | float3 diff; 127 | float roughSpecIns = d*f*v; 128 | if (tex2D(_MaskTex, i.uv_MaskTex).a < 0.005) 129 | roughSpecIns *= _SPScleraDetial.a; 130 | diff = dot(lightDir, UnpackNormal(tex2D(_NormalIrisDetialTex, i.uv_MainTex))); 131 | 132 | float3 roughSpec = roughSpecIns*tex2D(_SpecularTex, i.uv_MainTex); 133 | if (tex2D(_MaskTex, i.uv_MaskTex).a < 0.005) 134 | roughSpec *= _SPScleraDetial.rgb; 135 | 136 | 137 | 138 | return float4(c *(diff)* _Lum + roughSpec * _SPIris + SpecIns + Luminance(ref)* _ReflAmount, 1) * _LightColor0; 139 | 140 | } 141 | ENDCG 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Realistic eye shading/eye no detial Spec Shading.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about realistic eye rendering without Sclera's detial specular in unity3d 4 | *if you feel the Sclera's Specular unnatural, please look this one 5 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 6 | */ 7 | Shader "Custom/eye no detial Spec Shading" { 8 | Properties{ 9 | //cornea角膜 10 | //Iris虹膜 11 | //sclera巩膜 12 | _Lum("Luminance", Range(0, 10)) = 4 13 | _MainTex("Base (RGB)", 2D) = "white" {} 14 | _IrisColor("cornea Color", Color) = (1, 1, 1, 1) 15 | _SCCornea("Specular Color", Color) = (1, 1, 1, 1) 16 | _SpecularTex("SpecularTex (RGB)", 2D) = "white" {} 17 | _NormalIrisTex("NormalIrisTex (RGB)", 2D) = "white" {} 18 | _MaskTex("MaskTex (RGB)", 2D) = "white" {} 19 | _NormalIrisDetialTex("Iris Detial Tex (RGB)", 2D) = "white" {} 20 | _GLCornea("gloss", Range(0, 2)) = 0.5 21 | _GLIris("Iris Gloss", Range(0, 2)) = 0.5 22 | _SPIris("Iris Specular Power", Range(1, 100)) = 20 23 | 24 | _ReflAmount("ReflAmount", Range(0, 2)) = 1 25 | _Cubemap("CubeMap", CUBE) = ""{} 26 | } 27 | SubShader{ 28 | pass{ 29 | Tags{ "LightMode" = "ForwardBase" } 30 | Cull Back 31 | CGPROGRAM 32 | #pragma vertex vert 33 | #pragma fragment frag 34 | #include "UnityCG.cginc" 35 | float _SPIris; 36 | float _Lum; 37 | float _ReflAmount; 38 | samplerCUBE _Cubemap; 39 | float4 _LightColor0; 40 | float4 _SCCornea; 41 | float4 _IrisColor; 42 | float _GLCornea; 43 | float _GLIris; 44 | sampler2D _MaskTex; 45 | sampler2D _MainTex; 46 | sampler2D _SpecularTex; 47 | sampler2D _NormalIrisTex; 48 | sampler2D _NormalIrisDetialTex; 49 | float4 _MainTex_ST; 50 | float4 _MaskTex_ST; 51 | struct v2f { 52 | float4 pos : SV_POSITION; 53 | float2 uv_MainTex : TEXCOORD0; 54 | float3 lightDir : TEXCOORD1; 55 | float3 viewDir : TEXCOORD2; 56 | float3 normal : TEXCOORD3; 57 | float2 uv_MaskTex : TEXCOORD4; 58 | }; 59 | 60 | v2f vert(appdata_full v) { 61 | v2f o; 62 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 63 | o.normal = v.normal; 64 | o.lightDir = ObjSpaceLightDir(v.vertex); 65 | o.viewDir = ObjSpaceViewDir(v.vertex); 66 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 67 | o.uv_MaskTex = TRANSFORM_TEX(v.texcoord, _MaskTex); 68 | return o; 69 | } 70 | #define PIE 3.1415926535 71 | 72 | 73 | float4 frag(v2f i) :COLOR 74 | { 75 | float3 viewDir = normalize(i.viewDir); 76 | float3 lightDir = normalize(i.lightDir); 77 | float3 H = normalize(lightDir + viewDir); 78 | float3 N = normalize(i.normal); 79 | float3 c = tex2D(_MainTex, i.uv_MainTex); 80 | /* 81 | *this part is about Iris's diffuse Color,just Color 82 | */ 83 | if (tex2D(_MaskTex, i.uv_MaskTex).a > 0) 84 | c = lerp(c, c*_IrisColor, tex2D(_MaskTex, i.uv_MainTex).a + 0.2); 85 | 86 | /* 87 | *this part is compute Cornea's PBR specular 88 | */ 89 | float _SP; 90 | 91 | _SP = lerp(pow(8192, lerp(0, 0.5, _GLCornea - 0.4)),pow(8192, _GLCornea), tex2D(_MaskTex, i.uv_MainTex).a +0.005); 92 | 93 | 94 | float d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 95 | float f = _SCCornea + (1 - _SCCornea)*pow(2, -10 * dot(H, lightDir)); 96 | float k = min(1, _GLCornea + 0.545); 97 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 98 | 99 | float SpecIns = d*f*v; 100 | 101 | SpecIns = lerp(0, SpecIns, clamp(tex2D(_MaskTex, i.uv_MainTex).a - 0.3,0, 1)); 102 | 103 | /* 104 | *this part is compute Iris and Sclera's PBR specular 105 | */ 106 | float3 n2; 107 | 108 | n2 = UnpackNormal(tex2D(_NormalIrisTex, i.uv_MainTex)); 109 | 110 | 111 | if (tex2D(_MaskTex, i.uv_MaskTex).a > 0.005) 112 | _SP = pow(8192, _GLIris); 113 | 114 | 115 | d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP); 116 | f = _SCCornea + (1 - _SCCornea)*pow(2, -10 * dot(H, lightDir)); 117 | k = min(1, _GLIris + 0.545); 118 | v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 119 | 120 | float3 refDir = reflect(-viewDir, N); 121 | float3 ref = texCUBElod(_Cubemap, float4(refDir, 0.5 - _GLCornea*0.5)).rgb; 122 | 123 | 124 | float3 diff; 125 | float roughSpecIns = d*f*v; 126 | diff = dot(lightDir, UnpackNormal(tex2D(_NormalIrisDetialTex, i.uv_MainTex))); 127 | 128 | float3 roughSpec = roughSpecIns*tex2D(_SpecularTex, i.uv_MainTex); 129 | 130 | 131 | 132 | return float4(c *(diff)* _Lum + roughSpec * _SPIris + SpecIns + Luminance(ref)* _ReflAmount, 1) * _LightColor0; 133 | 134 | } 135 | ENDCG 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /Realistic plant shading/1 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic plant shading/1 (1).png -------------------------------------------------------------------------------- /Realistic plant shading/1 (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic plant shading/1 (2).png -------------------------------------------------------------------------------- /Realistic plant shading/1 (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic plant shading/1 (3).png -------------------------------------------------------------------------------- /Realistic plant shading/1 (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic plant shading/1 (4).png -------------------------------------------------------------------------------- /Realistic plant shading/1 (5).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/Realistic plant shading/1 (5).png -------------------------------------------------------------------------------- /Realistic plant shading/plant1.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about plants real time rendering in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/plant1" { 7 | Properties{ 8 | _MainTex("Base (RGB)", 2D) = "white" {} 9 | _Color(" Color", Color) = (1, 1, 1, 1) 10 | _NormalTex("Normal Tex", 2D) = "white" {} 11 | _SpecTex("Specular Tex", 2D) = "white" {} 12 | _TransTex("Transport Tex", 2D) = "white" {} 13 | _TL("Transport Level", Range(-0.5, 0.5)) = 0 14 | _Lum("Lum", Range(0, 6)) = 1 15 | _SC("Specular Color", Color) = (1, 1, 1, 1) 16 | _SCP("Specular Power", Range(0, 6)) = 1 17 | _GL("gloss", Range(0, 2)) = 0.5 18 | _RimPower("RimPower", Range(0.1, 0.8)) = 0.5 19 | _RimColor("Rim Color", Color) = (1, 1, 1, 1) 20 | _RimTex("Rim (RGB)", 2D) = "white" {} 21 | 22 | _moveDirect("move Direct", Vector) = (0, 0, 0, 0) 23 | } 24 | SubShader{ 25 | pass{ 26 | Tags{ "LightMode" = "ForwardBase" "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } 27 | Cull Back 28 | ZWrite on 29 | Blend SrcAlpha OneMinusSrcAlpha 30 | CGPROGRAM 31 | #pragma vertex vert 32 | #pragma fragment frag 33 | #include "UnityCG.cginc" 34 | float _TL; 35 | float _SCP; 36 | float _Lum; 37 | float4 _LightColor0; 38 | float4 _SC; 39 | float4 _Color; 40 | float _GL; 41 | uniform sampler2D _MainTex; 42 | uniform sampler2D _NormalTex; 43 | uniform sampler2D _SpecTex; 44 | 45 | float _RimPower; 46 | float4 _RimColor; 47 | uniform sampler2D _RimTex; 48 | uniform sampler2D _TransTex; 49 | float4 _MainTex_ST; 50 | 51 | float4 _moveDirect; 52 | struct v2f { 53 | float4 pos : SV_POSITION; 54 | float2 uv_MainTex : TEXCOORD0; 55 | float3 lightDir : TEXCOORD1; 56 | float3 viewDir : TEXCOORD2; 57 | float3 normal : TEXCOORD3; 58 | 59 | }; 60 | 61 | v2f vert(appdata_full v) { 62 | v2f o; 63 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 64 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 65 | o.normal = v.normal; 66 | o.lightDir = ObjSpaceLightDir(v.vertex); 67 | o.viewDir = ObjSpaceViewDir(v.vertex); 68 | 69 | return o; 70 | } 71 | #define PIE 3.1415926535 72 | 73 | 74 | float4 frag(v2f i) :COLOR 75 | { 76 | float4 c = tex2D(_MainTex, i.uv_MainTex); 77 | if (c.a<0.5) 78 | discard; 79 | float3 viewDir = normalize(i.viewDir); 80 | float3 lightDir = normalize(i.lightDir); 81 | float3 H = normalize(lightDir + viewDir); 82 | float3 N = normalize(i.normal); 83 | 84 | float3 n1 = UnpackNormal(tex2D(_NormalTex, i.uv_MainTex)); 85 | float3 n2 = N; 86 | 87 | N = (n1 + N) / 2; 88 | N = normalize(N); 89 | /* 90 | *this part is compute Physically-Based Rendering 91 | *the method is in the ppt about "ops2" 92 | */ 93 | 94 | float _SP = pow(8192, _GL); 95 | float d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 96 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 97 | float k = min(1, _GL + 0.545); 98 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 99 | 100 | float all = d*f*v; 101 | all = saturate(all); 102 | 103 | 104 | float3 SpecC = tex2D(_SpecTex, i.uv_MainTex); 105 | float3 TransC = tex2D(_TransTex, i.uv_MainTex); 106 | float3 diff = dot(lightDir, N); 107 | 108 | float3 rim = (1 - dot(viewDir, N))*_RimPower * _RimColor *tex2D(_RimTex, i.uv_MainTex); 109 | 110 | diff = (1 - all)*diff; 111 | diff = saturate(diff); 112 | float3 cc = (c.rgb *(diff+0.2)*_Color*_Lum + all * SpecC*_SC * _SCP); 113 | return float4(cc * 2 + rim, c.a * (1 - Luminance(TransC) + _TL)); 114 | } 115 | ENDCG 116 | } 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /Realistic plant shading/plant2.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about plants real time rendering in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/plant2" { 7 | Properties{ 8 | _MainTex("Base (RGB)", 2D) = "white" {} 9 | _Color(" Color", Color) = (1, 1, 1, 1) 10 | _NormalTex("Normal Tex", 2D) = "white" {} 11 | _SpecTex("Specular Tex", 2D) = "white" {} 12 | _TransTex("Transport Tex", 2D) = "white" {} 13 | _TL("Transport Level", Range(-0.5, 0.5)) = 0 14 | _Lum("Lum", Range(0, 6)) = 1 15 | _SC("Specular Color", Color) = (1, 1, 1, 1) 16 | _SCP("Specular Power", Range(0, 4)) = 1 17 | _GL("gloss", Range(0, 2)) = 0.5 18 | _RimPower("RimPower", Range(0.1, 0.8)) = 0.5 19 | _RimColor("Rim Color", Color) = (1, 1, 1, 1) 20 | _RimTex("Rim (RGB)", 2D) = "white" {} 21 | 22 | _moveDirect("move Direct", Vector) = (0, 0, 0, 0) 23 | } 24 | SubShader{ 25 | pass{ 26 | Tags{ "LightMode" = "ForwardBase" "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } 27 | Cull Back 28 | ZWrite on 29 | Blend SrcAlpha OneMinusSrcAlpha 30 | CGPROGRAM 31 | #pragma vertex vert 32 | #pragma fragment frag 33 | #include "UnityCG.cginc" 34 | float _TL; 35 | float _SCP; 36 | float _Lum; 37 | float4 _LightColor0; 38 | float4 _SC; 39 | float4 _Color; 40 | float _GL; 41 | uniform sampler2D _MainTex; 42 | uniform sampler2D _NormalTex; 43 | uniform sampler2D _SpecTex; 44 | 45 | float _RimPower; 46 | float4 _RimColor; 47 | uniform sampler2D _RimTex; 48 | uniform sampler2D _TransTex; 49 | float4 _MainTex_ST; 50 | 51 | float4 _moveDirect; 52 | struct v2f { 53 | float4 pos : SV_POSITION; 54 | float2 uv_MainTex : TEXCOORD0; 55 | float3 lightDir : TEXCOORD1; 56 | float3 viewDir : TEXCOORD2; 57 | float3 normal : TEXCOORD3; 58 | 59 | }; 60 | 61 | v2f vert(appdata_full v) { 62 | v2f o; 63 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 64 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 65 | o.normal = v.normal; 66 | o.lightDir = ObjSpaceLightDir(v.vertex); 67 | o.viewDir = ObjSpaceViewDir(v.vertex); 68 | 69 | return o; 70 | } 71 | #define PIE 3.1415926535 72 | 73 | 74 | float4 frag(v2f i) :COLOR 75 | { 76 | float4 c = tex2D(_MainTex, i.uv_MainTex); 77 | 78 | 79 | 80 | 81 | if (c.a < 0.5) 82 | discard; 83 | float3 viewDir = normalize(i.viewDir); 84 | float3 lightDir = normalize(i.lightDir); 85 | float3 H = normalize(lightDir + viewDir); 86 | float3 N = normalize(i.normal); 87 | 88 | float3 n1 = UnpackNormal(tex2D(_NormalTex, i.uv_MainTex)); 89 | float3 n2 = N; 90 | 91 | N = (n1 + N) / 2; 92 | N = normalize(N); 93 | /* 94 | *this part is compute Physically-Based Rendering 95 | *the method is in the ppt about "ops2" 96 | */ 97 | 98 | float _SP = pow(8192, _GL); 99 | float d = (_SP + 2) / (8 * PIE) * pow(dot(N, H), _SP); 100 | float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir)); 101 | float k = min(1, _GL + 0.545); 102 | float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k)); 103 | 104 | float all = d*f*v; 105 | all = saturate(all); 106 | 107 | 108 | float3 SpecC = tex2D(_SpecTex, i.uv_MainTex); 109 | float3 TransC = tex2D(_TransTex, i.uv_MainTex); 110 | float3 diff = dot(lightDir, N); 111 | 112 | float3 rim = (1 - dot(viewDir, N))*_RimPower * _RimColor *tex2D(_RimTex, i.uv_MainTex); 113 | 114 | 115 | diff = (1 - all)*diff; 116 | diff = saturate(diff); 117 | float3 cc = (c.rgb *(diff + 0.2)*_Color*_Lum + (all + 0.1)*(saturate(Luminance(SpecC)) + 0.1)*_SC*_SCP); 118 | return float4(cc * 2 + rim, c.a * (1 - Luminance(TransC) + _TL)); 119 | } 120 | ENDCG 121 | } 122 | } 123 | } 124 | 125 | -------------------------------------------------------------------------------- /fur/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/1.png -------------------------------------------------------------------------------- /fur/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/2.png -------------------------------------------------------------------------------- /fur/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/3.png -------------------------------------------------------------------------------- /fur/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/4.png -------------------------------------------------------------------------------- /fur/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/5.png -------------------------------------------------------------------------------- /fur/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/fur/6.png -------------------------------------------------------------------------------- /fur/fur.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about fur rendering in unity3d 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | */ 6 | Shader "Custom/sufaceshaderYuan" { 7 | Properties{ 8 | _EdgeLength("Edge length", Range(0.04, 0.5)) = 0.3 9 | _Phong("Phong Strengh", Range(0, 2)) = 0.5 10 | _MainTex("Base (RGB)", 2D) = "white" {} 11 | _Color("Color", color) = (1, 1, 1, 0) 12 | 13 | _DispTex("Disp Texture", 2D) = "gray" {} 14 | _NormalMap("Normalmap", 2D) = "bump" {} 15 | _Displacement("Displacement", Range(0, 2)) = 0.3 16 | _SpecColor("Spec color", color) = (0.5, 0.5, 0.5, 0.5) 17 | _Route("Route", Range(0, 1)) = 0.5 18 | 19 | _FrontRimColor("front Rim Color", color) = (1, 1, 1, 0) 20 | _FrontRimPow("front Rim Power", Range(0, 3)) = 1 21 | 22 | _BackRimColor("Back Rim Color", color) = (1, 1, 1, 0) 23 | _BackRimPow("Back Rim Power", Range(0, 3)) = 1 24 | 25 | _GL("Gloss", Range(0, 2)) = 0.5 26 | 27 | _LengthCull("LengthCull", Range(0.001, 1.5)) = 0.5 28 | } 29 | SubShader{ 30 | Tags{ "Queue" = "Transparent" 31 | "IgnoreProjector" = "True" 32 | "RenderType" = "Transparent" } 33 | LOD 300 34 | Cull Back 35 | CGPROGRAM 36 | #pragma target 4.0 37 | 38 | #pragma surface surf HairShader /*alpha*/ vertex:disp tessellate:tessEdge tessphong:_Phong nolightmap 39 | 40 | #include "Tessellation.cginc" 41 | #include "MyFunc.cginc" 42 | 43 | struct appdata { 44 | float4 vertex : POSITION; 45 | float4 tangent : TANGENT; 46 | float3 normal : NORMAL; 47 | float2 texcoord : TEXCOORD0; 48 | }; 49 | 50 | 51 | sampler2D _DispTex; 52 | float _Displacement; 53 | 54 | 55 | float _Route; 56 | float _Phong; 57 | float _EdgeLength; 58 | 59 | float4 tessEdge(appdata v0, appdata v1, appdata v2) 60 | { 61 | return UnityEdgeLengthBasedTess(v0.vertex, v1.vertex, v2.vertex, _EdgeLength); 62 | } 63 | 64 | struct Input { 65 | float2 uv_MainTex; 66 | float4 tangent; 67 | }; 68 | float _U; 69 | float _LengthCull; 70 | /* 71 | *this part is the vertex shader, displace vertex here(displacement mapping) 72 | */ 73 | void disp(inout appdata v) 74 | { 75 | float d = tex2Dlod(_DispTex, float4(v.texcoord.xy, 0, 0)).r * _Displacement; 76 | v.vertex.xyz += v.normal * d; 77 | /* 78 | *this part you can change the formula to make the fur curve 79 | */ 80 | if (d >= 0.1) 81 | v.vertex.y -= sin(length(v.normal * d) * 2)*v.normal* _Route; 82 | 83 | if (length(v.normal * d) > _LengthCull) 84 | v.vertex.xyz -= rand(v.vertex.xz)*v.normal*(2 * _LengthCull + 1) / ((1 + d)*(3.5 - 2 * _LengthCull)); 85 | } 86 | fixed4 _Color; 87 | sampler2D _MainTex; 88 | sampler2D _NormalMap; 89 | 90 | 91 | float4 _DC; 92 | uniform sampler2D _AlphaTex; 93 | uniform sampler2D _ShiftTex; 94 | uniform sampler2D _NormalTex; 95 | uniform sampler2D _SpecularMaskTex; 96 | float4 _SC1; 97 | float4 _SC2; 98 | float _SpecularExp1; 99 | float _SpecularExp2; 100 | float _SpecularShiftX; 101 | float _SpecularShiftY; 102 | 103 | float4 _FrontRimColor; 104 | float _FrontRimPow; 105 | 106 | float4 _BackRimColor; 107 | float _BackRimPow; 108 | 109 | float _GL; 110 | 111 | 112 | struct SurfaceOutputHair 113 | { 114 | fixed3 Albedo; 115 | fixed3 Normal; 116 | fixed3 Emission; 117 | fixed3 Specular; 118 | fixed Gloss; 119 | fixed Alpha; 120 | float3 n2; 121 | 122 | }; 123 | 124 | inline fixed4 LightingHairShader(SurfaceOutputHair s, fixed3 lightDir, fixed3 viewDir, fixed atten) 125 | { 126 | viewDir = normalize(viewDir); 127 | lightDir = normalize(lightDir); 128 | float3 H = normalize(lightDir + viewDir); 129 | float3 N = normalize(s.Normal); 130 | float frontRim = dot(viewDir, N) / 2; 131 | float BackRim = (1 - dot(viewDir, N)) / 2; 132 | 133 | float specBase = max(0, dot(N, H)); 134 | float spec = pow(specBase, 10) *(_GL + 0.2); 135 | spec = lerp(0, 0.8, spec); 136 | 137 | fixed4 c = 1; 138 | c.rgb = (s.Albedo * _LightColor0.rgb * atten) + 139 | frontRim* _FrontRimColor * _FrontRimPow*atten + 140 | BackRim * _BackRimColor * _BackRimPow*atten + 141 | spec * _SpecColor; 142 | c.a = 1; 143 | return c; 144 | } 145 | 146 | void surf(Input IN, inout SurfaceOutputHair o) { 147 | half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 148 | o.Albedo = c.rgb; 149 | o.Specular = 0.2; 150 | o.Gloss = 1.0; 151 | o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex)); 152 | 153 | float d = tex2Dlod(_DispTex, float4(IN.uv_MainTex.xy, 0, 0)).r * _Displacement; 154 | o.Alpha = 1; 155 | o.n2 = UnpackNormal(tex2D(_NormalTex, IN.uv_MainTex)); 156 | } 157 | 158 | ENDCG 159 | } 160 | FallBack "Transparent/VertexLit" 161 | } 162 | -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/Noise.cs: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this is about noise(value perlin fractal) 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | *my email: wolf_crixus@sina.cn 6 | */ 7 | using UnityEngine; 8 | using System.Collections; 9 | [ExecuteInEditMode] 10 | public class Noise : MonoBehaviour 11 | { 12 | public Texture2D texture; 13 | public int resolution = 126; 14 | // Use this for initialization 15 | int TABSIZE = 200; 16 | static bool initialized = false; 17 | /* Coefficients of basis matrix. */ 18 | 19 | 20 | 21 | void Start() 22 | { 23 | 24 | } 25 | private void OnEnable() 26 | { 27 | texture = new Texture2D(resolution, resolution, TextureFormat.RGB24, false); 28 | texture.name = "Procedural Texture"; 29 | texture.wrapMode = TextureWrapMode.Clamp; 30 | texture.filterMode = FilterMode.Bilinear; 31 | GetComponent().material.mainTexture = texture; 32 | FillTexture(); 33 | } 34 | /* public void FillTexture()//random 35 | { 36 | if (texture.width != resolution) 37 | { 38 | texture.Resize(resolution, resolution); 39 | } 40 | 41 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 42 | Vector3 point10 = new Vector3(0.5f, -0.5f); 43 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 44 | Vector3 point11 = new Vector3(0.5f, 0.5f); 45 | 46 | 47 | float stepSize = 1f / resolution; 48 | Random.seed = 42; 49 | for (int y = 0; y < resolution; y++) 50 | { 51 | Vector3 point0 = Vector3.Lerp(point00, point01, (y + 0.5f) * stepSize); 52 | Vector3 point1 = Vector3.Lerp(point10, point11, (y + 0.5f) * stepSize); 53 | for (int x = 0; x < resolution; x++) 54 | { 55 | Vector3 point = Vector3.Lerp(point0, point1, (x + 0.5f) * stepSize); 56 | texture.SetPixel(x, y, Color.white * Random.value); 57 | } 58 | } 59 | texture.Apply(); 60 | }*/ 61 | 62 | public void FillTexture()//value//perlin 63 | { 64 | if (texture.width != resolution) 65 | { 66 | texture.Resize(resolution, resolution); 67 | } 68 | 69 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 70 | Vector3 point10 = new Vector3(0.5f, -0.5f); 71 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 72 | Vector3 point11 = new Vector3(0.5f, 0.5f); 73 | 74 | 75 | float stepSize = 1f / resolution; 76 | for (int y = 0; y < resolution; y++) 77 | { 78 | Vector3 point0 = Vector3.Lerp(point00, point01, (y + 0.5f) * stepSize); 79 | Vector3 point1 = Vector3.Lerp(point10, point11, (y + 0.5f) * stepSize); 80 | for (int x = 0; x < resolution; x++) 81 | { 82 | Vector3 point = Vector3.Lerp(point0, point1, (x + 0.5f) * stepSize); 83 | texture.SetPixel(x, y, Color.white * NoiseMethod.Value3D(point, 22));// 84 | } 85 | } 86 | 87 | texture.Apply(); 88 | } 89 | 90 | 91 | /* public void FillTexture()//Fractal Noise 92 | { 93 | if (texture.width != resolution) 94 | { 95 | texture.Resize(resolution, resolution); 96 | } 97 | 98 | float frequency = 22; 99 | 100 | //[Range(1, 8)] 101 | int octaves = 6;//1普通,8烟雾状 102 | 103 | // [Range(1f, 4f)] 104 | float lacunarity = 2f; 105 | 106 | // [Range(0f, 1f)] 107 | float persistence = 0.5f; 108 | 109 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 110 | Vector3 point10 = new Vector3(0.5f, -0.5f); 111 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 112 | Vector3 point11 = new Vector3(0.5f, 0.5f); 113 | 114 | 115 | float stepSize = 1f / resolution; 116 | for (int y = 0; y < resolution; y++) 117 | { 118 | Vector3 point0 = Vector3.Lerp(point00, point01, (y + 0.5f) * stepSize); 119 | Vector3 point1 = Vector3.Lerp(point10, point11, (y + 0.5f) * stepSize); 120 | for (int x = 0; x < resolution; x++) 121 | { 122 | Vector3 point = Vector3.Lerp(point0, point1, (x + 0.5f) * stepSize); 123 | float sample = NoiseMethod.Sum(1, point, frequency, octaves, lacunarity, persistence); 124 | // if (type != NoiseMethodType.Value) 125 | // { 126 | // sample = sample * 0.5f + 0.5f; 127 | // } 128 | 129 | texture.SetPixel(x, y, Color.white * sample); 130 | } 131 | } 132 | 133 | 134 | 135 | 136 | texture.Apply(); 137 | } 138 | 139 | */ 140 | 141 | 142 | 143 | // Update is called once per frame 144 | void Update() 145 | { 146 | OnEnable(); 147 | FillTexture(); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/NoiseMethod.cs: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this is about noise(value perlin fractal) 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | *my email: wolf_crixus@sina.cn 6 | */ 7 | using UnityEngine; 8 | using System.Collections; 9 | 10 | public class NoiseMethod : MonoBehaviour 11 | { 12 | private const int hashMask = 255; 13 | [Range(1, 3)] 14 | public int dimensions = 3; 15 | // Use this for initialization 16 | void Start() 17 | { 18 | 19 | } 20 | private static int[] hash = { 21 | 151,160,137, 91, 90, 15,131, 13,201, 95, 96, 53,194,233, 7,225, 22 | 140, 36,103, 30, 69,142, 8, 99, 37,240, 21, 10, 23,190, 6,148, 23 | 247,120,234, 75, 0, 26,197, 62, 94,252,219,203,117, 35, 11, 32, 24 | 57,177, 33, 88,237,149, 56, 87,174, 20,125,136,171,168, 68,175, 25 | 74,165, 71,134,139, 48, 27,166, 77,146,158,231, 83,111,229,122, 26 | 60,211,133,230,220,105, 92, 41, 55, 46,245, 40,244,102,143, 54, 27 | 65, 25, 63,161, 1,216, 80, 73,209, 76,132,187,208, 89, 18,169, 28 | 200,196,135,130,116,188,159, 86,164,100,109,198,173,186, 3, 64, 29 | 52,217,226,250,124,123, 5,202, 38,147,118,126,255, 82, 85,212, 30 | 207,206, 59,227, 47, 16, 58, 17,182,189, 28, 42,223,183,170,213, 31 | 119,248,152, 2, 44,154,163, 70,221,153,101,155,167, 43,172, 9, 32 | 129, 22, 39,253, 19, 98,108,110, 79,113,224,232,178,185,112,104, 33 | 218,246, 97,228,251, 34,242,193,238,210,144, 12,191,179,162,241, 34 | 81, 51,145,235,249, 14,239,107, 49,192,214, 31,181,199,106,157, 35 | 184, 84,204,176,115,121, 50, 45,127, 4,150,254,138,236,205, 93, 36 | 222,114, 67, 29, 24, 72,243,141,128,195, 78, 66,215, 61,156,180, 37 | 38 | 151,160,137, 91, 90, 15,131, 13,201, 95, 96, 53,194,233, 7,225, 39 | 140, 36,103, 30, 69,142, 8, 99, 37,240, 21, 10, 23,190, 6,148, 40 | 247,120,234, 75, 0, 26,197, 62, 94,252,219,203,117, 35, 11, 32, 41 | 57,177, 33, 88,237,149, 56, 87,174, 20,125,136,171,168, 68,175, 42 | 74,165, 71,134,139, 48, 27,166, 77,146,158,231, 83,111,229,122, 43 | 60,211,133,230,220,105, 92, 41, 55, 46,245, 40,244,102,143, 54, 44 | 65, 25, 63,161, 1,216, 80, 73,209, 76,132,187,208, 89, 18,169, 45 | 200,196,135,130,116,188,159, 86,164,100,109,198,173,186, 3, 64, 46 | 52,217,226,250,124,123, 5,202, 38,147,118,126,255, 82, 85,212, 47 | 207,206, 59,227, 47, 16, 58, 17,182,189, 28, 42,223,183,170,213, 48 | 119,248,152, 2, 44,154,163, 70,221,153,101,155,167, 43,172, 9, 49 | 129, 22, 39,253, 19, 98,108,110, 79,113,224,232,178,185,112,104, 50 | 218,246, 97,228,251, 34,242,193,238,210,144, 12,191,179,162,241, 51 | 81, 51,145,235,249, 14,239,107, 49,192,214, 31,181,199,106,157, 52 | 184, 84,204,176,115,121, 50, 45,127, 4,150,254,138,236,205, 93, 53 | 222,114, 67, 29, 24, 72,243,141,128,195, 78, 66,215, 61,156,180 54 | }; 55 | private static float Smooth(float t) 56 | { 57 | return t * t * t * (t * (t * 6f - 15f) + 10f); 58 | } 59 | 60 | private static float Dot(Vector2 g, float x, float y) 61 | { 62 | return g.x * x + g.y * y; 63 | } 64 | private static float Dot(Vector3 g, float x, float y, float z) 65 | { 66 | return g.x * x + g.y * y + g.z * z; 67 | } 68 | public static float Value1D(Vector3 point, float frequency) 69 | { 70 | point *= frequency; 71 | int i = Mathf.FloorToInt(point.x); 72 | i &= hashMask; 73 | return hash[i] * (1f / hashMask); 74 | } 75 | 76 | public static float Value2D(Vector3 point, float frequency) 77 | { 78 | point *= frequency; 79 | int ix0 = Mathf.FloorToInt(point.x); 80 | int iy0 = Mathf.FloorToInt(point.y); 81 | ix0 &= hashMask; 82 | iy0 &= hashMask; 83 | int ix1 = ix0 + 1; 84 | int iy1 = iy0 + 1; 85 | 86 | int h0 = hash[ix0]; 87 | int h1 = hash[ix1]; 88 | int h00 = hash[h0 + iy0]; 89 | int h11 = hash[h1 + iy1]; 90 | 91 | return h00 * (1f / hashMask); 92 | } 93 | public static float Value3D(Vector3 point, float frequency) 94 | { 95 | point *= frequency; 96 | int ix0 = Mathf.FloorToInt(point.x); 97 | int iy0 = Mathf.FloorToInt(point.y); 98 | int iz0 = Mathf.FloorToInt(point.z); 99 | float tx = point.x - ix0; 100 | float ty = point.y - iy0; 101 | float tz = point.z - iz0; 102 | ix0 &= hashMask; 103 | iy0 &= hashMask; 104 | iz0 &= hashMask; 105 | int ix1 = ix0 + 1; 106 | int iy1 = iy0 + 1; 107 | int iz1 = iz0 + 1; 108 | 109 | int h0 = hash[ix0]; 110 | int h1 = hash[ix1]; 111 | int h00 = hash[h0 + iy0]; 112 | int h10 = hash[h1 + iy0]; 113 | int h01 = hash[h0 + iy1]; 114 | int h11 = hash[h1 + iy1]; 115 | int h000 = hash[h00 + iz0]; 116 | int h100 = hash[h10 + iz0]; 117 | int h010 = hash[h01 + iz0]; 118 | int h110 = hash[h11 + iz0]; 119 | int h001 = hash[h00 + iz1]; 120 | int h101 = hash[h10 + iz1]; 121 | int h011 = hash[h01 + iz1]; 122 | int h111 = hash[h11 + iz1]; 123 | 124 | tx = Smooth(tx); 125 | ty = Smooth(ty); 126 | tz = Smooth(tz); 127 | return Mathf.Lerp( 128 | Mathf.Lerp(Mathf.Lerp(h000, h100, tx), Mathf.Lerp(h010, h110, tx), ty), 129 | Mathf.Lerp(Mathf.Lerp(h001, h101, tx), Mathf.Lerp(h011, h111, tx), ty), 130 | tz) * (1f / hashMask); 131 | } 132 | /* public static NoiseMethod[] valueMethods = { 133 | Value1D, 134 | Value2D, 135 | Value3D 136 | };*/ 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | private static float[] gradients1D = { 150 | 1f, -1f 151 | }; 152 | 153 | private const int gradientsMask1D = 1; 154 | 155 | public static float Perlin1D(Vector3 point, float frequency) 156 | { 157 | point *= frequency; 158 | int i0 = Mathf.FloorToInt(point.x); 159 | float t0 = point.x - i0; 160 | float t1 = t0 - 1f; 161 | i0 &= hashMask; 162 | int i1 = i0 + 1; 163 | 164 | float g0 = gradients1D[hash[i0] & gradientsMask1D]; 165 | float g1 = gradients1D[hash[i1] & gradientsMask1D]; 166 | 167 | float t = Smooth(t0); 168 | return Mathf.Lerp(t0, t1, t); 169 | } 170 | 171 | /* private static Vector2[] gradients2D = { 172 | new Vector2( 1f, 0f), 173 | new Vector2(-1f, 0f), 174 | new Vector2( 0f, 1f), 175 | new Vector2( 0f,-1f), 176 | }; 177 | private static Vector2[] gradients2D = { 178 | new Vector2( 1f, 1f), 179 | new Vector2(-1f, 1f), 180 | new Vector2( 1f,-1f), 181 | new Vector2(-1f,-1f) 182 | }; 183 | private const int gradientsMask2D = 3;*/ 184 | private static Vector2[] gradients2D = { 185 | new Vector2( 1f, 0f), 186 | new Vector2(-1f, 0f), 187 | new Vector2( 0f, 1f), 188 | new Vector2( 0f,-1f), 189 | new Vector2( 1f, 1f).normalized, 190 | new Vector2(-1f, 1f).normalized, 191 | new Vector2( 1f,-1f).normalized, 192 | new Vector2(-1f,-1f).normalized 193 | }; 194 | 195 | private const int gradientsMask2D = 7; 196 | 197 | 198 | 199 | public static float Perlin2D(Vector3 point, float frequency) 200 | { 201 | point *= frequency; 202 | int ix0 = Mathf.FloorToInt(point.x); 203 | int iy0 = Mathf.FloorToInt(point.y); 204 | float tx0 = point.x - ix0; 205 | float ty0 = point.y - iy0; 206 | float tx1 = tx0 - 1f; 207 | float ty1 = ty0 - 1f; 208 | ix0 &= hashMask; 209 | iy0 &= hashMask; 210 | int ix1 = ix0 + 1; 211 | int iy1 = iy0 + 1; 212 | 213 | int h0 = hash[ix0]; 214 | int h1 = hash[ix1]; 215 | Vector2 g00 = gradients2D[hash[h0 + iy0] & gradientsMask2D]; 216 | Vector2 g10 = gradients2D[hash[h1 + iy0] & gradientsMask2D]; 217 | Vector2 g01 = gradients2D[hash[h0 + iy1] & gradientsMask2D]; 218 | Vector2 g11 = gradients2D[hash[h1 + iy1] & gradientsMask2D]; 219 | 220 | float v00 = Dot(g00, tx0, ty0); 221 | float v10 = Dot(g10, tx1, ty0); 222 | float v01 = Dot(g01, tx0, ty1); 223 | float v11 = Dot(g11, tx1, ty1); 224 | 225 | float tx = Smooth(tx0); 226 | float ty = Smooth(ty0); 227 | // float tx = tx0;// Smooth(tx0); 228 | // float ty = ty0;//Smooth(ty0); 229 | return Mathf.Lerp( 230 | Mathf.Lerp(v00, v10, tx), 231 | Mathf.Lerp(v01, v11, tx), 232 | ty) * 2f; 233 | } 234 | 235 | private static Vector3[] gradients3D = { 236 | new Vector3( 1f, 1f, 0f), 237 | new Vector3(-1f, 1f, 0f), 238 | new Vector3( 1f,-1f, 0f), 239 | new Vector3(-1f,-1f, 0f), 240 | new Vector3( 1f, 0f, 1f), 241 | new Vector3(-1f, 0f, 1f), 242 | new Vector3( 1f, 0f,-1f), 243 | new Vector3(-1f, 0f,-1f), 244 | new Vector3( 0f, 1f, 1f), 245 | new Vector3( 0f,-1f, 1f), 246 | new Vector3( 0f, 1f,-1f), 247 | new Vector3( 0f,-1f,-1f), 248 | 249 | new Vector3( 1f, 1f, 0f), 250 | new Vector3(-1f, 1f, 0f), 251 | new Vector3( 0f,-1f, 1f), 252 | new Vector3( 0f,-1f,-1f) 253 | }; 254 | 255 | private const int gradientsMask3D = 15; 256 | public static float Perlin3D(Vector3 point, float frequency) 257 | { 258 | point *= frequency; 259 | int ix0 = Mathf.FloorToInt(point.x); 260 | int iy0 = Mathf.FloorToInt(point.y); 261 | int iz0 = Mathf.FloorToInt(point.z); 262 | float tx0 = point.x - ix0; 263 | float ty0 = point.y - iy0; 264 | float tz0 = point.z - iz0; 265 | float tx1 = tx0 - 1f; 266 | float ty1 = ty0 - 1f; 267 | float tz1 = tz0 - 1f; 268 | ix0 &= hashMask; 269 | iy0 &= hashMask; 270 | iz0 &= hashMask; 271 | int ix1 = ix0 + 1; 272 | int iy1 = iy0 + 1; 273 | int iz1 = iz0 + 1; 274 | 275 | int h0 = hash[ix0]; 276 | int h1 = hash[ix1]; 277 | int h00 = hash[h0 + iy0]; 278 | int h10 = hash[h1 + iy0]; 279 | int h01 = hash[h0 + iy1]; 280 | int h11 = hash[h1 + iy1]; 281 | Vector3 g000 = gradients3D[hash[h00 + iz0] & gradientsMask3D]; 282 | Vector3 g100 = gradients3D[hash[h10 + iz0] & gradientsMask3D]; 283 | Vector3 g010 = gradients3D[hash[h01 + iz0] & gradientsMask3D]; 284 | Vector3 g110 = gradients3D[hash[h11 + iz0] & gradientsMask3D]; 285 | Vector3 g001 = gradients3D[hash[h00 + iz1] & gradientsMask3D]; 286 | Vector3 g101 = gradients3D[hash[h10 + iz1] & gradientsMask3D]; 287 | Vector3 g011 = gradients3D[hash[h01 + iz1] & gradientsMask3D]; 288 | Vector3 g111 = gradients3D[hash[h11 + iz1] & gradientsMask3D]; 289 | 290 | float v000 = Dot(g000, tx0, ty0, tz0); 291 | float v100 = Dot(g100, tx1, ty0, tz0); 292 | float v010 = Dot(g010, tx0, ty1, tz0); 293 | float v110 = Dot(g110, tx1, ty1, tz0); 294 | float v001 = Dot(g001, tx0, ty0, tz1); 295 | float v101 = Dot(g101, tx1, ty0, tz1); 296 | float v011 = Dot(g011, tx0, ty1, tz1); 297 | float v111 = Dot(g111, tx1, ty1, tz1); 298 | 299 | float tx = Smooth(tx0); 300 | float ty = Smooth(ty0); 301 | float tz = Smooth(tz0); 302 | return Mathf.Lerp( 303 | Mathf.Lerp(Mathf.Lerp(v000, v100, tx), Mathf.Lerp(v010, v110, tx), ty), 304 | Mathf.Lerp(Mathf.Lerp(v001, v101, tx), Mathf.Lerp(v011, v111, tx), ty), 305 | tz); 306 | } 307 | 308 | public static float Sum(//0-value3d,,,1-perlin2d 309 | int method, Vector3 point, float frequency, int octaves, float lacunarity, float persistence 310 | ) 311 | { 312 | float sum = 0; 313 | switch (method) 314 | { 315 | case 0: 316 | sum = Value3D(point, frequency); 317 | break; 318 | case 1: 319 | sum = Perlin2D(point, frequency); 320 | break; 321 | } 322 | // float sum = method(point, frequency); 323 | float amplitude = 1f; 324 | float range = 1f; 325 | for (int o = 1; o < octaves; o++) 326 | { 327 | frequency *= lacunarity; 328 | amplitude *= persistence; 329 | range += amplitude; 330 | switch (method) 331 | { 332 | case 0: 333 | sum += Value3D(point, frequency) * amplitude; 334 | 335 | break; 336 | case 1: 337 | sum += Perlin2D(point, frequency) * amplitude; 338 | 339 | break; 340 | } 341 | 342 | } 343 | return sum / range; 344 | } 345 | 346 | // Update is called once per frame 347 | void Update() 348 | { 349 | 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/terrain.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about terrain rendering 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | *my email: wolf_crixus@sina.cn 6 | */ 7 | Shader "Custom/terrain" { 8 | Properties{ 9 | _MainTex("Base (RGB)", 2D) = "white" {} 10 | _NormalTex("Normal (RGB)", 2D) = "white" {} 11 | _LowTex("Low Tex", 2D) = "white" {} 12 | _LowNormalTex("Low Normal Tex", 2D) = "white" {} 13 | 14 | _OtherLowTex("Other Low Tex", 2D) = "white" {} 15 | _OtherLowNormalTex("Other Low Normal Tex", 2D) = "white" {} 16 | 17 | _UpTex("Up Tex", 2D) = "white" {} 18 | _UpNormalTex("Up Normal Tex", 2D) = "white" {} 19 | 20 | _OtherUpTex("Other Up Tex", 2D) = "white" {} 21 | _OtherUpNormalTex("Other Up Normal Tex", 2D) = "white" {} 22 | 23 | _NoiseTex("Noise Tex", 2D) = "white" {} 24 | 25 | _UpDownWeight("Up Down Weight", Range(-1, 1)) = 0.3 26 | _NoiseOtherWeight("Noise Other Weight", Range(-1, 1)) = 0.3 27 | // _DamagePos("DamagePos", Vector) = (1, 1, 1, 1) 28 | 29 | _IsSnow("is Snow ", Range(0, 1)) = 1//0-no,1-yes 30 | _SnowNormalTex("Snow Normal Tex", 2D) = "white" {} 31 | _SnowDir("Snow Dir", Vector) = (0, 1, 0, 0) 32 | _SnowColor("Snow Color", Color) = (0.8, 0.9, 1, 1) 33 | _SnowInten("Snow Intensity", Range(-1, 1)) = 0.3 34 | 35 | } 36 | SubShader{ 37 | pass{//平行光的的pass渲染 38 | Tags{ "LightMode" = "ForwardBase" } 39 | Cull Back 40 | CGPROGRAM 41 | #pragma vertex vert 42 | #pragma fragment frag 43 | #include "UnityCG.cginc" 44 | #pragma target 5.0 45 | 46 | 47 | sampler2D _NoiseTex; 48 | sampler2D _LowTex; 49 | sampler2D _LowNormalTex; 50 | sampler2D _UpTex; 51 | sampler2D _UpNormalTex; 52 | 53 | sampler2D _OtherLowTex; 54 | sampler2D _OtherLowNormalTex; 55 | sampler2D _OtherUpTex; 56 | sampler2D _OtherUpNormalTex; 57 | float _UpDownWeight; 58 | float _NoiseOtherWeight; 59 | 60 | 61 | sampler2D _SnowNormalTex; 62 | float3 _SnowDir; 63 | float4 _SnowColor; 64 | float _SnowInten; 65 | int _IsSnow; 66 | 67 | 68 | uniform sampler2D _MainTex; 69 | uniform sampler2D _NormalTex; 70 | 71 | float4 _NoiseTex_ST; 72 | float4 _LowTex_ST; 73 | float4 _UpTex_ST; 74 | float4 _MainTex_ST; 75 | float4 _OtherLowTex_ST; 76 | float4 _OtherUpTex_ST; 77 | float4 _SnowNormalTex_ST; 78 | 79 | struct v2f { 80 | float4 pos : SV_POSITION; 81 | float2 uv_MainTex : TEXCOORD0; 82 | float3 lightDir : TEXCOORD1; 83 | float3 viewDir : TEXCOORD2; 84 | float3 normal : TEXCOORD3; 85 | float2 uv_LowTex : TEXCOORD4; 86 | float2 uv_UpTex : TEXCOORD5; 87 | float2 uv_NoiseTex : TEXCOORD6; 88 | float2 uv_OtherLowTex : TEXCOORD7; 89 | float2 uv_OtherUpTex : TEXCOORD8; 90 | float2 uv_SnowNormalTex : TEXCOORD9; 91 | float4 pos_w : TEXCOORD10; 92 | }; 93 | 94 | v2f vert(appdata_full v) { 95 | v2f o; 96 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex);//切换到世界坐标 97 | o.normal = v.normal; 98 | o.lightDir = ObjSpaceLightDir(v.vertex); 99 | o.viewDir = ObjSpaceViewDir(v.vertex); 100 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 101 | o.uv_LowTex = TRANSFORM_TEX(v.texcoord, _LowTex); 102 | o.uv_UpTex = TRANSFORM_TEX(v.texcoord, _UpTex); 103 | o.uv_OtherLowTex = TRANSFORM_TEX(v.texcoord, _OtherLowTex); 104 | o.uv_OtherUpTex = TRANSFORM_TEX(v.texcoord, _OtherUpTex); 105 | o.uv_NoiseTex = TRANSFORM_TEX(v.texcoord, _NoiseTex); 106 | o.uv_SnowNormalTex = TRANSFORM_TEX(v.texcoord, _SnowNormalTex); 107 | o.pos_w = v.vertex; 108 | 109 | 110 | return o; 111 | } 112 | #define PIE 3.1415926535 113 | 114 | 115 | float4 frag(v2f i) :COLOR 116 | { 117 | float3 lightDir = normalize(i.lightDir); 118 | float3 viewDir = normalize(i.viewDir); 119 | float3 N = normalize(i.normal); 120 | // N = normalize((N + UnpackNormal(tex2D(_DamageNormalTex, i.uv_DamageNormalTex))) / 2); 121 | float4 up = tex2D(_UpTex, i.uv_UpTex); 122 | float4 low = tex2D(_LowTex, i.uv_LowTex); 123 | 124 | float3 n_up = UnpackNormal(tex2D(_UpNormalTex, i.uv_UpTex)); 125 | float3 n_low = UnpackNormal(tex2D(_LowNormalTex, i.uv_LowTex)); 126 | 127 | 128 | float4 up_o = tex2D(_OtherUpTex, i.uv_OtherUpTex); 129 | float4 low_o = tex2D(_OtherLowTex, i.uv_OtherLowTex); 130 | 131 | float3 n_up_o = UnpackNormal(tex2D(_OtherUpNormalTex, i.uv_OtherUpTex)); 132 | float3 n_low_o = UnpackNormal(tex2D(_OtherLowNormalTex, i.uv_OtherLowTex)); 133 | 134 | float noise = tex2D(_NoiseTex, i.uv_NoiseTex).x; 135 | 136 | up = lerp(up, up_o, noise + _NoiseOtherWeight); 137 | low = lerp(low, low_o, noise + _NoiseOtherWeight); 138 | 139 | n_up = lerp(n_up, n_up_o, noise + _NoiseOtherWeight); 140 | n_low = lerp(n_low, n_low_o, noise + _NoiseOtherWeight); 141 | 142 | 143 | float4 c = 0; 144 | 145 | c = lerp(low, up*1.3, i.pos_w.y*0.1 + _UpDownWeight); 146 | 147 | float3 n_fin = lerp(n_low, n_up, i.pos_w.y*0.1 + _UpDownWeight); 148 | n_fin = normalize(n_fin); 149 | 150 | N = normalize((N + n_fin) / 2); 151 | 152 | 153 | if (_IsSnow > 0) 154 | { 155 | _SnowDir = normalize(_SnowDir); 156 | 157 | if (dot(N, _SnowDir) > _SnowInten) { 158 | c = _SnowColor; 159 | N = normalize((normalize(i.normal) + normalize(UnpackNormal(tex2D(_SnowNormalTex, i.uv_SnowNormalTex)))) / 2); 160 | } 161 | } 162 | 163 | float diffuse = dot(lightDir, N); 164 | return c*diffuse*1.2; 165 | } 166 | ENDCG 167 | } 168 | } 169 | } 170 | 171 | -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/terrain_g.cs: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this is about random generation terrain based on fractal noise 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | *my email: wolf_crixus@sina.cn 6 | */ 7 | using UnityEngine; 8 | using System.Collections; 9 | [ExecuteInEditMode] 10 | public class terrain_g : MonoBehaviour 11 | { 12 | 13 | //材质和高度图 14 | public Material diffuseMap; 15 | public Texture2D heightMap; 16 | //顶点、uv、索引信息 17 | private Vector3[] vertives; 18 | private Vector2[] uvs; 19 | private int[] triangles; 20 | 21 | //生成信息 22 | private Vector2 size;//长宽 23 | private float minHeight = -10; 24 | private float maxHeight = 10; 25 | private Vector2 segment; 26 | private float unitH; 27 | 28 | //面片mesh 29 | private GameObject terrain; 30 | 31 | // Use this for initialization 32 | void Start() 33 | { 34 | //默认生成一个地形,如果不喜欢,注销掉然后用参数生成 35 | SetTerrain(); 36 | } 37 | 38 | 39 | /// 40 | /// 生成默认地形 41 | /// 42 | public void SetTerrain() 43 | { 44 | SetTerrain(100, 100, 200, 200, -10, 10); 45 | } 46 | 47 | 48 | 49 | public void SetTerrain(float width, float height, uint segmentX, uint segmentY, int min, int max) 50 | { 51 | Init(width, height, segmentX, segmentY, min, max); 52 | GetVertives(); 53 | DrawMesh(); 54 | } 55 | 56 | 57 | 58 | private void Init(float width, float height, uint segmentX, uint segmentY, int min, int max) 59 | { 60 | size = new Vector2(width, height); 61 | maxHeight = max; 62 | minHeight = min; 63 | unitH = maxHeight - minHeight; 64 | segment = new Vector2(segmentX, segmentY); 65 | if (terrain != null) 66 | { 67 | Destroy(terrain); 68 | } 69 | terrain = new GameObject(); 70 | terrain.name = "plane"; 71 | } 72 | 73 | /// 74 | /// 绘制网格 75 | /// 76 | private void DrawMesh() 77 | { 78 | Mesh mesh = terrain.AddComponent().mesh; 79 | terrain.AddComponent(); 80 | if (diffuseMap == null) 81 | { 82 | Debug.LogWarning("No material,Create diffuse!!"); 83 | diffuseMap = new Material(Shader.Find("Diffuse")); 84 | } 85 | if (heightMap == null) 86 | { 87 | Debug.LogWarning("No heightMap!!!"); 88 | } 89 | terrain.renderer.material = diffuseMap; 90 | //给mesh 赋值 91 | mesh.Clear(); 92 | mesh.vertices = vertives;//,pos); 93 | mesh.uv = uvs; 94 | mesh.triangles = triangles; 95 | //重置法线 96 | mesh.RecalculateNormals(); 97 | //重置范围 98 | mesh.RecalculateBounds(); 99 | } 100 | 101 | 102 | 103 | /* private Vector3[] GetVertives() 104 | { 105 | int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); 106 | float w = size.x / segment.x; 107 | float h = size.y / segment.y; 108 | 109 | int index = 0; 110 | GetUV(); 111 | GetTriangles(); 112 | vertives = new Vector3[sum]; 113 | for (int i = 0; i < segment.y + 1; i++) 114 | { 115 | for (int j = 0; j < segment.x + 1; j++) 116 | { 117 | float tempHeight = 0; 118 | if (heightMap != null) 119 | { 120 | tempHeight = GetHeight(heightMap, uvs[index]); 121 | } 122 | vertives[index] = new Vector3(j * w, tempHeight, i * h); 123 | index++; 124 | } 125 | } 126 | return vertives; 127 | } 128 | */ 129 | 130 | 131 | /* private Vector3[] GetVertives()//texture 132 | { 133 | int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); 134 | float w = size.x / segment.x; 135 | float h = size.y / segment.y; 136 | 137 | int index = 0; 138 | GetUV(); 139 | GetTriangles(); 140 | vertives = new Vector3[sum]; 141 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 142 | Vector3 point10 = new Vector3(0.5f, -0.5f); 143 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 144 | Vector3 point11 = new Vector3(0.5f, 0.5f); 145 | 146 | 147 | 148 | Random.seed = 42; 149 | 150 | 151 | for (int i = 0; i < segment.y + 1; i++) 152 | { 153 | for (int j = 0; j < segment.x + 1; j++) 154 | { 155 | float tempHeight = 0; 156 | // if ((i+j)%5 == 0) 157 | { 158 | 159 | tempHeight =Mathf.Abs (heightMap.GetPixel(i , j ).r -0.5f)*2* 10;// 160 | 161 | } 162 | vertives[index] = new Vector3(j * w, tempHeight, i * h); 163 | index++; 164 | } 165 | } 166 | return vertives; 167 | } 168 | */ 169 | /* private Vector3[] GetVertives()//perlin 170 | { 171 | 172 | 173 | 174 | int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); 175 | float w = size.x / segment.x; 176 | float h = size.y / segment.y; 177 | 178 | int index = 0; 179 | GetUV(); 180 | GetTriangles(); 181 | vertives = new Vector3[sum]; 182 | 183 | 184 | int resolution = 256; 185 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 186 | Vector3 point10 = new Vector3(0.5f, -0.5f); 187 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 188 | Vector3 point11 = new Vector3(0.5f, 0.5f); 189 | 190 | 191 | float stepSize = 1f / resolution; 192 | 193 | 194 | 195 | Random.seed = 42; 196 | 197 | 198 | for (int i = 0; i < segment.y + 1; i++) 199 | { 200 | Vector3 point0 = Vector3.Lerp(point00, point01, (i + 0.5f) * stepSize); 201 | Vector3 point1 = Vector3.Lerp(point10, point11, (i + 0.5f) * stepSize); 202 | for (int j = 0; j < segment.x + 1; j++) 203 | { 204 | float tempHeight = 0; 205 | // if ((i+j)%5 == 0) 206 | { 207 | Vector3 point = Vector3.Lerp(point0, point1, (j + 0.5f) * stepSize); 208 | 209 | tempHeight = NoiseMethod.Perlin2D(point, 22) * 10;// 210 | 211 | } 212 | vertives[index] = new Vector3(j * w, tempHeight, i * h); 213 | index++; 214 | } 215 | } 216 | return vertives; 217 | }*/ 218 | private Vector3[] GetVertives()//Fractal Noise 219 | { 220 | 221 | float frequency = 5; 222 | 223 | //[Range(1, 8)] 224 | int octaves = 6;//1普通,8烟雾状 225 | 226 | // [Range(1f, 4f)] 227 | float lacunarity = 2f; 228 | 229 | // [Range(0f, 1f)] 230 | float persistence = 0.5f; 231 | 232 | 233 | 234 | int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); 235 | float w = size.x / segment.x; 236 | float h = size.y / segment.y; 237 | 238 | int index = 0; 239 | GetUV(); 240 | GetTriangles(); 241 | vertives = new Vector3[sum]; 242 | 243 | 244 | int resolution = 256; 245 | Vector3 point00 = new Vector3(-0.5f, -0.5f); 246 | Vector3 point10 = new Vector3(0.5f, -0.5f); 247 | Vector3 point01 = new Vector3(-0.5f, 0.5f); 248 | Vector3 point11 = new Vector3(0.5f, 0.5f); 249 | 250 | 251 | float stepSize = 1f / resolution; 252 | 253 | 254 | 255 | Random.seed = 42; 256 | 257 | 258 | for (int i = 0; i < segment.y + 1; i++) 259 | { 260 | Vector3 point0 = Vector3.Lerp(point00, point01, (i + 0.5f) * stepSize); 261 | Vector3 point1 = Vector3.Lerp(point10, point11, (i + 0.5f) * stepSize); 262 | for (int j = 0; j < segment.x + 1; j++) 263 | { 264 | float tempHeight = 0; 265 | // if ((i+j)%5 == 0) 266 | { 267 | Vector3 point = Vector3.Lerp(point0, point1, (j + 0.5f) * stepSize); 268 | float sample = NoiseMethod.Sum(1, point, frequency, octaves, lacunarity, persistence); 269 | tempHeight = sample* 20;// 270 | } 271 | vertives[index] = new Vector3(j * w, tempHeight, i * h); 272 | index++; 273 | } 274 | } 275 | return vertives; 276 | } 277 | 278 | 279 | private Vector2[] GetUV() 280 | { 281 | int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); 282 | uvs = new Vector2[sum]; 283 | float u = 1.0F / segment.x; 284 | float v = 1.0F / segment.y; 285 | uint index = 0; 286 | for (int i = 0; i < segment.y + 1; i++) 287 | { 288 | for (int j = 0; j < segment.x + 1; j++) 289 | { 290 | uvs[index] = new Vector2(j * u, i * v); 291 | index++; 292 | } 293 | } 294 | return uvs; 295 | } 296 | 297 | 298 | 299 | private int[] GetTriangles() 300 | { 301 | int sum = Mathf.FloorToInt(segment.x * segment.y * 6); 302 | triangles = new int[sum]; 303 | uint index = 0; 304 | for (int i = 0; i < segment.y; i++) 305 | { 306 | for (int j = 0; j < segment.x; j++) 307 | { 308 | int role = Mathf.FloorToInt(segment.x) + 1; 309 | int self = j + (i * role); 310 | int next = j + ((i + 1) * role); 311 | triangles[index] = self; 312 | triangles[index + 1] = next + 1; 313 | triangles[index + 2] = self + 1; 314 | triangles[index + 3] = self; 315 | triangles[index + 4] = next; 316 | triangles[index + 5] = next + 1; 317 | index += 6; 318 | } 319 | } 320 | return triangles; 321 | } 322 | 323 | private float GetHeight(Texture2D texture, Vector2 uv) 324 | { 325 | if (texture != null) 326 | { 327 | //提取灰度。如果强制读取某个通道,可以忽略 328 | Color c = GetColor(texture, uv); 329 | float gray = c.grayscale;//或者可以自己指定灰度提取算法,比如:gray = 0.3F * c.r + 0.59F * c.g + 0.11F * c.b; 330 | float h = unitH * gray; 331 | return h; 332 | } 333 | else 334 | { 335 | return 0; 336 | } 337 | } 338 | 339 | 340 | private Color GetColor(Texture2D texture, Vector2 uv) 341 | { 342 | 343 | Color color = texture.GetPixel(Mathf.FloorToInt(texture.width * uv.x), Mathf.FloorToInt(texture.height * uv.y)); 344 | return color; 345 | } 346 | 347 | 348 | public void SetPos(Vector3 pos) 349 | { 350 | if (terrain) 351 | { 352 | terrain.transform.position = pos; 353 | } 354 | else 355 | { 356 | SetTerrain(); 357 | terrain.transform.position = pos; 358 | } 359 | } 360 | } 361 | 362 | -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/1.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/2.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/3.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/7.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/8.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/9.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/Fractal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/Fractal.png -------------------------------------------------------------------------------- /random generation terrain based on fractal noise/test/Fractal2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/random generation terrain based on fractal noise/test/Fractal2.png -------------------------------------------------------------------------------- /snow and sand/send big 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/snow and sand/send big 3.png -------------------------------------------------------------------------------- /snow and sand/send2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/snow and sand/send2.png -------------------------------------------------------------------------------- /snow and sand/snow big3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/snow and sand/snow big3.png -------------------------------------------------------------------------------- /snow and sand/snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/snow and sand/snow.png -------------------------------------------------------------------------------- /snow and sand/snow.shader: -------------------------------------------------------------------------------- 1 | /* 2 | *Hi, I'm Lin Dong, 3 | *this shader is about snow and sand rendering 4 | *if you want to get more detail please enter my blog http://blog.csdn.net/wolf96 5 | *my email: wolf_crixus@sina.cn 6 | */ 7 | Shader "Custom/snow" { 8 | Properties{ 9 | _MainTex("Base (RGB)", 2D) = "white" {} 10 | _NormalTex("Normal (RGB)", 2D) = "white" {} 11 | 12 | 13 | _SnowNormalTex("Snow Normal Tex", 2D) = "white" {} 14 | _SnowColor("Snow Color", Color) = (0.8, 0.9, 1, 1) 15 | _SnowInten("Snow Intensity", Range(-1, 1)) = 0.3 16 | 17 | _SpecColor("Specular Color", Color) = (0.9, 0.95, 1, 1) 18 | 19 | 20 | _NoiseTex("Noise Tex", 2D) = "white" {} 21 | _NoiseWeight("Noise Weight", Range(0, 1)) = 0.3 22 | _SpecwInten("Specular Intensity", Range(0, 2)) = 0.3 23 | 24 | _Roughness("Roughness", Range(0, 1)) = 0.3 25 | } 26 | SubShader{ 27 | pass{//平行光的的pass渲染 28 | Tags{ "LightMode" = "ForwardBase" } 29 | Cull Back 30 | CGPROGRAM 31 | #pragma vertex vert 32 | #pragma fragment frag 33 | #include "UnityCG.cginc" 34 | #pragma target 5.0 35 | 36 | 37 | sampler2D _SnowNormalTex; 38 | float4 _SnowColor; 39 | float _SnowInten; 40 | float _NoiseWeight; 41 | float _SpecwInten; 42 | float _Roughness; 43 | 44 | float4 _SpecColor; 45 | 46 | uniform sampler2D _MainTex; 47 | uniform sampler2D _NormalTex; 48 | uniform sampler2D _NoiseTex; 49 | 50 | 51 | float4 _MainTex_ST; 52 | float4 _NoiseTex_ST; 53 | float4 _SnowNormalTex_ST; 54 | 55 | struct v2f { 56 | float4 pos : SV_POSITION; 57 | float2 uv_MainTex : TEXCOORD0; 58 | float3 lightDir : TEXCOORD1; 59 | float3 viewDir : TEXCOORD2; 60 | float3 normal : TEXCOORD3; 61 | float2 uv_NoiseTex : TEXCOORD4; 62 | float2 uv_SnowNormalTex : TEXCOORD5; 63 | float4 pos_w : TEXCOORD6; 64 | }; 65 | 66 | v2f vert(appdata_full v) { 67 | v2f o; 68 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 69 | o.normal = v.normal; 70 | o.lightDir = ObjSpaceLightDir(v.vertex); 71 | o.viewDir = ObjSpaceViewDir(v.vertex); 72 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 73 | o.uv_NoiseTex = TRANSFORM_TEX(v.texcoord, _NoiseTex); 74 | o.uv_SnowNormalTex = TRANSFORM_TEX(v.texcoord, _SnowNormalTex); 75 | o.pos_w = v.vertex; 76 | 77 | 78 | return o; 79 | } 80 | 81 | half OrenNayarDiffuse(half3 light, half3 view, half3 norm, half roughness) 82 | { 83 | half VdotN = dot(view, norm); 84 | half LdotN = dot(light, norm); 85 | half cos_theta_i = LdotN; 86 | half theta_r = acos(VdotN); 87 | half theta_i = acos(cos_theta_i); 88 | half cos_phi_diff = dot(normalize(view - norm * VdotN), 89 | normalize(light - norm * LdotN)); 90 | half alpha = max(theta_i, theta_r); 91 | half beta = min(theta_i, theta_r); 92 | half sigma2 = roughness * roughness; 93 | half A = 1.0 - 0.5 * sigma2 / (sigma2 + 0.33); 94 | half B = 0.45 * sigma2 / (sigma2 + 0.09); 95 | return saturate(cos_theta_i) *(A + (B * saturate(cos_phi_diff) * sin(alpha) * tan(beta))); 96 | } 97 | float4 frag(v2f i) :COLOR 98 | { 99 | float3 lightDir = normalize(i.lightDir); 100 | float3 viewDir = normalize(i.viewDir); 101 | float3 N = normalize(i.normal); 102 | float3 H = normalize(lightDir + viewDir); 103 | 104 | 105 | float4 c = _SnowColor; 106 | // N = N + normalize(UnpackNormal(tex2D(_SnowNormalTex, i.uv_SnowNormalTex))) ; 107 | N = (N + UnpackNormal(tex2D(_SnowNormalTex, i.uv_SnowNormalTex)))/2; 108 | N = normalize(N); 109 | // float diffuse = saturate(dot(lightDir, N))+0.05;//1 110 | // float diffuse = OrenNayarDiffuse(lightDir, viewDir, N, _Roughness);//2 111 | 112 | 113 | float3 N2 = N; 114 | N2.y *= 0.3; 115 | float diffuse = saturate(4 * dot(N2, lightDir));;//3 116 | 117 | diffuse = saturate(diffuse) + 0.05; 118 | 119 | float4 spec = _SpecColor *saturate((dot(N, viewDir))); 120 | float noise = tex2D(_NoiseTex, i.uv_NoiseTex); 121 | 122 | 123 | if (noise > _NoiseWeight) 124 | noise *= 2; 125 | 126 | return c*diffuse + spec*noise*_SpecwInten; 127 | } 128 | ENDCG 129 | } 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /snow and sand/snow2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolf96/shader_for_unity/d8d11e5f6b4416a400f42313bd727435f2101107/snow and sand/snow2.png --------------------------------------------------------------------------------