Created
February 14, 2015 09:22
-
-
Save strich/78ae7ddfc9c68a0e8b9d to your computer and use it in GitHub Desktop.
This file contains 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 created with Shader Forge v1.02 | |
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/ | |
// Note: Manually altering this data may prevent you from opening it in Shader Forge | |
/*SF_DATA;ver:1.02;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,rprd:False,enco:False,frtr:True,vitr:True,dbil:True,rmgx:True,rpth:1,hqsc:False,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:1,culm:0,dpts:2,wrdp:True,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,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,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:1,x:34625,y:32712,varname:node_1,prsc:2|diff-391-OUT,spec-435-OUT,gloss-79-OUT,normal-44-RGB,emission-617-OUT,amspl-192-OUT;n:type:ShaderForge.SFN_Tex2d,id:5,x:33399,y:31694,ptovrint:False,ptlb:Diffuse,ptin:_Diffuse,varname:node_3400,prsc:2,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Color,id:6,x:33399,y:31922,ptovrint:False,ptlb:Color,ptin:_Color,varname:node_5218,prsc:2,glob:False,c1:0.4980392,c2:0.4980392,c3:0.4980392,c4:1;n:type:ShaderForge.SFN_Multiply,id:7,x:33678,y:31913,varname:node_7,prsc:2|A-5-RGB,B-6-RGB;n:type:ShaderForge.SFN_Tex2d,id:25,x:32778,y:32508,ptovrint:False,ptlb:Specular_R Gloss_G,ptin:_Specular_RGloss_G,varname:node_5859,prsc:2,ntxv:2,isnm:False;n:type:ShaderForge.SFN_Multiply,id:42,x:33911,y:32495,varname:node_42,prsc:2|A-25-R,B-52-OUT;n:type:ShaderForge.SFN_Tex2d,id:44,x:34640,y:32447,ptovrint:False,ptlb:Normal Map,ptin:_NormalMap,varname:node_894,prsc:2,ntxv:3,isnm:True;n:type:ShaderForge.SFN_ValueProperty,id:52,x:33699,y:32469,ptovrint:False,ptlb:Specular Intensity,ptin:_SpecularIntensity,varname:node_2046,prsc:2,glob:False,v1:1;n:type:ShaderForge.SFN_Cubemap,id:59,x:33324,y:33394,ptovrint:False,ptlb:Reflection,ptin:_Reflection,varname:node_4029,prsc:2,cube:f466cf7415226e046b096197eb7341aa,pvfc:1;n:type:ShaderForge.SFN_Multiply,id:79,x:33302,y:33082,varname:node_79,prsc:2|A-111-OUT,B-8704-OUT;n:type:ShaderForge.SFN_ConstantClamp,id:111,x:33038,y:32675,varname:node_111,prsc:2,min:0.25,max:1|IN-25-G;n:type:ShaderForge.SFN_Multiply,id:188,x:33833,y:33324,varname:node_188,prsc:2|A-278-OUT,B-396-OUT;n:type:ShaderForge.SFN_Multiply,id:192,x:34090,y:33655,varname:node_192,prsc:2|A-188-OUT,B-193-OUT;n:type:ShaderForge.SFN_Add,id:193,x:33833,y:33861,varname:node_193,prsc:2|A-194-OUT,B-195-OUT;n:type:ShaderForge.SFN_Multiply,id:194,x:33630,y:33751,varname:node_194,prsc:2|A-196-OUT,B-197-OUT;n:type:ShaderForge.SFN_OneMinus,id:195,x:33630,y:33956,varname:node_195,prsc:2|IN-197-OUT;n:type:ShaderForge.SFN_ComponentMask,id:196,x:33366,y:33679,varname:node_196,prsc:2,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-198-OUT;n:type:ShaderForge.SFN_Vector1,id:197,x:33366,y:33832,varname:node_197,prsc:2,v1:0.4;n:type:ShaderForge.SFN_NormalVector,id:198,x:33116,y:33679,prsc:2,pt:False;n:type:ShaderForge.SFN_Multiply,id:278,x:33667,y:33252,varname:node_278,prsc:2|A-79-OUT,B-59-RGB;n:type:ShaderForge.SFN_Lerp,id:388,x:33982,y:31711,varname:node_388,prsc:2|A-5-RGB,B-390-OUT,T-5-A;n:type:ShaderForge.SFN_Lerp,id:389,x:33965,y:31919,varname:node_389,prsc:2|A-390-OUT,B-7-OUT,T-5-A;n:type:ShaderForge.SFN_Vector1,id:390,x:33669,y:31592,varname:node_390,prsc:2,v1:0;n:type:ShaderForge.SFN_Add,id:391,x:34284,y:31818,varname:node_391,prsc:2|A-388-OUT,B-389-OUT;n:type:ShaderForge.SFN_Clamp01,id:435,x:34230,y:32636,varname:node_435,prsc:2|IN-42-OUT;n:type:ShaderForge.SFN_Multiply,id:617,x:34276,y:32949,varname:node_617,prsc:2|A-621-RGB,B-619-RGB,C-5404-OUT;n:type:ShaderForge.SFN_Color,id:619,x:34016,y:32986,ptovrint:False,ptlb:TeamColor,ptin:_TeamColor,varname:node_3765,prsc:2,glob:False,c1:1,c2:1,c3:1,c4:1;n:type:ShaderForge.SFN_Tex2d,id:621,x:33926,y:32739,ptovrint:False,ptlb:Emissive,ptin:_Emissive,varname:node_428,prsc:2,tex:c66f32dde8532284294be7d980b15cdc,ntxv:2,isnm:False;n:type:ShaderForge.SFN_ValueProperty,id:5404,x:34016,y:33163,ptovrint:False,ptlb:Emissive Strength,ptin:_EmissiveStrength,varname:node_5404,prsc:2,glob:False,v1:0;n:type:ShaderForge.SFN_ValueProperty,id:396,x:33638,y:33596,ptovrint:False,ptlb: Reflection Strength,ptin:_ReflectionStrength,varname:node_396,prsc:2,glob:False,v1:0;n:type:ShaderForge.SFN_ValueProperty,id:8704,x:33019,y:33100,ptovrint:False,ptlb:Shininess,ptin:_Shininess,varname:node_8704,prsc:2,glob:False,v1:0;proporder:6-5-25-52-8704-44-59-396-619-621-5404;pass:END;sub:END;*/ | |
Shader "Environment/EnvironmentTeam" { | |
Properties { | |
_Color ("Color", Color) = (0.4980392,0.4980392,0.4980392,1) | |
_Diffuse ("Diffuse", 2D) = "white" {} | |
_Specular_RGloss_G ("Specular_R Gloss_G", 2D) = "black" {} | |
_SpecularIntensity ("Specular Intensity", Float ) = 1 | |
_Shininess ("Shininess", Float ) = 0 | |
_NormalMap ("Normal Map", 2D) = "bump" {} | |
_Reflection ("Reflection", Cube) = "_Skybox" {} | |
_ReflectionStrength (" Reflection Strength", Float ) = 0 | |
_TeamColor ("TeamColor", Color) = (1,1,1,1) | |
_Emissive ("Emissive", 2D) = "black" {} | |
_EmissiveStrength ("Emissive Strength", Float ) = 0 | |
} | |
SubShader { | |
Tags { | |
"RenderType"="Opaque" | |
} | |
Pass { | |
Name "PrePassBase" | |
Tags { | |
"LightMode"="PrePassBase" | |
} | |
Fog {Mode Off} | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_PREPASSBASE | |
#include "UnityCG.cginc" | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform fixed4 unity_Ambient; | |
uniform sampler2D _Specular_RGloss_G; uniform float4 _Specular_RGloss_G_ST; | |
uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST; | |
uniform float _Shininess; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
float2 texcoord0 : TEXCOORD0; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float2 uv0 : TEXCOORD0; | |
float4 posWorld : TEXCOORD1; | |
float3 normalDir : TEXCOORD2; | |
float3 tangentDir : TEXCOORD3; | |
float3 binormalDir : TEXCOORD4; | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.uv0 = v.texcoord0; | |
o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz; | |
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz ); | |
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); | |
o.posWorld = mul(_Object2World, v.vertex); | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); | |
/////// Vectors: | |
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); | |
float3 _NormalMap_var = UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(i.uv0, _NormalMap))); | |
float3 normalLocal = _NormalMap_var.rgb; | |
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals | |
float4 _Specular_RGloss_G_var = tex2D(_Specular_RGloss_G,TRANSFORM_TEX(i.uv0, _Specular_RGloss_G)); | |
float node_79 = (clamp(_Specular_RGloss_G_var.g,0.25,1)*_Shininess); | |
return fixed4( normalDirection * 0.5 + 0.5, max(node_79,0.0078125) ); | |
} | |
ENDCG | |
} | |
Pass { | |
Name "PrePassFinal" | |
Tags { | |
"LightMode"="PrePassFinal" | |
} | |
ZWrite Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_PREPASSFINAL | |
#include "UnityCG.cginc" | |
#pragma multi_compile_prepassfinal | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform sampler2D _LightBuffer; | |
#if defined (SHADER_API_XBOX360) && defined (HDR_LIGHT_PREPASS_ON) | |
sampler2D _LightSpecBuffer; | |
#endif | |
uniform fixed4 unity_Ambient; | |
uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST; | |
uniform float4 _Color; | |
uniform sampler2D _Specular_RGloss_G; uniform float4 _Specular_RGloss_G_ST; | |
uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST; | |
uniform float _SpecularIntensity; | |
uniform samplerCUBE _Reflection; | |
uniform float4 _TeamColor; | |
uniform sampler2D _Emissive; uniform float4 _Emissive_ST; | |
uniform float _EmissiveStrength; | |
uniform float _ReflectionStrength; | |
uniform float _Shininess; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
float2 texcoord0 : TEXCOORD0; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float2 uv0 : TEXCOORD0; | |
float4 posWorld : TEXCOORD1; | |
float3 normalDir : TEXCOORD2; | |
float3 tangentDir : TEXCOORD3; | |
float3 binormalDir : TEXCOORD4; | |
float4 projPos : TEXCOORD5; | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.uv0 = v.texcoord0; | |
o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz; | |
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz ); | |
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); | |
o.posWorld = mul(_Object2World, v.vertex); | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.projPos = ComputeScreenPos (o.pos); | |
COMPUTE_EYEDEPTH(o.projPos.z); | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); | |
/////// Vectors: | |
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); | |
float3 _NormalMap_var = UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(i.uv0, _NormalMap))); | |
float3 normalLocal = _NormalMap_var.rgb; | |
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals | |
float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); | |
////// Lighting: | |
half4 lightAccumulation = tex2Dproj(_LightBuffer, UNITY_PROJ_COORD(i.projPos)); | |
#if defined (SHADER_API_GLES) || defined (SHADER_API_GLES3) | |
lightAccumulation = max(lightAccumulation, half4(0.001)); | |
#endif | |
#ifndef HDR_LIGHT_PREPASS_ON | |
lightAccumulation = -log2(lightAccumulation); | |
#endif | |
#if defined (SHADER_API_XBOX360) && defined (HDR_LIGHT_PREPASS_ON) | |
lightAccumulation.w = tex2Dproj (_LightSpecBuffer, UNITY_PROJ_COORD(i.projPos)).r; | |
#endif | |
////// Specular: | |
float4 _Specular_RGloss_G_var = tex2D(_Specular_RGloss_G,TRANSFORM_TEX(i.uv0, _Specular_RGloss_G)); | |
float node_79 = (clamp(_Specular_RGloss_G_var.g,0.25,1)*_Shininess); | |
float node_197 = 0.4; | |
float node_435 = saturate((_Specular_RGloss_G_var.r*_SpecularIntensity)); | |
float3 specularColor = float3(node_435,node_435,node_435); | |
float3 directSpecular = (lightAccumulation.rgb * 2)*lightAccumulation.a; | |
float3 indirectSpecular = (0 + (((node_79*texCUBE(_Reflection,viewReflectDirection).rgb)*_ReflectionStrength)*((i.normalDir.g*node_197)+(1.0 - node_197)))); | |
float3 specular = (directSpecular + indirectSpecular) * specularColor; | |
/////// Diffuse: | |
float3 indirectDiffuse = float3(0,0,0); | |
float3 directDiffuse = lightAccumulation.rgb; | |
indirectDiffuse += unity_Ambient.rgb; // Ambient Light | |
float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse)); | |
float node_390 = 0.0; | |
float3 diffuse = (directDiffuse + indirectDiffuse) * (lerp(_Diffuse_var.rgb,float3(node_390,node_390,node_390),_Diffuse_var.a)+lerp(float3(node_390,node_390,node_390),(_Diffuse_var.rgb*_Color.rgb),_Diffuse_var.a)); | |
////// Emissive: | |
float4 _Emissive_var = tex2D(_Emissive,TRANSFORM_TEX(i.uv0, _Emissive)); | |
float3 emissive = (_Emissive_var.rgb*_TeamColor.rgb*_EmissiveStrength); | |
/// Final Color: | |
float3 finalColor = diffuse + specular + emissive; | |
return fixed4(finalColor,1); | |
} | |
ENDCG | |
} | |
Pass { | |
Name "ForwardBase" | |
Tags { | |
"LightMode"="ForwardBase" | |
} | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_FORWARDBASE | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
#pragma multi_compile_fwdbase_fullshadows | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform float4 _LightColor0; | |
uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST; | |
uniform float4 _Color; | |
uniform sampler2D _Specular_RGloss_G; uniform float4 _Specular_RGloss_G_ST; | |
uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST; | |
uniform float _SpecularIntensity; | |
uniform samplerCUBE _Reflection; | |
uniform float4 _TeamColor; | |
uniform sampler2D _Emissive; uniform float4 _Emissive_ST; | |
uniform float _EmissiveStrength; | |
uniform float _ReflectionStrength; | |
uniform float _Shininess; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
float2 texcoord0 : TEXCOORD0; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float2 uv0 : TEXCOORD0; | |
float4 posWorld : TEXCOORD1; | |
float3 normalDir : TEXCOORD2; | |
float3 tangentDir : TEXCOORD3; | |
float3 binormalDir : TEXCOORD4; | |
LIGHTING_COORDS(5,6) | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.uv0 = v.texcoord0; | |
o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz; | |
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz ); | |
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); | |
o.posWorld = mul(_Object2World, v.vertex); | |
float3 lightColor = _LightColor0.rgb; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
TRANSFER_VERTEX_TO_FRAGMENT(o) | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); | |
/////// Vectors: | |
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); | |
float3 _NormalMap_var = UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(i.uv0, _NormalMap))); | |
float3 normalLocal = _NormalMap_var.rgb; | |
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals | |
float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); | |
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); | |
float3 lightColor = _LightColor0.rgb; | |
float3 halfDirection = normalize(viewDirection+lightDirection); | |
////// Lighting: | |
float attenuation = LIGHT_ATTENUATION(i)*2; | |
float3 attenColor = attenuation * _LightColor0.xyz; | |
///////// Gloss: | |
float4 _Specular_RGloss_G_var = tex2D(_Specular_RGloss_G,TRANSFORM_TEX(i.uv0, _Specular_RGloss_G)); | |
float node_79 = (clamp(_Specular_RGloss_G_var.g,0.25,1)*_Shininess); | |
float gloss = node_79; | |
float specPow = exp2( gloss * 10.0+1.0); | |
////// Specular: | |
float NdotL = max(0, dot( normalDirection, lightDirection )); | |
float node_197 = 0.4; | |
float node_435 = saturate((_Specular_RGloss_G_var.r*_SpecularIntensity)); | |
float3 specularColor = float3(node_435,node_435,node_435); | |
float3 directSpecular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow); | |
float3 indirectSpecular = (0 + (((node_79*texCUBE(_Reflection,viewReflectDirection).rgb)*_ReflectionStrength)*((i.normalDir.g*node_197)+(1.0 - node_197)))); | |
float3 specular = (directSpecular + indirectSpecular) * specularColor; | |
/////// Diffuse: | |
NdotL = max(0.0,dot( normalDirection, lightDirection )); | |
float3 indirectDiffuse = float3(0,0,0); | |
float3 directDiffuse = max( 0.0, NdotL) * attenColor; | |
indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb*2; // Ambient Light | |
float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse)); | |
float node_390 = 0.0; | |
float3 diffuse = (directDiffuse + indirectDiffuse) * (lerp(_Diffuse_var.rgb,float3(node_390,node_390,node_390),_Diffuse_var.a)+lerp(float3(node_390,node_390,node_390),(_Diffuse_var.rgb*_Color.rgb),_Diffuse_var.a)); | |
////// Emissive: | |
float4 _Emissive_var = tex2D(_Emissive,TRANSFORM_TEX(i.uv0, _Emissive)); | |
float3 emissive = (_Emissive_var.rgb*_TeamColor.rgb*_EmissiveStrength); | |
/// Final Color: | |
float3 finalColor = diffuse + specular + emissive; | |
return fixed4(finalColor,1); | |
} | |
ENDCG | |
} | |
Pass { | |
Name "ForwardAdd" | |
Tags { | |
"LightMode"="ForwardAdd" | |
} | |
Blend One One | |
Fog { Color (0,0,0,0) } | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_FORWARDADD | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
#pragma multi_compile_fwdadd_fullshadows | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform float4 _LightColor0; | |
uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST; | |
uniform float4 _Color; | |
uniform sampler2D _Specular_RGloss_G; uniform float4 _Specular_RGloss_G_ST; | |
uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST; | |
uniform float _SpecularIntensity; | |
uniform float4 _TeamColor; | |
uniform sampler2D _Emissive; uniform float4 _Emissive_ST; | |
uniform float _EmissiveStrength; | |
uniform float _Shininess; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
float2 texcoord0 : TEXCOORD0; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float2 uv0 : TEXCOORD0; | |
float4 posWorld : TEXCOORD1; | |
float3 normalDir : TEXCOORD2; | |
float3 tangentDir : TEXCOORD3; | |
float3 binormalDir : TEXCOORD4; | |
LIGHTING_COORDS(5,6) | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.uv0 = v.texcoord0; | |
o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz; | |
o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz ); | |
o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); | |
o.posWorld = mul(_Object2World, v.vertex); | |
float3 lightColor = _LightColor0.rgb; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
TRANSFER_VERTEX_TO_FRAGMENT(o) | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); | |
/////// Vectors: | |
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); | |
float3 _NormalMap_var = UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(i.uv0, _NormalMap))); | |
float3 normalLocal = _NormalMap_var.rgb; | |
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals | |
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)*2; | |
float3 attenColor = attenuation * _LightColor0.xyz; | |
///////// Gloss: | |
float4 _Specular_RGloss_G_var = tex2D(_Specular_RGloss_G,TRANSFORM_TEX(i.uv0, _Specular_RGloss_G)); | |
float node_79 = (clamp(_Specular_RGloss_G_var.g,0.25,1)*_Shininess); | |
float gloss = node_79; | |
float specPow = exp2( gloss * 10.0+1.0); | |
////// Specular: | |
float NdotL = max(0, dot( normalDirection, lightDirection )); | |
float node_435 = saturate((_Specular_RGloss_G_var.r*_SpecularIntensity)); | |
float3 specularColor = float3(node_435,node_435,node_435); | |
float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow); | |
float3 specular = directSpecular * specularColor; | |
/////// Diffuse: | |
NdotL = max(0.0,dot( normalDirection, lightDirection )); | |
float3 directDiffuse = max( 0.0, NdotL) * attenColor; | |
float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse)); | |
float node_390 = 0.0; | |
float3 diffuse = directDiffuse * (lerp(_Diffuse_var.rgb,float3(node_390,node_390,node_390),_Diffuse_var.a)+lerp(float3(node_390,node_390,node_390),(_Diffuse_var.rgb*_Color.rgb),_Diffuse_var.a)); | |
/// Final Color: | |
float3 finalColor = diffuse + specular; | |
return fixed4(finalColor * 1,0); | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
CustomEditor "ShaderForgeMaterialInspector" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment