Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_CubeMap("CubeMap",CUBE)=""{}
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "UnityCG.cginc"
sampler2D _MainTex;
samplerCUBE _CubeMap;
struct Input {
float4 position:POSITION;
float3 reflectvec;
float2 uv_MainTex:Texcoord1;
};
Input Vert(appdata_full v){
Input i;
i.position = normalize(mul(UNITY_MATRIX_MVP,v.vertex));
i.uv_MainTex = v.texcoord*_CosTime;
float4 pos = normalize(mul(UNITY_MATRIX_MV,v.vertex));
pos = pos/pos.w;
float3 eyevec = normalize(_WorldSpaceCameraPos.xyz-pos.xyz);
float3 tangent = normalize(v.tangent);
float3 normal = normalize(v.normal);
float3 binormal = normalize(cross(normal,v.tangent.xyz)*v.tangent.w);
float3x3 TBN;
TBN[0] = tangent;
TBN[1] = binormal;
TBN[2] = normal;
float3 norm = normalize(mul(TBN,v.normal));
i.reflectvec = reflect(-eyevec,norm);
return i;
}
half4 Frag(Input i):COLOR0
{
return tex2D(_MainTex,i.uv_MainTex)*texCUBE(_CubeMap,i.reflectvec);
}
ENDCG
}
}
_MainTex ("Base (RGB)", 2D) = "white" {}
_CubeMap("CubeMap",CUBE)=""{}
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "UnityCG.cginc"
sampler2D _MainTex;
samplerCUBE _CubeMap;
struct Input {
float4 position:POSITION;
float3 reflectvec;
float2 uv_MainTex:Texcoord1;
};
Input Vert(appdata_full v){
Input i;
i.position = normalize(mul(UNITY_MATRIX_MVP,v.vertex));
i.uv_MainTex = v.texcoord*_CosTime;
float4 pos = normalize(mul(UNITY_MATRIX_MV,v.vertex));
pos = pos/pos.w;
float3 eyevec = normalize(_WorldSpaceCameraPos.xyz-pos.xyz);
float3 tangent = normalize(v.tangent);
float3 normal = normalize(v.normal);
float3 binormal = normalize(cross(normal,v.tangent.xyz)*v.tangent.w);
float3x3 TBN;
TBN[0] = tangent;
TBN[1] = binormal;
TBN[2] = normal;
float3 norm = normalize(mul(TBN,v.normal));
i.reflectvec = reflect(-eyevec,norm);
return i;
}
half4 Frag(Input i):COLOR0
{
return tex2D(_MainTex,i.uv_MainTex)*texCUBE(_CubeMap,i.reflectvec);
}
ENDCG
}
}
}
本人在搞opengl 根据glsl 来编写untiy3d cgshader
顶点着色器---变换顶点,顶点uv信息等等
gl_NormalMatrix 法线转换的untiy3d没有 只能自己创建一个 TBN
片段着色器--根据顶点uv来完成贴图映射
参考 http://www.zwqxin.com/archives/shaderglsl/review-cube-mapping-shader.html