最近shader学习中,看的视频。
练习的固定管线的shader如下:
ps.在unity5中半透明不好用,其他的还好
1 //不区分大小写 2 //这是固定管线的Shader 3 Shader "ShaderStudy/FixedShader" 4 { 5 Properties//定义属性代码块 6 { 7 //shader中使用的变量名(显示在检视面板中的变量名,变量类型)=初始值 8 _mainColor("Main Color", Color) = (1, 1, 1, 1) 9 _ambientColor("Ambient Color", Color) = (1, 1, 1, 1) 10 _specularColor("Specular Color", Color) = (1, 1, 1, 1) 11 _shininess("Smooth", Range(0, 10)) = 5 12 _emission("Emission", Color) = (1, 1, 1, 1) 13 _constantColor("ConstantColor", Color) = (1, 1, 1, 0.5) 14 _mainTexture("MainTexture", 2D) = ""{} 15 _secondTexture("SecondTexture", 2D) = ""{} 16 } 17 18 SubShader 19 { 20 Tags//标签,表明渲染的顺序 21 { 22 "Queue" = "Transparent" 23 } 24 25 Pass 26 { 27 Blend SrcAlpha OneMinusSrcAlpha//混合源alpha值和1-alpha值,使有关于alpha的改变能够正常实现 28 // color[_MainColor]//单纯设置颜色,这个颜色不带任何效果,[]里面放的是变量 29 // color(1,1,1,1)//()里面放的是常量 30 Material//设置材质 31 { 32 diffuse[_mainColor]//漫反射效果,需要打开光照效果才能正常使用,不然是黑的,因为没有光 33 Ambient[_ambientColor]//环境光效果 34 Specular[_specularColor]//高光效果 35 Shininess[_shininess]//高光集中程度,数值越大越集中,越光滑 36 Emission[_emission]//自发光效果 37 } 38 Lighting On//打开光照效果,即能够反射光线 39 // Lighting Off//关闭光照效果 40 SeparateSpecular On//高光效果打开 41 // SeparateSpecular Off//高光效果关闭 42 43 SetTexture[_mainTexture] 44 { 45 // Combine texture//仅使用texture的颜色信息进行着色 46 // Combine texture * primary//将texture和之前Material中的颜色计算的结果进行混合 47 Combine texture * primary double//颜色值相乘混合后会导致颜色偏暗,double将颜色值乘以2,提亮最终结果 48 // Combine texture * primary quad//颜色值相乘混合后会导致颜色偏暗,quad将所得的颜色值乘以4,提亮最终结果 49 } 50 51 //可以设置多个texture,但是,最大支持多少个texture由硬件决定,硬件越好,支持混合的texture数量越多 52 //一半来讲,2个texture的基本都支持 53 SetTexture[_secondTexture] 54 { 55 ConstantColor[_constantColor] 56 // Combine texture * primary double//这会覆盖之前的texture的计算 57 //将texture与之前经过所有计算而得出的颜色值进行混合,alpha值进行混合 58 Combine texture * previous double, texture * constant 59 //经过测试,unity5里面半透明不好用,随着主摄像机的模式的变化,会掺杂天空盒或者是背景底色,或重复堆叠自身颜色,直至看不出半透明效果 60 } 61 } 62 } 63 }