effect-removeBlack.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const xrFrameSystem = wx.getXrFrameSystem();
  2. xrFrameSystem.registerEffect('removeBlack', scene => scene.createEffect({
  3. name: "removeBlack",
  4. images: [{
  5. key: 'u_videoMap',
  6. default: 'white',
  7. macro: 'WX_USE_VIDEOMAP'
  8. }],
  9. defaultRenderQueue: 2000,
  10. passes: [{
  11. "renderStates": {
  12. cullOn: false,
  13. blendOn: true,
  14. blendSrc: xrFrameSystem.EBlendFactor.SRC_ALPHA,
  15. blendDst: xrFrameSystem.EBlendFactor.ONE_MINUS_SRC_ALPHA,
  16. cullFace: xrFrameSystem.ECullMode.BACK,
  17. },
  18. lightMode: "ForwardBase",
  19. useMaterialRenderStates: true,
  20. shaders: [0, 1]
  21. }],
  22. shaders: [
  23. `#version 100
  24. uniform highp mat4 u_view;
  25. uniform highp mat4 u_viewInverse;
  26. uniform highp mat4 u_vp;
  27. uniform highp mat4 u_projection;
  28. uniform highp mat4 u_world;
  29. attribute vec3 a_position;
  30. attribute highp vec2 a_texCoord;
  31. varying highp vec2 v_UV;
  32. void main()
  33. {
  34. v_UV = a_texCoord;
  35. vec4 worldPosition = u_world * vec4(a_position, 1.0);
  36. gl_Position = u_projection * u_view * worldPosition;
  37. }`,
  38. `#version 100
  39. precision mediump float;
  40. precision highp int;
  41. varying highp vec2 v_UV;
  42. #ifdef WX_USE_VIDEOMAP
  43. uniform sampler2D u_videoMap;
  44. #endif
  45. void main()
  46. {
  47. #ifdef WX_USE_VIDEOMAP
  48. vec4 baseColor = texture2D(u_videoMap, v_UV);
  49. #else
  50. vec4 baseColor = vec4(1.0, 1.0, 1.0, 1.0);
  51. #endif
  52. float rgbSum = baseColor.r + baseColor.g + baseColor.b;
  53. // 设定阈值避免异常情况
  54. if (rgbSum < 0.1) {
  55. gl_FragData[0] = vec4(1.0, 1.0, 1.0, 0.0);
  56. } else {
  57. gl_FragData[0] = vec4(pow(baseColor.rgb, vec3(2.2)), 1.0);
  58. }
  59. }
  60. `],
  61. }));