Question by
Nao_kozono · Sep 07, 2018 at 09:52 AM ·
iosiphoneshader programming
Display reflection on iOS
There was no problem with OpenGL, but there was a problem with the expression of water in Metal. Specifically, the location of the reflection is shifted like the image.
The version of Unity is 2017, 4, 3 f
iPhone is iPhoneSE, iOS 11, 4, 1.
I am using Shader Forge.
The code is as follows.
// Shader created with Shader Forge v1.38
// Shader Forge (c) Freya Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,lico:0,lgpr:1,limd:3,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:True,hqlp:False,rprd:True,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:True,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:2865,x:32963,y:32738,varname:node_2865,prsc:2|diff-6343-OUT,spec-2677-OUT,gloss-1813-OUT,normal-1024-OUT,emission-4134-OUT,alpha-6991-OUT,refract-3972-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:32410,y:32458,varname:node_6343,prsc:2|A-7499-RGB,B-7406-A;n:type:ShaderForge.SFN_Slider,id:1813,x:32181,y:32691,ptovrint:False,ptlb:Gloss,ptin:_Gloss,varname:_Metallic_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.8,max:1;n:type:ShaderForge.SFN_ValueProperty,id:2677,x:32338,y:32622,ptovrint:False,ptlb:Metallic,ptin:_Metallic,varname:node_2677,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0;n:type:ShaderForge.SFN_VertexColor,id:7406,x:32153,y:32470,varname:node_7406,prsc:2;n:type:ShaderForge.SFN_Normalize,id:1024,x:32395,y:32833,varname:node_1024,prsc:2|IN-3332-OUT;n:type:ShaderForge.SFN_Lerp,id:3332,x:32199,y:32833,varname:node_3332,prsc:2|A-9913-OUT,B-1639-RGB,T-8512-OUT;n:type:ShaderForge.SFN_Vector3,id:9913,x:31938,y:32710,varname:node_9913,prsc:2,v1:0,v2:0,v3:1;n:type:ShaderForge.SFN_Slider,id:8512,x:31781,y:32814,ptovrint:False,ptlb:Reflection,ptin:_Reflection,varname:node_8512,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_TexCoord,id:8096,x:31597,y:32882,varname:node_8096,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Panner,id:390,x:31759,y:32882,varname:node_390,prsc:2,spu:0.02,spv:0.02|UVIN-8096-UVOUT;n:type:ShaderForge.SFN_Slider,id:6991,x:32219,y:32982,ptovrint:False,ptlb:Opacity,ptin:_Opacity,varname:node_6991,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Tex2d,id:1639,x:31938,y:32906,ptovrint:False,ptlb:Normal_Tex,ptin:_Normal_Tex,varname:node_1639,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:569206d62ff6ac94b937a1afcfa5b3d3,ntxv:3,isnm:True|UVIN-390-UVOUT;n:type:ShaderForge.SFN_ComponentMask,id:8475,x:32199,y:33073,varname:node_8475,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-1639-RGB;n:type:ShaderForge.SFN_Multiply,id:3972,x:32425,y:33183,varname:node_3972,prsc:2|A-8475-OUT,B-2521-OUT;n:type:ShaderForge.SFN_Multiply,id:2521,x:32199,y:33223,varname:node_2521,prsc:2|A-392-OUT,B-6999-OUT;n:type:ShaderForge.SFN_Slider,id:392,x:31708,y:33110,ptovrint:False,ptlb:Distorition,ptin:_Distorition,varname:node_392,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.4358974,max:1;n:type:ShaderForge.SFN_ValueProperty,id:6999,x:31840,y:33225,ptovrint:False,ptlb:Value,ptin:_Value,varname:node_6999,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0.2;n:type:ShaderForge.SFN_Multiply,id:4134,x:32748,y:32871,varname:node_4134,prsc:2|A-6343-OUT,B-9039-OUT;n:type:ShaderForge.SFN_Slider,id:9039,x:32491,y:33058,ptovrint:False,ptlb:Emissive,ptin:_Emissive,varname:node_9039,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.5128206,max:10;n:type:ShaderForge.SFN_Tex2d,id:7499,x:31997,y:32320,ptovrint:False,ptlb:Dif_Tex,ptin:_Dif_Tex,varname:node_7499,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:746e62f46e897ed41850cd7a9ad4ac03,ntxv:0,isnm:False|UVIN-2213-UVOUT;n:type:ShaderForge.SFN_TexCoord,id:3113,x:31525,y:32387,varname:node_3113,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Panner,id:2213,x:31737,y:32387,varname:node_2213,prsc:2,spu:0.2,spv:0.2|UVIN-3113-UVOUT;proporder:1813-2677-8512-6991-1639-392-6999-9039-7499;pass:END;sub:END;*/
Shader "Shader Forge/Sh_Waterfall_PBR" {
Properties {
_Gloss ("Gloss", Range(0, 1)) = 0.8
_Metallic ("Metallic", Float ) = 0
_Reflection ("Reflection", Range(0, 1)) = 0
_Opacity ("Opacity", Range(0, 1)) = 0
_Normal_Tex ("Normal_Tex", 2D) = "bump" {}
_Distorition ("Distorition", Range(0, 1)) = 0.4358974
_Value ("Value", Float ) = 0.2
_Emissive ("Emissive", Range(0, 10)) = 0.5128206
_Dif_Tex ("Dif_Tex", 2D) = "white" {}
[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 only_renderers d3d9 d3d11 glcore gles gles3 metal
#pragma target 2.0
uniform sampler2D _GrabTexture;
uniform float _Gloss;
uniform float _Metallic;
uniform float _Reflection;
uniform float _Opacity;
uniform sampler2D _Normal_Tex; uniform float4 _Normal_Tex_ST;
uniform float _Distorition;
uniform float _Value;
uniform float _Emissive;
uniform sampler2D _Dif_Tex; uniform float4 _Dif_Tex_ST;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
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 vertexColor : COLOR;
float4 projPos : 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;
o.vertexColor = v.vertexColor;
#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.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
return o;
}
float4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float4 node_9256 = _Time;
float2 node_390 = (i.uv0+node_9256.g*float2(0.02,0.02));
float3 _Normal_Tex_var = UnpackNormal(tex2D(_Normal_Tex,TRANSFORM_TEX(node_390, _Normal_Tex)));
float3 normalLocal = normalize(lerp(float3(0,0,1),_Normal_Tex_var.rgb,_Reflection));
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + (_Normal_Tex_var.rgb.rg*(_Distorition*_Value));
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 gloss = _Gloss;
float perceptualRoughness = 1.0 - _Gloss;
float roughness = perceptualRoughness * perceptualRoughness;
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 UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION
d.boxMin[0] = unity_SpecCube0_BoxMin;
d.boxMin[1] = unity_SpecCube1_BoxMin;
#endif
#if 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 = saturate(dot( normalDirection, lightDirection ));
float LdotH = saturate(dot(lightDirection, halfDirection));
float3 specularColor = _Metallic;
float specularMonochrome;
float2 node_2213 = (i.uv0+node_9256.g*float2(0.2,0.2));
float4 _Dif_Tex_var = tex2D(_Dif_Tex,TRANSFORM_TEX(node_2213, _Dif_Tex));
float3 node_6343 = (_Dif_Tex_var.rgb*i.vertexColor.a);
float3 diffuseColor = node_6343; // Need this for specular when using metallic
diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
specularMonochrome = 1.0-specularMonochrome;
float NdotV = abs(dot( normalDirection, viewDirection ));
float NdotH = saturate(dot( normalDirection, halfDirection ));
float VdotH = saturate(dot( viewDirection, halfDirection ));
float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
float normTerm = GGXTerm(NdotH, roughness);
float specularPBL = (visTerm*normTerm) * UNITY_PI;
#ifdef UNITY_COLORSPACE_GAMMA
specularPBL = sqrt(max(1e-4h, specularPBL));
#endif
specularPBL = max(0, specularPBL * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularPBL = 0.0;
#endif
half surfaceReduction;
#ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0-0.28*roughness*perceptualRoughness;
#else
surfaceReduction = 1.0/(roughness*roughness + 1.0);
#endif
specularPBL *= any(specularColor) ? 1.0 : 0.0;
float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
half grazingTerm = saturate( gloss + specularMonochrome );
float3 indirectSpecular = (gi.indirect.specular);
indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);
indirectSpecular *= surfaceReduction;
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;
////// Emissive:
float3 emissive = (node_6343*_Emissive);
/// Final Color:
float3 finalColor = diffuse + specular + emissive;
fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,_Opacity),1);
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 only_renderers d3d9 d3d11 glcore gles gles3 metal
#pragma target 2.0
uniform float _Gloss;
uniform float _Metallic;
uniform float _Emissive;
uniform sampler2D _Dif_Tex; uniform float4 _Dif_Tex_ST;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float4 vertexColor : COLOR;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
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 );
float4 node_8392 = _Time;
float2 node_2213 = (i.uv0+node_8392.g*float2(0.2,0.2));
float4 _Dif_Tex_var = tex2D(_Dif_Tex,TRANSFORM_TEX(node_2213, _Dif_Tex));
float3 node_6343 = (_Dif_Tex_var.rgb*i.vertexColor.a);
o.Emission = (node_6343*_Emissive);
float3 diffColor = node_6343;
float specularMonochrome;
float3 specColor;
diffColor = DiffuseAndSpecularFromMetallic( diffColor, _Metallic, specColor, specularMonochrome );
float roughness = 1.0 - _Gloss;
o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
return UnityMetaFragment( o );
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}
What is the solution?
[1]: /storage/temp/124133-img-0001trim-00107.png
[2]: /storage/temp/124134-img-0001trim-00246.png
, When I build the water material created by Shader Forge in iOS, the reflection moves like photos.
Shaders are as follows.
// Shader created with Shader Forge v1.38
// Shader Forge (c) Freya Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,lico:0,lgpr:1,limd:3,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:True,hqlp:False,rprd:True,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:True,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:2865,x:32963,y:32738,varname:node_2865,prsc:2|diff-6343-OUT,spec-2677-OUT,gloss-1813-OUT,normal-1024-OUT,emission-4134-OUT,alpha-6991-OUT,refract-3972-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:32410,y:32458,varname:node_6343,prsc:2|A-7499-RGB,B-7406-A;n:type:ShaderForge.SFN_Slider,id:1813,x:32181,y:32691,ptovrint:False,ptlb:Gloss,ptin:_Gloss,varname:_Metallic_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.8,max:1;n:type:ShaderForge.SFN_ValueProperty,id:2677,x:32338,y:32622,ptovrint:False,ptlb:Metallic,ptin:_Metallic,varname:node_2677,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0;n:type:ShaderForge.SFN_VertexColor,id:7406,x:32153,y:32470,varname:node_7406,prsc:2;n:type:ShaderForge.SFN_Normalize,id:1024,x:32395,y:32833,varname:node_1024,prsc:2|IN-3332-OUT;n:type:ShaderForge.SFN_Lerp,id:3332,x:32199,y:32833,varname:node_3332,prsc:2|A-9913-OUT,B-1639-RGB,T-8512-OUT;n:type:ShaderForge.SFN_Vector3,id:9913,x:31938,y:32710,varname:node_9913,prsc:2,v1:0,v2:0,v3:1;n:type:ShaderForge.SFN_Slider,id:8512,x:31781,y:32814,ptovrint:False,ptlb:Reflection,ptin:_Reflection,varname:node_8512,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_TexCoord,id:8096,x:31597,y:32882,varname:node_8096,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Panner,id:390,x:31759,y:32882,varname:node_390,prsc:2,spu:0.02,spv:0.02|UVIN-8096-UVOUT;n:type:ShaderForge.SFN_Slider,id:6991,x:32219,y:32982,ptovrint:False,ptlb:Opacity,ptin:_Opacity,varname:node_6991,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Tex2d,id:1639,x:31938,y:32906,ptovrint:False,ptlb:Normal_Tex,ptin:_Normal_Tex,varname:node_1639,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:569206d62ff6ac94b937a1afcfa5b3d3,ntxv:3,isnm:True|UVIN-390-UVOUT;n:type:ShaderForge.SFN_ComponentMask,id:8475,x:32199,y:33073,varname:node_8475,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-1639-RGB;n:type:ShaderForge.SFN_Multiply,id:3972,x:32425,y:33183,varname:node_3972,prsc:2|A-8475-OUT,B-2521-OUT;n:type:ShaderForge.SFN_Multiply,id:2521,x:32199,y:33223,varname:node_2521,prsc:2|A-392-OUT,B-6999-OUT;n:type:ShaderForge.SFN_Slider,id:392,x:31708,y:33110,ptovrint:False,ptlb:Distorition,ptin:_Distorition,varname:node_392,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.4358974,max:1;n:type:ShaderForge.SFN_ValueProperty,id:6999,x:31840,y:33225,ptovrint:False,ptlb:Value,ptin:_Value,varname:node_6999,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0.2;n:type:ShaderForge.SFN_Multiply,id:4134,x:32748,y:32871,varname:node_4134,prsc:2|A-6343-OUT,B-9039-OUT;n:type:ShaderForge.SFN_Slider,id:9039,x:32491,y:33058,ptovrint:False,ptlb:Emissive,ptin:_Emissive,varname:node_9039,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.5128206,max:10;n:type:ShaderForge.SFN_Tex2d,id:7499,x:31997,y:32320,ptovrint:False,ptlb:Dif_Tex,ptin:_Dif_Tex,varname:node_7499,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:746e62f46e897ed41850cd7a9ad4ac03,ntxv:0,isnm:False|UVIN-2213-UVOUT;n:type:ShaderForge.SFN_TexCoord,id:3113,x:31525,y:32387,varname:node_3113,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Panner,id:2213,x:31737,y:32387,varname:node_2213,prsc:2,spu:0.2,spv:0.2|UVIN-3113-UVOUT;proporder:1813-2677-8512-6991-1639-392-6999-9039-7499;pass:END;sub:END;*/
Shader "Shader Forge/Sh_Waterfall_PBR" {
Properties {
_Gloss ("Gloss", Range(0, 1)) = 0.8
_Metallic ("Metallic", Float ) = 0
_Reflection ("Reflection", Range(0, 1)) = 0
_Opacity ("Opacity", Range(0, 1)) = 0
_Normal_Tex ("Normal_Tex", 2D) = "bump" {}
_Distorition ("Distorition", Range(0, 1)) = 0.4358974
_Value ("Value", Float ) = 0.2
_Emissive ("Emissive", Range(0, 10)) = 0.5128206
_Dif_Tex ("Dif_Tex", 2D) = "white" {}
[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 only_renderers d3d9 d3d11 glcore gles gles3 metal
#pragma target 2.0
uniform sampler2D _GrabTexture;
uniform float _Gloss;
uniform float _Metallic;
uniform float _Reflection;
uniform float _Opacity;
uniform sampler2D _Normal_Tex; uniform float4 _Normal_Tex_ST;
uniform float _Distorition;
uniform float _Value;
uniform float _Emissive;
uniform sampler2D _Dif_Tex; uniform float4 _Dif_Tex_ST;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
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 vertexColor : COLOR;
float4 projPos : 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;
o.vertexColor = v.vertexColor;
#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.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
return o;
}
float4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float4 node_9256 = _Time;
float2 node_390 = (i.uv0+node_9256.g*float2(0.02,0.02));
float3 _Normal_Tex_var = UnpackNormal(tex2D(_Normal_Tex,TRANSFORM_TEX(node_390, _Normal_Tex)));
float3 normalLocal = normalize(lerp(float3(0,0,1),_Normal_Tex_var.rgb,_Reflection));
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + (_Normal_Tex_var.rgb.rg*(_Distorition*_Value));
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 gloss = _Gloss;
float perceptualRoughness = 1.0 - _Gloss;
float roughness = perceptualRoughness * perceptualRoughness;
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 UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION
d.boxMin[0] = unity_SpecCube0_BoxMin;
d.boxMin[1] = unity_SpecCube1_BoxMin;
#endif
#if 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 = saturate(dot( normalDirection, lightDirection ));
float LdotH = saturate(dot(lightDirection, halfDirection));
float3 specularColor = _Metallic;
float specularMonochrome;
float2 node_2213 = (i.uv0+node_9256.g*float2(0.2,0.2));
float4 _Dif_Tex_var = tex2D(_Dif_Tex,TRANSFORM_TEX(node_2213, _Dif_Tex));
float3 node_6343 = (_Dif_Tex_var.rgb*i.vertexColor.a);
float3 diffuseColor = node_6343; // Need this for specular when using metallic
diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
specularMonochrome = 1.0-specularMonochrome;
float NdotV = abs(dot( normalDirection, viewDirection ));
float NdotH = saturate(dot( normalDirection, halfDirection ));
float VdotH = saturate(dot( viewDirection, halfDirection ));
float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
float normTerm = GGXTerm(NdotH, roughness);
float specularPBL = (visTerm*normTerm) * UNITY_PI;
#ifdef UNITY_COLORSPACE_GAMMA
specularPBL = sqrt(max(1e-4h, specularPBL));
#endif
specularPBL = max(0, specularPBL * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularPBL = 0.0;
#endif
half surfaceReduction;
#ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0-0.28*roughness*perceptualRoughness;
#else
surfaceReduction = 1.0/(roughness*roughness + 1.0);
#endif
specularPBL *= any(specularColor) ? 1.0 : 0.0;
float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
half grazingTerm = saturate( gloss + specularMonochrome );
float3 indirectSpecular = (gi.indirect.specular);
indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);
indirectSpecular *= surfaceReduction;
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;
////// Emissive:
float3 emissive = (node_6343*_Emissive);
/// Final Color:
float3 finalColor = diffuse + specular + emissive;
fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,_Opacity),1);
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 only_renderers d3d9 d3d11 glcore gles gles3 metal
#pragma target 2.0
uniform float _Gloss;
uniform float _Metallic;
uniform float _Emissive;
uniform sampler2D _Dif_Tex; uniform float4 _Dif_Tex_ST;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float4 vertexColor : COLOR;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
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 );
float4 node_8392 = _Time;
float2 node_2213 = (i.uv0+node_8392.g*float2(0.2,0.2));
float4 _Dif_Tex_var = tex2D(_Dif_Tex,TRANSFORM_TEX(node_2213, _Dif_Tex));
float3 node_6343 = (_Dif_Tex_var.rgb*i.vertexColor.a);
o.Emission = (node_6343*_Emissive);
float3 diffColor = node_6343;
float specularMonochrome;
float3 specColor;
diffColor = DiffuseAndSpecularFromMetallic( diffColor, _Metallic, specColor, specularMonochrome );
float roughness = 1.0 - _Gloss;
o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
return UnityMetaFragment( o );
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}
iPhone is iPhoneSE.
Unity is 2017.4.3f.
What is the solution?
Thank you!
img-0001trim-00107.png
(122.1 kB)
img-0001trim-00246.png
(127.1 kB)
Comment