Shader "Shader Forge/niuqu" { Properties { _BumpMap ("Normal Map", 2D) = "bump" {} _MainTex ("Base Color", 2D) = "black" {} _noize ("noize", 2D) = "white" {} _noizeintensity ("noize intensity", Range(0, 1)) = 1 _refractionIntensity ("refraction Intensity", Range(0, 1)) = 0.8164595 _color ("color", Color) = (1,1,1,1) [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" } GrabPass{ } Pass { Name "FORWARD" Tags { "LightMode"="ForwardBase" } Blend SrcAlpha OneMinusSrcAlpha ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDBASE #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #include "UnityCG.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma multi_compile_fwdbase #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 #pragma target 3.0 uniform sampler2D _GrabTexture; uniform float4 _TimeEditor; uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST; uniform sampler2D _noize; uniform float4 _noize_ST; uniform float _noizeintensity; uniform float _refractionIntensity; uniform float4 _color; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; float3 normalDir : TEXCOORD4; float3 tangentDir : TEXCOORD5; float3 bitangentDir : TEXCOORD6; float4 screenPos : TEXCOORD7; UNITY_FOG_COORDS(8) #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH) float4 ambientOrLightmapUV : TEXCOORD9; #endif }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; #ifdef LIGHTMAP_ON o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; o.ambientOrLightmapUV.zw = 0; #elif UNITY_SHOULD_SAMPLE_SH #endif #ifdef DYNAMICLIGHTMAP_ON o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; #endif o.normalDir = UnityObjectToWorldNormal(v.normal); o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); o.posWorld = mul(unity_ObjectToWorld, v.vertex); float3 lightColor = _LightColor0.rgb; o.pos = UnityObjectToClipPos(v.vertex ); UNITY_TRANSFER_FOG(o,o.pos); o.screenPos = o.pos; return o; } float4 frag(VertexOutput i) : COLOR { #if UNITY_UV_STARTS_AT_TOP float grabSign = -_ProjectionParams.x; #else float grabSign = _ProjectionParams.x; #endif i.normalDir = normalize(i.normalDir); i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 ); i.screenPos.y *= _ProjectionParams.x; float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float4 node_2706 = _Time + _TimeEditor; float2 node_7849 = (i.uv0+node_2706.g*float2(0,0.1)); float4 _noize_var = tex2D(_noize,TRANSFORM_TEX(node_7849, _noize)); float2 node_4608 = (i.uv0+(_noizeintensity*_noize_var.r)); float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(node_4608, _BumpMap))); float3 normalLocal = lerp(float3(0,0,0.5),_BumpMap_var.rgb,_refractionIntensity); float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + (_BumpMap_var.rgb.rg*(_refractionIntensity*0.2)); float4 sceneColor = tex2D(_GrabTexture, sceneUVs); float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); float3 lightColor = _LightColor0.rgb; float3 halfDirection = normalize(viewDirection+lightDirection); ////// Lighting: float attenuation = 1; float3 attenColor = attenuation * _LightColor0.xyz; float Pi = 3.141592654; float InvPi = 0.31830988618; ///////// Gloss: float node_3135 = 1.5; float gloss = node_3135; float specPow = exp2( gloss * 10.0+1.0); /////// GI Data: UnityLight light; #ifdef LIGHTMAP_OFF light.color = lightColor; light.dir = lightDirection; light.ndotl = LambertTerm (normalDirection, light.dir); #else light.color = half3(0.f, 0.f, 0.f); light.ndotl = 0.0f; light.dir = half3(0.f, 0.f, 0.f); #endif UnityGIInput d; d.light = light; d.worldPos = i.posWorld.xyz; d.worldViewDir = viewDirection; d.atten = attenuation; #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) d.ambient = 0; d.lightmapUV = i.ambientOrLightmapUV; #else d.ambient = i.ambientOrLightmapUV; #endif #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) || defined(UNITY_ENABLE_REFLECTION_BUFFERS) d.boxMin[0] = unity_SpecCube0_BoxMin; d.boxMin[1] = unity_SpecCube1_BoxMin; #endif #ifdef UNITY_SPECCUBE_BOX_PROJECTION d.boxMax[0] = unity_SpecCube0_BoxMax; d.boxMax[1] = unity_SpecCube1_BoxMax; d.probePosition[0] = unity_SpecCube0_ProbePosition; d.probePosition[1] = unity_SpecCube1_ProbePosition; #endif d.probeHDR[0] = unity_SpecCube0_HDR; d.probeHDR[1] = unity_SpecCube1_HDR; Unity_GlossyEnvironmentData ugls_en_data; ugls_en_data.roughness = 1.0 - gloss; ugls_en_data.reflUVW = viewReflectDirection; UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data ); lightDirection = gi.light.dir; lightColor = gi.light.color; ////// Specular: float NdotL = max(0, dot( normalDirection, lightDirection )); float node_8749 = 0.5; float LdotH = max(0.0,dot(lightDirection, halfDirection)); float3 specularColor = node_3135; float specularMonochrome; float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_4608, _MainTex)); float3 diffuseColor = (_MainTex_var.rgb*_color.rgb); // Need this for specular when using metallic diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome ); specularMonochrome = 1.0-specularMonochrome; float NdotV = max(0.0,dot( normalDirection, viewDirection )); float NdotH = max(0.0,dot( normalDirection, halfDirection )); float VdotH = max(0.0,dot( viewDirection, halfDirection )); float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss ); float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss)); float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4); if (IsGammaSpace()) specularPBL = sqrt(max(1e-4h, specularPBL)); specularPBL = max(0, specularPBL * NdotL); float3 directSpecular = 1*specularPBL*lightColor*FresnelTerm(specularColor, LdotH); half grazingTerm = saturate( gloss + specularMonochrome ); float3 indirectSpecular = (gi.indirect.specular + float3(node_8749,node_8749,node_8749)); indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV); float3 specular = (directSpecular + indirectSpecular); /////// Diffuse: NdotL = max(0.0,dot( normalDirection, lightDirection )); half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss); float nlPow5 = Pow5(1-NdotL); float nvPow5 = Pow5(1-NdotV); float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor; float3 indirectDiffuse = float3(0,0,0); indirectDiffuse += gi.indirect.diffuse; float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor; /// Final Color: float3 finalColor = diffuse + specular; fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,0.3),1); UNITY_APPLY_FOG(i.fogCoord, finalRGBA); return finalRGBA; } ENDCG } Pass { Name "FORWARD_DELTA" Tags { "LightMode"="ForwardAdd" } Blend One One ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDADD #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #include "UnityCG.cginc" #include "AutoLight.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma multi_compile_fwdadd #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 #pragma target 3.0 uniform sampler2D _GrabTexture; uniform float4 _TimeEditor; uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST; uniform sampler2D _noize; uniform float4 _noize_ST; uniform float _noizeintensity; uniform float _refractionIntensity; uniform float4 _color; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; float3 normalDir : TEXCOORD4; float3 tangentDir : TEXCOORD5; float3 bitangentDir : TEXCOORD6; float4 screenPos : TEXCOORD7; LIGHTING_COORDS(8,9) UNITY_FOG_COORDS(10) }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; o.normalDir = UnityObjectToWorldNormal(v.normal); o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); o.posWorld = mul(unity_ObjectToWorld, v.vertex); float3 lightColor = _LightColor0.rgb; o.pos = UnityObjectToClipPos(v.vertex ); UNITY_TRANSFER_FOG(o,o.pos); o.screenPos = o.pos; TRANSFER_VERTEX_TO_FRAGMENT(o) return o; } float4 frag(VertexOutput i) : COLOR { #if UNITY_UV_STARTS_AT_TOP float grabSign = -_ProjectionParams.x; #else float grabSign = _ProjectionParams.x; #endif i.normalDir = normalize(i.normalDir); i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 ); i.screenPos.y *= _ProjectionParams.x; float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float4 node_963 = _Time + _TimeEditor; float2 node_7849 = (i.uv0+node_963.g*float2(0,0.1)); float4 _noize_var = tex2D(_noize,TRANSFORM_TEX(node_7849, _noize)); float2 node_4608 = (i.uv0+(_noizeintensity*_noize_var.r)); float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(node_4608, _BumpMap))); float3 normalLocal = lerp(float3(0,0,0.5),_BumpMap_var.rgb,_refractionIntensity); float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + (_BumpMap_var.rgb.rg*(_refractionIntensity*0.2)); float4 sceneColor = tex2D(_GrabTexture, sceneUVs); float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); float3 lightColor = _LightColor0.rgb; float3 halfDirection = normalize(viewDirection+lightDirection); ////// Lighting: float attenuation = LIGHT_ATTENUATION(i); float3 attenColor = attenuation * _LightColor0.xyz; float Pi = 3.141592654; float InvPi = 0.31830988618; ///////// Gloss: float node_3135 = 1.5; float gloss = node_3135; float specPow = exp2( gloss * 10.0+1.0); ////// Specular: float NdotL = max(0, dot( normalDirection, lightDirection )); float LdotH = max(0.0,dot(lightDirection, halfDirection)); float3 specularColor = node_3135; float specularMonochrome; float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_4608, _MainTex)); float3 diffuseColor = (_MainTex_var.rgb*_color.rgb); // Need this for specular when using metallic diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome ); specularMonochrome = 1.0-specularMonochrome; float NdotV = max(0.0,dot( normalDirection, viewDirection )); float NdotH = max(0.0,dot( normalDirection, halfDirection )); float VdotH = max(0.0,dot( viewDirection, halfDirection )); float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss ); float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss)); float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4); if (IsGammaSpace()) specularPBL = sqrt(max(1e-4h, specularPBL)); specularPBL = max(0, specularPBL * NdotL); float3 directSpecular = attenColor*specularPBL*lightColor*FresnelTerm(specularColor, LdotH); float3 specular = directSpecular; /////// Diffuse: NdotL = max(0.0,dot( normalDirection, lightDirection )); half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss); float nlPow5 = Pow5(1-NdotL); float nvPow5 = Pow5(1-NdotV); float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor; float3 diffuse = directDiffuse * diffuseColor; /// Final Color: float3 finalColor = diffuse + specular; fixed4 finalRGBA = fixed4(finalColor * 0.3,0); UNITY_APPLY_FOG(i.fogCoord, finalRGBA); return finalRGBA; } ENDCG } Pass { Name "Meta" Tags { "LightMode"="Meta" } Cull Off CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_META 1 #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #include "UnityCG.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #include "UnityMetaPass.cginc" #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_shadowcaster #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 #pragma target 3.0 uniform float4 _TimeEditor; uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _noize; uniform float4 _noize_ST; uniform float _noizeintensity; uniform float4 _color; struct VertexInput { float4 vertex : POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; o.posWorld = mul(unity_ObjectToWorld, v.vertex); o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST ); return o; } float4 frag(VertexOutput i) : SV_Target { float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); UnityMetaInput o; UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o ); o.Emission = 0; float4 node_7142 = _Time + _TimeEditor; float2 node_7849 = (i.uv0+node_7142.g*float2(0,0.1)); float4 _noize_var = tex2D(_noize,TRANSFORM_TEX(node_7849, _noize)); float2 node_4608 = (i.uv0+(_noizeintensity*_noize_var.r)); float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_4608, _MainTex)); float3 diffColor = (_MainTex_var.rgb*_color.rgb); float specularMonochrome; float3 specColor; float node_3135 = 1.5; diffColor = DiffuseAndSpecularFromMetallic( diffColor, node_3135, specColor, specularMonochrome ); float roughness = 1.0 - node_3135; o.Albedo = diffColor + specColor * roughness * roughness * 0.5; return UnityMetaFragment( o ); } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector" }