builtin-camera-texture.effect 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: camera-texture-vs:vert
  7. frag: camera-texture-fs:frag
  8. properties: &props
  9. mainTexture: { value: grey }
  10. tilingOffset: { value: [1, 1, 0, 0] }
  11. mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
  12. colorScale: { value: [1, 1, 1], target: colorScaleAndCutoff.xyz }
  13. alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  14. color: { target: mainColor, editor: { visible: false } } # backward compability
  15. migrations: &migs
  16. properties:
  17. mainColor: { formerlySerializedAs: color }
  18. - name: transparent
  19. passes:
  20. - vert: camera-texture-vs:vert
  21. frag: camera-texture-fs:frag
  22. depthStencilState: &d1
  23. depthTest: true
  24. depthWrite: false
  25. blendState:
  26. targets:
  27. - blend: true
  28. blendSrc: src_alpha
  29. blendDst: one_minus_src_alpha
  30. blendDstAlpha: one_minus_src_alpha
  31. properties: *props
  32. migrations: *migs
  33. - name: add
  34. passes:
  35. - vert: camera-texture-vs:vert
  36. frag: camera-texture-fs:frag
  37. rasterizerState: &r1 { cullMode: none }
  38. depthStencilState: *d1
  39. blendState:
  40. targets:
  41. - blend: true
  42. blendSrc: src_alpha
  43. blendDst: one
  44. blendSrcAlpha: src_alpha
  45. blendDstAlpha: one
  46. properties: *props
  47. migrations: *migs
  48. - name: alpha-blend
  49. passes:
  50. - vert: camera-texture-vs:vert
  51. frag: camera-texture-fs:frag
  52. rasterizerState: *r1
  53. depthStencilState: *d1
  54. blendState:
  55. targets:
  56. - blend: true
  57. blendSrc: src_alpha
  58. blendDst: one_minus_src_alpha
  59. blendSrcAlpha: src_alpha
  60. blendDstAlpha: one_minus_src_alpha
  61. properties: *props
  62. migrations: *migs
  63. }%
  64. CCProgram camera-texture-vs %{
  65. precision highp float;
  66. #include <legacy/input>
  67. #include <builtin/uniforms/cc-global>
  68. #include <legacy/decode-base>
  69. #include <legacy/local-batch>
  70. #include <legacy/input>
  71. #if USE_VERTEX_COLOR
  72. in lowp vec4 a_color;
  73. out lowp vec4 v_color;
  74. #endif
  75. #if USE_TEXTURE
  76. out vec2 v_uv;
  77. uniform TexCoords {
  78. vec4 tilingOffset;
  79. };
  80. #endif
  81. vec4 vert () {
  82. vec4 position;
  83. CCVertInput(position);
  84. mat4 matWorld;
  85. CCGetWorldMatrix(matWorld);
  86. #if USE_TEXTURE
  87. v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;
  88. #if SAMPLE_FROM_RT
  89. CC_HANDLE_RT_SAMPLE_FLIP(v_uv);
  90. #endif
  91. #endif
  92. #if USE_VERTEX_COLOR
  93. v_color = a_color;
  94. #endif
  95. return cc_matProj * (cc_matView * matWorld) * position;
  96. }
  97. }%
  98. CCProgram camera-texture-fs %{
  99. precision highp float;
  100. #include <legacy/output>
  101. #if USE_ALPHA_TEST
  102. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
  103. #endif
  104. #if USE_TEXTURE
  105. in vec2 v_uv;
  106. uniform sampler2D mainTexture;
  107. #endif
  108. uniform Constant {
  109. vec4 mainColor;
  110. vec4 colorScaleAndCutoff;
  111. };
  112. #if USE_VERTEX_COLOR
  113. in lowp vec4 v_color;
  114. #endif
  115. vec4 frag () {
  116. vec4 o = mainColor;
  117. o.rgb *= colorScaleAndCutoff.xyz;
  118. #if USE_VERTEX_COLOR
  119. o *= v_color;
  120. #endif
  121. #if USE_TEXTURE
  122. o *= texture(mainTexture, v_uv);
  123. #endif
  124. #if USE_ALPHA_TEST
  125. if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
  126. #endif
  127. return CCFragOutput(o);
  128. }
  129. }%