builtin-unlit.effect 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: unlit-vs:vert
  7. frag: unlit-fs:frag
  8. properties: &props
  9. mainTexture: { value: grey }
  10. tilingOffset: { value: [1, 1, 0, 0] }
  11. mainColor: { value: [1, 1, 1, 1], linear: true, 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, linear: true, editor: { visible: false } } # backward compability
  15. migrations: &migs
  16. properties:
  17. mainColor: { formerlySerializedAs: color }
  18. - &planar-shadow
  19. vert: planar-shadow-vs:vert
  20. frag: planar-shadow-fs:frag
  21. phase: planar-shadow
  22. propertyIndex: 0
  23. depthStencilState:
  24. depthTest: true
  25. depthWrite: false
  26. stencilTestFront: true
  27. stencilFuncFront: not_equal
  28. stencilPassOpFront: replace
  29. stencilRef: 0x80 # only use the leftmost bit
  30. stencilReadMask: 0x80
  31. stencilWriteMask: 0x80
  32. blendState:
  33. targets:
  34. - blend: true
  35. blendSrc: src_alpha
  36. blendDst: one_minus_src_alpha
  37. blendDstAlpha: one_minus_src_alpha
  38. - &deferred-forward
  39. vert: unlit-vs:vert
  40. frag: unlit-fs:frag
  41. phase: deferred-forward
  42. propertyIndex: 0
  43. - name: transparent
  44. passes:
  45. - vert: unlit-vs:vert
  46. frag: unlit-fs:frag
  47. depthStencilState: &d1
  48. depthTest: true
  49. depthWrite: false
  50. blendState: &b1
  51. targets:
  52. - blend: true
  53. blendSrc: src_alpha
  54. blendDst: one_minus_src_alpha
  55. blendDstAlpha: one_minus_src_alpha
  56. properties: *props
  57. migrations: *migs
  58. - *planar-shadow
  59. - &deferred-forward-transparent
  60. vert: unlit-vs:vert
  61. frag: unlit-fs:frag
  62. phase: deferred-forward
  63. propertyIndex: 0
  64. migrations: *migs
  65. depthStencilState: *d1
  66. blendState: *b1
  67. - name: add
  68. passes:
  69. - vert: unlit-vs:vert
  70. frag: unlit-fs:frag
  71. rasterizerState: &r1 { cullMode: none }
  72. depthStencilState: *d1
  73. blendState: &b2
  74. targets:
  75. - blend: true
  76. blendSrc: src_alpha
  77. blendDst: one
  78. blendSrcAlpha: src_alpha
  79. blendDstAlpha: one
  80. properties: *props
  81. migrations: *migs
  82. - &deferred-forward-add
  83. vert: unlit-vs:vert
  84. frag: unlit-fs:frag
  85. phase: deferred-forward
  86. rasterizerState: *r1
  87. depthStencilState: *d1
  88. blendState: *b2
  89. propertyIndex: 0
  90. migrations: *migs
  91. - name: alpha-blend
  92. passes:
  93. - vert: unlit-vs:vert
  94. frag: unlit-fs:frag
  95. rasterizerState: *r1
  96. depthStencilState: *d1
  97. blendState: &b3
  98. targets:
  99. - blend: true
  100. blendSrc: src_alpha
  101. blendDst: one_minus_src_alpha
  102. blendSrcAlpha: src_alpha
  103. blendDstAlpha: one_minus_src_alpha
  104. properties: *props
  105. migrations: *migs
  106. - &deferred-forward-alpha-blend
  107. vert: unlit-vs:vert
  108. frag: unlit-fs:frag
  109. phase: deferred-forward
  110. rasterizerState: *r1
  111. depthStencilState: *d1
  112. blendState: *b3
  113. propertyIndex: 0
  114. migrations: *migs
  115. }%
  116. CCProgram unlit-vs %{
  117. precision highp float;
  118. #include <legacy/input>
  119. #include <builtin/uniforms/cc-global>
  120. #include <legacy/decode-base>
  121. #include <legacy/local-batch>
  122. #include <legacy/input>
  123. #include <legacy/fog-vs>
  124. #if USE_VERTEX_COLOR
  125. in lowp vec4 a_color;
  126. out lowp vec4 v_color;
  127. #endif
  128. #if USE_TEXTURE
  129. out vec2 v_uv;
  130. uniform TexCoords {
  131. vec4 tilingOffset;
  132. };
  133. #endif
  134. vec4 vert () {
  135. vec4 position;
  136. CCVertInput(position);
  137. mat4 matWorld;
  138. CCGetWorldMatrix(matWorld);
  139. #if USE_TEXTURE
  140. v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;
  141. #if SAMPLE_FROM_RT
  142. CC_HANDLE_RT_SAMPLE_FLIP(v_uv);
  143. #endif
  144. #endif
  145. #if USE_VERTEX_COLOR
  146. v_color = a_color;
  147. #endif
  148. CC_TRANSFER_FOG(matWorld * position);
  149. #if CC_USE_2D
  150. return cc_matProj * cc_matView * position;
  151. #else
  152. return cc_matProj * (cc_matView * matWorld) * position;
  153. #endif
  154. }
  155. }%
  156. CCProgram unlit-fs %{
  157. precision highp float;
  158. #include <legacy/output-standard>
  159. #include <legacy/fog-fs>
  160. #if USE_ALPHA_TEST
  161. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
  162. #endif
  163. #if USE_TEXTURE
  164. in vec2 v_uv;
  165. uniform sampler2D mainTexture;
  166. #endif
  167. uniform Constant {
  168. vec4 mainColor;
  169. vec4 colorScaleAndCutoff;
  170. };
  171. #if USE_VERTEX_COLOR
  172. in lowp vec4 v_color;
  173. #endif
  174. vec4 frag () {
  175. vec4 o = mainColor;
  176. o.rgb *= colorScaleAndCutoff.xyz;
  177. #if USE_VERTEX_COLOR
  178. o.rgb *= SRGBToLinear(v_color.rgb);//use linear
  179. o.a *= v_color.a;
  180. #endif
  181. #if USE_TEXTURE
  182. vec4 texColor = texture(mainTexture, v_uv);
  183. texColor.rgb = SRGBToLinear(texColor.rgb);
  184. o *= texColor;
  185. #endif
  186. #if USE_ALPHA_TEST
  187. if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
  188. #endif
  189. CC_APPLY_FOG(o);
  190. return CCFragOutput(o);
  191. }
  192. }%
  193. CCProgram planar-shadow-vs %{
  194. precision highp float;
  195. #include <legacy/input>
  196. #include <builtin/uniforms/cc-global>
  197. #include <legacy/decode-base>
  198. #include <legacy/local-batch>
  199. #include <builtin/uniforms/cc-shadow>
  200. #include <common/lighting/functions>
  201. out float v_dist;
  202. vec4 vert () {
  203. vec4 position;
  204. CCVertInput(position);
  205. // World Space
  206. mat4 matWorld, matWorldIT;
  207. CCGetWorldMatrixFull(matWorld, matWorldIT);
  208. vec3 worldPos = (matWorld * position).xyz;
  209. vec4 shadowPos = CalculatePlanarShadowPos(worldPos, cc_cameraPos.xyz, cc_mainLitDir.xyz, cc_planarNDInfo);
  210. position = CalculatePlanarShadowClipPos(shadowPos, cc_cameraPos.xyz, cc_matView, cc_matProj, cc_nearFar, cc_shadowWHPBInfo.w);
  211. v_dist = shadowPos.w;
  212. return position;
  213. }
  214. }%
  215. CCProgram planar-shadow-fs %{
  216. precision highp float;
  217. #include <builtin/uniforms/cc-shadow>
  218. #include <legacy/output>
  219. in float v_dist;
  220. vec4 frag () {
  221. if(v_dist < 0.0)
  222. discard;
  223. return CCFragOutput(cc_shadowColor);
  224. }
  225. }%