Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/OpaqueShader" {
- Properties {
- dColor ("Diffuse Color", Color) = (1.0, 1.0, 1.0, 1.0)
- sColor ("Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
- sPow ("Specular Power", Float) = 50.0
- fPow ("Fresnel Power", Float) = 10
- sStre ("Specular Strength", Float) = 20.0
- fStre ("Fresnel Strength", Float) = 10
- _MainTex ("Diffuse Texture", 2D) = "white" {}
- }
- SubShader {
- Pass {
- Tags { "LightMode" = "ForwardBase" "RenderType" = "Opaque" }
- Cull Back
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 3.0
- #pragma glsl
- #pragma multi_compile_fwdbase
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- sampler2D _MainTex;
- float sPow;
- float sStre;
- float fPow;
- float fStre;
- float4 dColor;
- float4 sColor;
- float4 _LightColor0;
- struct vOut {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD0;
- float4 pW : TEXCOORD1;
- float3 nW : TEXCOORD2;
- //float3 tW : TEXCOORD3;
- //float3 bI : TEXCOORD4;
- LIGHTING_COORDS(3,4)
- };
- vOut vert(appdata_base v){
- vOut o;
- o.nW = normalize( mul( float4(v.normal, 0.0), _World2Object).xyz);
- //o.tW = normalize( mul(_Object2World, v.tangent).xyz );
- //o.bI = normalize( cross(o.nW, o.tW) * v.tangent.w);
- o.pW = mul(_Object2World, v.vertex);
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uv = v.texcoord.xy;
- TRANSFER_VERTEX_TO_FRAGMENT(o);
- return o;
- }
- float4 frag(vOut i) : COLOR {
- float3 l = normalize( _WorldSpaceLightPos0.xyz );
- float3 n = normalize( i.nW );
- float3 v = normalize( _WorldSpaceCameraPos.xyz - i.pW.xyz );
- float3 h = normalize(v + l);
- float at = LIGHT_ATTENUATION(i);
- float3 ndotL = _LightColor0.rgb * saturate( dot(n, l)) * dColor.rgb;
- float3 spec = (saturate( pow(dot(n, v), sPow)) * sColor.rgb) * sStre;
- float3 fres = saturate(1.0f - pow(dot(v, n), fPow)) * fStre;
- spec *= ndotL;
- fres *= ndotL;
- ndotL *= at;
- spec *= at;
- fres *= at;
- return float4(ndotL + spec + fres, 1.0);
- }
- ENDCG
- }
- }
- Fallback "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement