Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. %% 初期化
  2. Pidx = PolygonIdx(p); % p番目のポリゴンのインデックス集合
  3.  
  4. %% ポリゴンの内部判定(Pscは頂点のスクリーン座標)
  5. [in, on] = inpolygon(X, Y, Psc(1, Pidx), Psc(2, Pidx));
  6.  
  7. %% UV座標の代入
  8. Uin = [];
  9. Vin = [];
  10. Uin = UV(1,Pidx);
  11. Vin = UV(2,Pidx);
  12.  
  13. %% UV座標の周期境界の計算
  14. while(any(Uin>1))
  15. Uin(Uin>1) = Uin(Uin>1) - 1;
  16. end
  17. while(any(Vin>1))
  18. Vin(Vin>1) = Vin(Vin>1) - 1;
  19. end
  20. while(any(Uin<0))
  21. Uin(Uin<0) = Uin(Uin<0) + 1;
  22. end
  23. while(any(Vin<0))
  24. Vin(Vin<0) = Vin(Vin<0) + 1;
  25. end
  26.  
  27. %% UV座標の内挿(Pscは頂点のスクリーン座標)
  28. fU = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', Uin');
  29. fV = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', (1-Vin)');
  30. U = fU(X(in), Y(in));
  31. V = fV(X(in), Y(in));
  32.  
  33. %% デプスの内挿(Pviewは頂点のビュー座標)
  34. fDepth = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', -Pview(3, Pidx)');
  35. Depth_tmp(in) = fDepth(X(in), Y(in));
  36.  
  37. %% デプスを元にマスクを作成
  38. Mask = Depth > Depth_tmp;
  39.  
  40. %% テクスチャフェッチ
  41. Img_tmp = TextureFetch(Img, in, U, V, Texture, Alpha);
  42.  
  43. %% デプスが更新されるところだけ画素値を更新
  44. ImgR_tmp = Img_tmp(:,:,1);
  45. ImgG_tmp = Img_tmp(:,:,2);
  46. ImgB_tmp = Img_tmp(:,:,3);
  47. ImgR(Mask) = ImgR_tmp(Mask);
  48. ImgG(Mask) = ImgG_tmp(Mask);
  49. ImgB(Mask) = ImgB_tmp(Mask);
  50. Depth(Mask) = Depth_tmp(Mask);
  51. Img(:,:,1) = ImgR;
  52. Img(:,:,2) = ImgG;
  53. Img(:,:,3) = ImgB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement