前言
初步学习第五章内容。
一、存在疑惑?
1.很多函数,还不清楚则怎么回事
2.概念模糊
二、学习过程
1.尝试写shader代码
Shader "Custom/Simple5" {
Properties {
_Color ("Color Tint", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader
{
Pass
{
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
struct a2v {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLORO;
};
v2f vert(appdata_full v){
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
// o.color = fixed4(v.normal * 0.5 + fixed3(0.5, 0.5, 0.5), 1.0);
// o.color = fixed4(v.tangent * 0.5 + fixed3(0.5, 0.5, 0.5), 1.0);
fixed3 binormal = cross(v.normal, v.tangent.xyz) * v.tangent.w;
o.color = fixed4(binormal * 0.5 + fixed3(0.5, 0.5, 0.5), 1.0);
// o.color = fixed4(v.texcoord.xy, 0.0, 1.0);
// o.color = fixed4(v.texcoord1.xy, 0.0, 1.0);
// o.color = frac(v.texcoord);
// if (any(saturate(v.texcoord) - v.texcoord)) {
// o.color.b = 0.5f;
// }
// o.color.a = 1.0;
// o.color = frac(v.texcoord1);
// if (any(saturate(v.texcoord1) - v.texcoord1)) {
// o.color.b = 0.5f;
// }
// o.color.a = 1.0;
// o.color = v.color;
return o;
}
fixed4 frag(v2f i) : SV_Target {
return i.color;
}
ENDCG
}
}
FallBack "Diffuse"
}
三 学习收获
1.初步尝鲜unity shader 感觉比在大学学的DirectX简单多了,很多东西不需要自己去考虑,只需要去思考着色器怎么写,具体的要等熟悉以后在看看怎么做。
2.见到了一些变量类型、函数,具体的还不熟悉,需要在后续学习中进一步了解。
3.shader调试起来非常麻烦,具体的调试工具晓得有几种,后面用的时候在看看。
4.对平台渲染差异看着一头雾水。
5.规范与简洁、慎用分子和循环语句、不要除以0