纹理块合并命令(combine)

作者:追风剑情 发布于:2018-12-26 18:10 分类:Shader

示例: 演示combine src1 lerp(alpha) src2插值混合效果


  1. Shader "Custom/BindChannelsTest" {
  2. Properties {
  3. //自发光颜色
  4. _IlluminCol ("Self-Illumination color (RGB)", Color) = (1,1,1,1)
  5. _MainTex ("Main Texture", 2D) = "white" {}
  6. }
  7.  
  8. Category {
  9. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  10.  
  11. BindChannels {
  12. Bind "Color", color
  13. Bind "Vertex", vertex
  14. Bind "Normal", normal
  15. //TexCoord对应第一个纹理(_MainTex)
  16. //texcoord1对应第二个SetTexture[]{}
  17. //Bind "TexCoord", texcoord0
  18. //Texcoord1对应第二个纹理(_SecondTex)
  19. //texcoord0对应第一个SetTexture[]{}
  20. //Bind "Texcoord1", texcoord1
  21.  
  22. //所有SetTexture都使用_MainTex的uv坐标
  23. Bind "TexCoord", texcoord //在这个shader中和上面的设置等效
  24.  
  25. //个人理解,不一定正确:
  26. //这里的Channel指的就是SetTexture[]{}
  27. //Bind 第几组纹理, 第几组纹理坐标
  28. //比如,想让SetTexture [_MainTex]使用_SecondTex的uv坐标:
  29. //Bind "TexCoord", texcoord1
  30. }
  31.  
  32. SubShader {
  33. Pass {
  34. SetTexture[_MainTex]
  35. {
  36. //使颜色属性进入混合器
  37. constantColor [_IlluminCol]
  38. //使用纹理的alpha通道混合顶点颜色
  39. //lerp()说明:
  40. //lerp(这里只使用到alpha值)
  41. //combine src1 lerp(alpha) src2
  42. //上面代码的意思: src1与src2之间进行线性插值
  43.  
  44. //相当于lerp(texture, constant.alpha, constant)
  45. //combine constant lerp(texture) previous
  46. //constant.alpha=1,则完全显示constant.rgb颜色
  47. //constant.alpha=0,则完全显示texture.rgb颜色
  48. combine texture lerp(constant) constant
  49. }
  50. }
  51. }
  52. }
  53. }


效果

1111.png222.png

3333.png4444.png

标签: Shader

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号