I write a material, use surface shader, followed by a normal shader pass.
but the normal shader pass don’t work.
can’t simultaneously use surface shader and normal shader ?
Shader "Reflective/Transparent Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
_Kr ("Reflection", Range(0, 1)) = 0.8
_FresnelMin("Fresnel Reflection Scale", Range(0, 1)) = 0.05
_FresnelExp("Fresnel Exponent", Range(0, 5)) = 3.5
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
CGPROGRAM
#pragma surface surf BlinnPhong alpha
float4 _Color;
float4 _ReflectColor;
float _Kr;
float _FresnelMin;
float _FresnelExp;
sampler2D _MainTex;
samplerCUBE _Cube;
struct Input {
float2 uv_MainTex;
float3 worldRefl;
float3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
pass {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Blend ONE ONE
ZWrite off
//ZTest off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
float4 _Color;
float4 _ReflectColor;
float _Kr;
float _FresnelMin;
float _FresnelExp;
sampler2D _MainTex;
samplerCUBE _Cube;
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float3 reflWorld : TEXCOORD1;
float3 viewDir : TEXCOORD2;
float3 normal : TEXCOORD3;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;
// calculate object space reflection vector
float3 viewDir = ObjSpaceViewDir( v.vertex );
float3 I = reflect( -viewDir, v.normal );
// transform to world space reflection vector
o.reflWorld = mul( (float3x3)_Object2World, I );
o.viewDir = mul((float3x3)_Object2World, viewDir);
o.normal = mul((float3x3)_Object2World, v.normal);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 reflcol = texCUBE( _Cube, i.reflWorld );
half KrMin = (_Kr * _FresnelMin);
half InvFrExp = (1.0f / _FresnelExp);
half fresnel = lerp(_Kr, KrMin, pow(abs(dot(normalize(i.viewDir), normalize(i.normal))), InvFrExp));
reflcol *= fresnel;
half4 result = (half4)0;
result.rgb = reflcol.rgb * _ReflectColor.rgb;
return result;
}
ENDCG
}
}
FallBack "Trasparent/Diffuse"
}