houseShader.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. export default {
  2. attributes: ['uv', 'position'],
  3. uniforms: ['view', 'projection', 'world',
  4. 'isYUV', 'focal_width_height', 'texture_video'],
  5. defines: ["#define SHADOWFULLFLOAT", "#define NUM_BONE_INFLUENCERS 0", "#define NUM_MORPH_INFLUENCERS 0"],
  6. samplers: ['shadowSampler', 'texture_video'],
  7. vertex:
  8. `
  9. precision highp float;
  10. varying vec3 ModelPos;
  11. attribute vec2 uv;
  12. attribute vec3 position;
  13. uniform mat4 view;
  14. uniform mat4 projection;
  15. uniform mat4 world;
  16. void main()
  17. {
  18. ModelPos = vec3( view * world * vec4(position , 1.0));
  19. gl_Position = projection * view * world * vec4(position , 1.0);
  20. }
  21. `,
  22. fragment: `
  23. precision highp float;
  24. varying vec3 ModelPos;
  25. uniform float isYUV; // false: 0, true: 1.0
  26. uniform sampler2D texture_video;
  27. uniform vec3 focal_width_height;
  28. vec2 SampleTex(vec3 pt3d)
  29. {
  30. return focal_width_height.x / focal_width_height.yz * pt3d.xy / pt3d.z + 0.5;
  31. }
  32. void main()
  33. {
  34. vec3 color = vec3(0,0,0);
  35. float shadow = 1.0;
  36. vec2 uv = SampleTex( normalize(ModelPos) );
  37. if( isYUV < 0.5 )
  38. {
  39. color = texture2D(texture_video, uv).rgb;
  40. }else{
  41. const mat4 YUV2RGB = mat4
  42. (
  43. 1.1643828125, 0, 1.59602734375, -.87078515625,
  44. 1.1643828125, -.39176171875, -.81296875, .52959375,
  45. 1.1643828125, 2.017234375, 0, -1.081390625,
  46. 0, 0, 0, 1
  47. );
  48. vec4 result = vec4(
  49. texture2D( texture_video, vec2( uv.x, uv.y * 0.666666 + 0.333333 ) ).x,
  50. texture2D( texture_video, vec2( uv.x * 0.5, uv.y * 0.333333 ) ).x,
  51. texture2D( texture_video, vec2( 0.5 + uv.x * 0.5, uv.y * 0.333333 ) ).x,
  52. 1
  53. ) * YUV2RGB;
  54. color = clamp(result.rgb, 0.0, 1.0);
  55. }
  56. if( uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 )
  57. {
  58. color = vec3(0,0,0);
  59. }
  60. gl_FragColor = vec4(shadow * color * 1.0, 1.0);
  61. }
  62. `
  63. }