6c68ba5e-4590-4a25-bd25-430a0ebc1544 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: standard-vs
  7. frag: standard-fs
  8. properties: &props
  9. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  10. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } }
  11. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  12. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } }
  13. roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  14. metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  15. - &forward-add
  16. vert: standard-vs
  17. frag: standard-fs
  18. phase: forward-add
  19. propertyIndex: 0
  20. embeddedMacros: { CC_FORWARD_ADD: true }
  21. depthStencilState:
  22. depthFunc: equal
  23. depthTest: true
  24. depthWrite: false
  25. blendState:
  26. targets:
  27. - blend: true
  28. blendSrc: one
  29. blendDst: one
  30. blendSrcAlpha: zero
  31. blendDstAlpha: one
  32. - &shadow-caster
  33. vert: shadow-caster-vs
  34. frag: shadow-caster-fs
  35. phase: shadow-caster
  36. propertyIndex: 0
  37. rasterizerState:
  38. cullMode: front
  39. properties:
  40. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
  41. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  42. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  43. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  44. - name: transparent
  45. passes:
  46. - vert: standard-vs
  47. frag: standard-fs
  48. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  49. depthStencilState:
  50. depthTest: true
  51. depthWrite: false
  52. blendState:
  53. targets:
  54. - blend: true
  55. blendSrc: src_alpha
  56. blendDst: one_minus_src_alpha
  57. blendDstAlpha: one_minus_src_alpha
  58. properties: *props
  59. - *forward-add
  60. - *shadow-caster
  61. }%
  62. CCProgram shared-ubos %{
  63. uniform Constants {
  64. vec4 albedo;
  65. vec4 albedoScaleAndCutoff;
  66. vec4 pbrParams;
  67. };
  68. }%
  69. CCProgram macro-remapping %{
  70. // ui displayed macros
  71. #pragma define-meta USE_TWOSIDE
  72. #pragma define-meta USE_VERTEX_COLOR
  73. #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
  74. #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
  75. }%
  76. CCProgram surface-vertex %{
  77. #define CC_SURFACES_VERTEX_MODIFY_WORLD_POS
  78. vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
  79. {
  80. return In.worldPos;
  81. }
  82. #define CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL
  83. vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In)
  84. {
  85. return In.worldNormal.xyz;
  86. }
  87. #define CC_SURFACES_VERTEX_MODIFY_UV
  88. void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In)
  89. {
  90. }
  91. }%
  92. CCProgram surface-fragment %{
  93. #if USE_ALBEDO_MAP
  94. uniform sampler2D albedoMap;
  95. #pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
  96. #endif
  97. #if USE_ALPHA_TEST
  98. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
  99. #endif
  100. #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
  101. vec4 SurfacesFragmentModifyBaseColorAndTransparency()
  102. {
  103. vec4 baseColor = albedo;
  104. #if USE_ALBEDO_MAP
  105. vec4 texColor = texture(albedoMap, ALBEDO_UV);
  106. texColor.rgb = SRGBToLinear(texColor.rgb);
  107. baseColor *= texColor;
  108. #endif
  109. #if USE_ALPHA_TEST
  110. if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
  111. #endif
  112. baseColor.rgb *= albedoScaleAndCutoff.xyz;
  113. return baseColor;
  114. }
  115. #define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
  116. void SurfacesFragmentAlphaClipOnly()
  117. {
  118. #if USE_ALPHA_TEST
  119. float alpha = albedo.ALPHA_TEST_CHANNEL;
  120. #if USE_VERTEX_COLOR
  121. alpha *= FSInput_vertexColor.a;
  122. #endif
  123. #if USE_ALBEDO_MAP
  124. alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL;
  125. #endif
  126. if (alpha < albedoScaleAndCutoff.w) discard;
  127. #endif
  128. }
  129. #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
  130. vec3 SurfacesFragmentModifyWorldNormal()
  131. {
  132. return normalize(FSInput_worldNormal);
  133. }
  134. #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE
  135. vec3 SurfacesFragmentModifyEmissive()
  136. {
  137. return vec3(0.0, 0.0, 0.0);
  138. }
  139. #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
  140. vec4 SurfacesFragmentModifyPBRParams()
  141. {
  142. // ao, roughness, metallic, specularIntensity
  143. return vec4(1.0, pbrParams.y, pbrParams.z, 0.5);
  144. }
  145. }%
  146. CCProgram standard-vs %{
  147. precision highp float;
  148. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  149. #include <macro-remapping>
  150. #include <surfaces/effect-macros/common-macros>
  151. // 2. common include with corresponding shader stage, include before surface functions
  152. #include <surfaces/includes/common-vs>
  153. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  154. // see surfaces/default-functions/xxx.chunk
  155. #include <shared-ubos>
  156. #include <surface-vertex>
  157. // 4. surface include with corresponding shader stage and shading-model (optional)
  158. #include <surfaces/includes/standard-vs>
  159. // 5. shader entry with corresponding shader stage and technique usage/type
  160. #include <shading-entries/main-functions/render-to-scene/vs>
  161. }%
  162. CCProgram shadow-caster-vs %{
  163. precision highp float;
  164. #include <surfaces/effect-macros/render-to-shadowmap>
  165. #include <surfaces/includes/common-vs>
  166. #include <shared-ubos>
  167. #include <surface-vertex>
  168. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  169. }%
  170. CCProgram standard-fs %{
  171. // shading-model : standard
  172. // lighting-model : standard (isotropy / anisotropy pbr)
  173. // shader stage : fs
  174. // technique usage/type : render-to-scene
  175. precision highp float;
  176. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  177. #include <macro-remapping>
  178. #include <surfaces/effect-macros/common-macros>
  179. // 2. common include with corresponding shader stage, include before surface functions
  180. #include <surfaces/includes/common-fs>
  181. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  182. // see surfaces/default-functions/xxx.chunk
  183. #include <shared-ubos>
  184. #include <surface-fragment>
  185. // 4. lighting-model (optional)
  186. #include <lighting-models/includes/standard>
  187. // 5. surface include with corresponding shader stage and shading-model (optional)
  188. #include <surfaces/includes/standard-fs>
  189. // 6. shader entry with corresponding shader stage and technique usage/type
  190. #include <shading-entries/main-functions/render-to-scene/fs>
  191. }%
  192. CCProgram shadow-caster-fs %{
  193. precision highp float;
  194. #include <surfaces/effect-macros/render-to-shadowmap>
  195. #include <surfaces/includes/common-fs>
  196. #include <shared-ubos>
  197. #include <surface-fragment>
  198. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  199. }%