Unity3D Shader 初步学习

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
}

}

本人在搞opengl 根据glsl 来编写untiy3d cgshader 


顶点着色器---变换顶点,顶点uv信息等等

gl_NormalMatrix 法线转换的untiy3d没有 只能自己创建一个 TBN 

片段着色器--根据顶点uv来完成贴图映射


参考 http://www.zwqxin.com/archives/shaderglsl/review-cube-mapping-shader.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值