融合2张纹理

作者:追风剑情 发布于:2018-12-27 17:50 分类:Shader

示例

  1. Shader "Custom/CompositingTest"
  2. {
  3. Properties
  4. {
  5. _MainTex ("_MainTex (A)", 2D) = "black" {}
  6. _SecondTex ("_SecondTex (A)", 2D) = "black" {}
  7. _AlphaParam ("_AlphaParam", Range (0, 1)) = 0.5
  8. _SecondAlphaParam ("_SecondAlphaParam", Range (0, 1)) = 0.5
  9. }
  10.  
  11. CGINCLUDE
  12.  
  13. #include "UnityCG.cginc"
  14.  
  15. sampler2D _MainTex;
  16. sampler2D _SecondTex;
  17. float _AlphaParam;
  18. float _SecondAlphaParam;
  19. float4 _MainTex_ST;
  20.  
  21. struct appdata_t {
  22. float4 vertex : POSITION;
  23. float2 texcoord : TEXCOORD0;
  24. };
  25.  
  26. struct v2f {
  27. float4 vertex : SV_POSITION;
  28. float2 texcoord : TEXCOORD0;
  29. };
  30.  
  31. v2f vertexDirect(appdata_t v)
  32. {
  33. v2f o;
  34. o.vertex = UnityObjectToClipPos(v.vertex);
  35. o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
  36. return o;
  37. }
  38.  
  39. fixed4 fragmentMix(v2f i) : SV_Target
  40. {
  41. fixed4 mainCol = tex2D(_MainTex, i.texcoord);
  42. fixed4 secondCol = tex2D(_SecondTex, i.texcoord);
  43.  
  44. return fixed4(_AlphaParam * mainCol.a * mainCol.rgb + _SecondAlphaParam * secondCol.a * secondCol.rgb, 1.0f);
  45. }
  46.  
  47. ENDCG
  48.  
  49. SubShader
  50. {
  51. Pass
  52. {
  53. Name "Mix_RGBA_To_RGBA"
  54. Cull Off ZWrite On Blend Off
  55. CGPROGRAM
  56. #pragma vertex vertexDirect
  57. #pragma fragment fragmentMix
  58. ENDCG
  59. }
  60. }
  61.  
  62. FallBack Off
  63. }

效果

111.png222.png

333.png444.png

555.png666.png

标签: Shader

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号