builtin-reflection-probe-preview.effect 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. migrations: &migs
  10. properties:
  11. mainColor: { formerlySerializedAs: color }
  12. - vert: unlit-vs:vert
  13. frag: unlit-fs:frag
  14. phase: deferred-forward
  15. propertyIndex: 0
  16. migrations: *migs
  17. - name: transparent
  18. passes:
  19. - vert: unlit-vs:vert
  20. frag: unlit-fs:frag
  21. depthStencilState: &d1
  22. depthTest: true
  23. depthWrite: false
  24. blendState: &b1
  25. targets:
  26. - blend: true
  27. blendSrc: src_alpha
  28. blendDst: one_minus_src_alpha
  29. blendDstAlpha: one_minus_src_alpha
  30. properties: *props
  31. migrations: *migs
  32. - vert: unlit-vs:vert
  33. frag: unlit-fs:frag
  34. phase: deferred-forward
  35. depthStencilState: *d1
  36. blendState: *b1
  37. propertyIndex: 0
  38. migrations: *migs
  39. - name: add
  40. passes:
  41. - vert: unlit-vs:vert
  42. frag: unlit-fs:frag
  43. rasterizerState: &r1 { cullMode: none }
  44. depthStencilState: *d1
  45. blendState: &b2
  46. targets:
  47. - blend: true
  48. blendSrc: src_alpha
  49. blendDst: one
  50. blendSrcAlpha: src_alpha
  51. blendDstAlpha: one
  52. properties: *props
  53. migrations: *migs
  54. - vert: unlit-vs:vert
  55. frag: unlit-fs:frag
  56. phase: deferred-forward
  57. depthStencilState: *d1
  58. blendState: *b2
  59. propertyIndex: 0
  60. migrations: *migs
  61. - name: alpha-blend
  62. passes:
  63. - vert: unlit-vs:vert
  64. frag: unlit-fs:frag
  65. rasterizerState: *r1
  66. depthStencilState: *d1
  67. blendState: &b3
  68. targets:
  69. - blend: true
  70. blendSrc: src_alpha
  71. blendDst: one_minus_src_alpha
  72. blendSrcAlpha: src_alpha
  73. blendDstAlpha: one_minus_src_alpha
  74. properties: *props
  75. migrations: *migs
  76. - vert: unlit-vs:vert
  77. frag: unlit-fs:frag
  78. phase: deferred-forward
  79. depthStencilState: *d1
  80. blendState: *b3
  81. propertyIndex: 0
  82. migrations: *migs
  83. }%
  84. CCProgram unlit-vs %{
  85. precision highp float;
  86. #include <legacy/input>
  87. #include <builtin/uniforms/cc-global>
  88. #include <legacy/decode-base>
  89. #include <legacy/local-batch>
  90. #include <legacy/input>
  91. #if CC_USE_REFLECTION_PROBE
  92. out mediump vec4 v_shadowBiasAndProbeId;
  93. #endif
  94. out mediump vec3 v_position;
  95. out mediump vec3 v_normal;
  96. vec4 vert () {
  97. vec4 position;
  98. CCVertInput(position);
  99. mat4 matWorld, matWorldIT;
  100. CCGetWorldMatrixFull(matWorld, matWorldIT);
  101. vec4 pos = matWorld * position;
  102. v_position = pos.xyz;
  103. v_normal = normalize((matWorldIT * vec4(a_normal, 0.0)).xyz);
  104. #if CC_USE_REFLECTION_PROBE
  105. #if USE_INSTANCING
  106. v_shadowBiasAndProbeId.zw = a_localShadowBiasAndProbeId.zw;
  107. #else
  108. v_shadowBiasAndProbeId.zw = cc_localShadowBias.zw;
  109. #endif
  110. #endif
  111. return cc_matProj * (cc_matView * matWorld) * position;
  112. }
  113. }%
  114. CCProgram unlit-fs %{
  115. precision highp float;
  116. #include <builtin/uniforms/cc-reflection-probe>
  117. #include <builtin/uniforms/cc-environment>
  118. #include <common/texture/texture-lod>
  119. #include <legacy/output-standard>
  120. #include <common/data/unpack>
  121. #include <builtin/uniforms/cc-global>
  122. #if CC_USE_REFLECTION_PROBE
  123. in mediump vec4 v_shadowBiasAndProbeId;
  124. #endif
  125. in mediump vec3 v_normal;
  126. in vec3 v_position;
  127. vec4 frag () {
  128. #if CC_USE_REFLECTION_PROBE
  129. if(v_shadowBiasAndProbeId.z < 0.0)
  130. {
  131. return vec4(1.0);
  132. }
  133. #endif
  134. vec3 V = normalize(cc_cameraPos.xyz - v_position);
  135. vec3 N = normalize(v_normal);
  136. vec3 R = normalize(reflect(-V, N));
  137. vec4 probe = fragTextureLod(cc_reflectionProbeCubemap, R, 0.0);
  138. vec4 finalColor = vec4(1.0);
  139. finalColor.rgb = unpackRGBE(probe);
  140. return CCFragOutput(finalColor);
  141. }
  142. }%