Created
August 12, 2019 18:51
-
-
Save mazelines/1dee8926c539d29dfb22ab1f10a5082d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "JP-PBR-BASE" | |
| { | |
| Properties | |
| { | |
| _Color("Main Color", Color) = (1,1,1,1) | |
| _MainTex("Base Color", 2D) = "white" {} | |
| _Roughness("Roughness",Range(0,1)) = 1 | |
| _NormalTex("Normal", 2D) = "bump" {} | |
| _AmbientOcclusionTex("Occlusion",2D) = "white" {} | |
| _Anisotropic("Anisotropic", Range(-20,1)) = 0 | |
| _Metallic("Metalness",Range(0,1)) = 0 | |
| _Emissive("Emissive", Float) = 1 | |
| [Header(Artist Lighting)] | |
| [PerRendererData]_DeviationRange("Devitation Direction XYZ", Vector) = (1,1,1) | |
| [NoScaleOffset]_EmissiveTex("Emissive Tex", 2D) = "black" {} | |
| [ToggleOff] _SpecularHighlights("Specular Highlights(遙섇뀎)", Float) = 0 | |
| [ToggleOff] _GlossyReflections("Glossy Reflections(?띶컙)", Float) = 0 | |
| [Toggle] _NonMetal("NonMetal", Float) = 1 | |
| } | |
| SubShader{ | |
| Tags{"RenderType" = "Opaque" "Queue" = "Geometry" "PerformanceChecks"="False"} | |
| Pass{ | |
| Name "FORWARD" | |
| Tags{ | |
| "LightMode" = "ForwardBase" | |
| } | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| #include "UnityCG.cginc" | |
| #include "AutoLight.cginc" | |
| #include "Lighting.cginc" | |
| #include "UnityPBSLighting.cginc" | |
| #include "UnityStandardBRDF.cginc" | |
| #include "UnityStandardCore.cginc" | |
| #include "X2mIncludes/X2mCommon.cginc" | |
| #pragma multi_compile_fwdbase_fullshadows | |
| #pragma shader_feature _SPECULARHIGHLIGHTS_OFF | |
| #pragma shader_feature _GLOSSYREFLECTIONS_OFF | |
| #pragma shader_feature _NONMETAL | |
| #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 d3d11_9x xboxone ps4 psp2 n3ds wiiu vulkan | |
| #pragma target 3.5 | |
| #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) | |
| #define UNITY_PASS_FORWARDBASE | |
| #define _NORMALMAP 1 | |
| #define _CAMERA_LIGHT_ON | |
| uniform half _Anisotropic; | |
| uniform half _Roughness; | |
| uniform half _Emissive; | |
| uniform sampler2D_half _EmissiveTex; uniform half4 _Emissive_ST; | |
| uniform sampler2D_half _NormalTex; uniform half4 _NormalTex_ST; | |
| uniform sampler2D_half _AmbientOcclusionTex; uniform half4 _AmbientOcclusionTex_ST; | |
| uniform half _NonMetal; | |
| uniform half _DeviationRange; | |
| struct VertexBaseInput | |
| { | |
| float4 vertex : POSITION; | |
| float4 color : COLOR; | |
| half3 normal : NORMAL; | |
| float4 texcoord0 : TEXCOORD0; | |
| float4 texcoord1 : TEXCOORD1; | |
| float4 texcoord2 : TEXCOORD2; | |
| half4 tangent : TANGENT; | |
| UNITY_VERTEX_INPUT_INSTANCE_ID | |
| }; | |
| struct VertexOutput | |
| { | |
| float4 pos : SV_POSITION; | |
| float4 uv0 : TEXCOORD0; | |
| float4 uv1 : TEXCOORD1; | |
| float4 uv2 : TEXCOORD2; | |
| float3 viewDir : TEXCOORD3; | |
| half3 normalDir : TEXCOORD4; | |
| half3 tangentDir : TEXCOORD5; | |
| half3 bitangentDir : TEXCOORD6; | |
| half4 ambientOrLightmapUV : TEXCOORD7; // SH or Lightmap UV | |
| float4 posWorld : TEXCOORD8; | |
| UNITY_SHADOW_COORDS(9) | |
| UNITY_VERTEX_INPUT_INSTANCE_ID | |
| UNITY_VERTEX_OUTPUT_STEREO | |
| }; | |
| VertexOutput vert(VertexBaseInput v) | |
| { | |
| UNITY_SETUP_INSTANCE_ID(v); | |
| VertexOutput o = (VertexOutput)0; //초기화 | |
| UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); | |
| 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 * unity_WorldTransformParams.w); | |
| o.pos = UnityObjectToClipPos(v.vertex); | |
| o.uv0.xy = TRANSFORM_TEX(v.texcoord0.xy , _MainTex); | |
| o.uv0.zw = v.texcoord0.zw; | |
| o.uv1 = v.texcoord1; | |
| o.uv2 = v.texcoord2; | |
| float3 lightColor = _LightColor0.rgb; | |
| o.posWorld = mul(unity_ObjectToWorld, v.vertex); | |
| UNITY_TRANSFER_FOG(o,o.pos); | |
| TRANSFER_VERTEX_TO_FRAGMENT(o) | |
| return o; | |
| } | |
| float4 frag(VertexOutput i) : COLOR{ | |
| UNITY_SETUP_INSTANCE_ID(i); | |
| i.normalDir = normalize(i.normalDir); | |
| float3x3 tangentW = float3x3(i.tangentDir, i.bitangentDir, i.normalDir); | |
| half3 Normal_var = UnpackNormal(tex2D(_NormalTex , i.uv0)); | |
| half AO_var = tex2D(_AmbientOcclusionTex , i.uv0.xy); | |
| half3 tangentSpaceNormal = Normal_var.xyz; | |
| float3 normalWorld = normalize(mul(tangentSpaceNormal, tangentW)); | |
| i.viewDir = normalize(i.posWorld.xyz - _WorldSpaceCameraPos); | |
| float3 viewReflectDirection = normalize(reflect(-i.viewDir, normalWorld)); | |
| //float3 lightDir = normalize(_WorldSpaceLightPos0.xyz); | |
| float3 lightDir = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); | |
| float3 lightReflectDirection = reflect(-lightDir, normalWorld); | |
| float3 halfDirection = normalize(i.viewDir + lightDir); | |
| //Extention data sets | |
| float NdotL = max(0.0, dot(normalWorld, lightDir)); | |
| float NdotH = max(0.0, dot(normalWorld, halfDirection)); | |
| float NdotV = max(0.0, dot(normalWorld, i.viewDir)); | |
| float VdotH = max(0.0, dot(i.viewDir, halfDirection)); | |
| float LdotH = max(0.0, dot(lightDir, halfDirection)); | |
| float LdotV = max(0.0, dot(lightDir, i.viewDir)); | |
| float RdotV = max(0.0, dot(lightReflectDirection, i.viewDir)); | |
| float HdotX = dot(halfDirection,i.tangentDir); | |
| float HdotY = dot(halfDirection, i.bitangentDir); | |
| UNITY_LIGHT_ATTENUATION(attenuation, i, i.posWorld.xyz); | |
| float3 attenColor = attenuation * _LightColor0.rgb; | |
| //End of Extention data | |
| half oneMinusReflectivity; | |
| half outputAlpha; | |
| half occlusion= AO_var; | |
| FragmentCommonData s = (FragmentCommonData)0; | |
| s.alpha; | |
| s.diffColor = tex2D(_MainTex, TRANSFORM_TEX(i.uv0, _MainTex)); | |
| s.diffColor = DiffuseAndSpecularFromMetallic(s.diffColor, _Metallic, /*out*/ _SpecColor.rgb, /*out*/ oneMinusReflectivity);; | |
| s.diffColor = PreMultiplyAlpha (s.diffColor, s.alpha, oneMinusReflectivity, /*out*/ outputAlpha); | |
| s.specColor = _SpecColor; | |
| s.oneMinusReflectivity = oneMinusReflectivity; | |
| s.eyeVec = i.viewDir; | |
| s.smoothness = 1-_Roughness; | |
| s.normalWorld = normalWorld; | |
| s.posWorld = i.posWorld.xyz; | |
| UnityLight light = MainLight(); | |
| light.color = _LightColor0; | |
| light.dir = lightDir; | |
| UnityGI gi = FragmentGI(s, occlusion, i.ambientOrLightmapUV, attenuation, light , 1); | |
| half4 c = BRDF1_Unity_PBS(s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness , s.normalWorld, s.eyeVec, gi.light, gi.indirect); | |
| c.a = 1; | |
| return OutputForward( c, c.a ); | |
| } | |
| ENDCG | |
| } | |
| } | |
| FallBack "Legacy Shaders/Diffuse" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment