Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Wetness_Shader" {
- Properties {
- _Gloss ("Gloss", Float ) = 0.75
- _Specularity ("Specularity", Float ) = 0.88
- _Texture ("Texture", 2D) = "white" {}
- _NormalMap ("Normal Map", 2D) = "bump" {}
- }
- SubShader {
- Tags {
- "RenderType"="Opaque"
- }
- 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 d3d11_9x
- #pragma target 3.0
- uniform float4 _LightColor0;
- uniform sampler2D _Texture; uniform float4 _Texture_ST;
- uniform float _Specularity;
- uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST;
- uniform float _Gloss;
- 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(float4(v.normal,0), _World2Object).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);
- 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);
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- /////// Normals:
- float2 node_158 = i.uv0;
- float node_148 = 0.0;
- float4 node_2 = tex2D(_Texture,TRANSFORM_TEX(node_158.rg, _Texture));
- float3 normalLocal = saturate(( saturate((node_148+node_2.b)) > 0.5 ? (1.0-(1.0-2.0*(saturate((node_148+node_2.b))-0.5))*(1.0-saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_158.rg, _NormalMap))).rgb+node_148)))) : (2.0*saturate((node_148+node_2.b))*saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_158.rg, _NormalMap))).rgb+node_148))) ));
- float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
- float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
- float3 halfDirection = normalize(viewDirection+lightDirection);
- ////// Lighting:
- float attenuation = LIGHT_ATTENUATION(i);
- float3 attenColor = attenuation * _LightColor0.xyz;
- /////// Diffuse:
- float NdotL = dot( normalDirection, lightDirection );
- float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
- ///////// Gloss:
- float gloss = _Gloss;
- float specPow = exp2( gloss * 10.0+1.0);
- ////// Specular:
- NdotL = max(0.0, NdotL);
- float3 specularColor = float3(_Specularity,_Specularity,_Specularity);
- float3 specular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
- float3 finalColor = 0;
- float3 diffuseLight = diffuse;
- finalColor += diffuseLight * node_2.rgb;
- finalColor += specular;
- /// Final Color:
- 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 d3d11_9x
- #pragma target 3.0
- uniform float4 _LightColor0;
- uniform sampler2D _Texture; uniform float4 _Texture_ST;
- uniform float _Specularity;
- uniform sampler2D _NormalMap; uniform float4 _NormalMap_ST;
- uniform float _Gloss;
- 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(float4(v.normal,0), _World2Object).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);
- 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);
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- /////// Normals:
- float2 node_159 = i.uv0;
- float node_148 = 0.0;
- float4 node_2 = tex2D(_Texture,TRANSFORM_TEX(node_159.rg, _Texture));
- float3 normalLocal = saturate(( saturate((node_148+node_2.b)) > 0.5 ? (1.0-(1.0-2.0*(saturate((node_148+node_2.b))-0.5))*(1.0-saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_159.rg, _NormalMap))).rgb+node_148)))) : (2.0*saturate((node_148+node_2.b))*saturate((UnpackNormal(tex2D(_NormalMap,TRANSFORM_TEX(node_159.rg, _NormalMap))).rgb+node_148))) ));
- float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
- float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
- float3 halfDirection = normalize(viewDirection+lightDirection);
- ////// Lighting:
- float attenuation = LIGHT_ATTENUATION(i);
- float3 attenColor = attenuation * _LightColor0.xyz;
- /////// Diffuse:
- float NdotL = dot( normalDirection, lightDirection );
- float3 diffuse = max( 0.0, NdotL) * attenColor;
- ///////// Gloss:
- float gloss = _Gloss;
- float specPow = exp2( gloss * 10.0+1.0);
- ////// Specular:
- NdotL = max(0.0, NdotL);
- float3 specularColor = float3(_Specularity,_Specularity,_Specularity);
- float3 specular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
- float3 finalColor = 0;
- float3 diffuseLight = diffuse;
- finalColor += diffuseLight * node_2.rgb;
- finalColor += specular;
- /// Final Color:
- return fixed4(finalColor * 1,0);
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- CustomEditor "ShaderForgeMaterialInspector"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement