From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Previews/Preview_IndirectDiffuseLight.shader | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/EditorResources/Previews/Preview_IndirectDiffuseLight.shader (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/EditorResources/Previews/Preview_IndirectDiffuseLight.shader') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/EditorResources/Previews/Preview_IndirectDiffuseLight.shader b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/EditorResources/Previews/Preview_IndirectDiffuseLight.shader new file mode 100644 index 00000000..65695576 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/EditorResources/Previews/Preview_IndirectDiffuseLight.shader @@ -0,0 +1,106 @@ +Shader "Hidden/IndirectDiffuseLight" +{ + Properties + { + _Intensity ("Intensity", Float) = 1 + } + + SubShader + { + Pass + { + CGPROGRAM + #pragma vertex vert_img + #pragma fragment frag + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + float _Intensity; + + float4 frag(v2f_img i) : SV_Target + { + float2 xy = 2 * i.uv - 1; + float z = -sqrt(1-saturate(dot(xy,xy))); + float3 worldNormal = normalize(float3(xy, z)); + float3 vertexPos = float3(xy, z); + float3 worldPos = mul(unity_ObjectToWorld, float4(vertexPos,1)).xyz; + float4 back = lerp(float4(0.4117,0.3843,0.3647,1),float4(0.4117,0.5059,0.6470,1),worldPos.y * 0.5 + 0.5); + return float4(GammaToLinearSpace(back.rgb * _Intensity),1); + } + ENDCG + } + + Pass // connected tangent + { + CGPROGRAM + #pragma vertex vert_img + #pragma fragment frag + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + float _Intensity; + sampler2D _A; + + float4 frag(v2f_img i) : SV_Target + { + float2 xy = 2 * i.uv - 1; + float z = -sqrt(1-saturate(dot(xy,xy))); + float3 vertexPos = float3(xy, z); + float3 normal = normalize(vertexPos); + float3 worldNormal = UnityObjectToWorldNormal(normal); + + float3 tangent = normalize(float3( -z, xy.y*0.01, xy.x )); + float3 worldPos = mul(unity_ObjectToWorld, float4(vertexPos,1)).xyz; + float3 worldTangent = UnityObjectToWorldDir(tangent); + float tangentSign = -1; + float3 worldBinormal = normalize( cross(worldNormal, worldTangent) * tangentSign); + float4 tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x); + float4 tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y); + float4 tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z); + + float2 sphereUVs = i.uv; + + sphereUVs.x = (atan2(vertexPos.x, -vertexPos.z) / (UNITY_PI) + 0.5); + // Needs further checking + //float3 tangentNormal = tex2Dlod(_A, float4(sphereUVs,0,0)).xyz; + float3 tangentNormal = tex2D(_A, sphereUVs).xyz; + + worldNormal = fixed3( dot( tSpace0.xyz, tangentNormal ), dot( tSpace1.xyz, tangentNormal ), dot( tSpace2.xyz, tangentNormal ) ); + + float4 back = lerp(float4(0.4117,0.3843,0.3647,1),float4(0.4117,0.5059,0.6470,1),worldNormal.y * 0.5 + 0.5); + + return float4(GammaToLinearSpace(back.rgb * _Intensity),1); + } + ENDCG + } + + Pass // connected world + { + CGPROGRAM + #pragma vertex vert_img + #pragma fragment frag + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + float _Intensity; + sampler2D _A; + + float4 frag( v2f_img i ) : SV_Target + { + float2 xy = 2 * i.uv - 1; + float z = -sqrt( 1 - saturate( dot( xy,xy ) ) ); + float3 vertexPos = float3( xy, z ); + float3 normal = normalize( vertexPos ); + float3 worldNormal = tex2D( _A, i.uv ); + + float4 back = lerp( float4( 0.4117,0.3843,0.3647,1 ),float4( 0.4117,0.5059,0.6470,1 ),worldNormal.y * 0.5 + 0.5 ); + + return float4( GammaToLinearSpace( back.rgb * _Intensity ),1 ); + } + ENDCG + } + } +} -- cgit v1.1-26-g67d0