Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% 初期化
- Pidx = PolygonIdx(p); % p番目のポリゴンのインデックス集合
- %% ポリゴンの内部判定(Pscは頂点のスクリーン座標)
- [in, on] = inpolygon(X, Y, Psc(1, Pidx), Psc(2, Pidx));
- %% UV座標の代入
- Uin = [];
- Vin = [];
- Uin = UV(1,Pidx);
- Vin = UV(2,Pidx);
- %% UV座標の周期境界の計算
- while(any(Uin>1))
- Uin(Uin>1) = Uin(Uin>1) - 1;
- end
- while(any(Vin>1))
- Vin(Vin>1) = Vin(Vin>1) - 1;
- end
- while(any(Uin<0))
- Uin(Uin<0) = Uin(Uin<0) + 1;
- end
- while(any(Vin<0))
- Vin(Vin<0) = Vin(Vin<0) + 1;
- end
- %% UV座標の内挿(Pscは頂点のスクリーン座標)
- fU = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', Uin');
- fV = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', (1-Vin)');
- U = fU(X(in), Y(in));
- V = fV(X(in), Y(in));
- %% デプスの内挿(Pviewは頂点のビュー座標)
- fDepth = scatteredInterpolant(Psc(1, Pidx)', Psc(2, Pidx)', -Pview(3, Pidx)');
- Depth_tmp(in) = fDepth(X(in), Y(in));
- %% デプスを元にマスクを作成
- Mask = Depth > Depth_tmp;
- %% テクスチャフェッチ
- Img_tmp = TextureFetch(Img, in, U, V, Texture, Alpha);
- %% デプスが更新されるところだけ画素値を更新
- ImgR_tmp = Img_tmp(:,:,1);
- ImgG_tmp = Img_tmp(:,:,2);
- ImgB_tmp = Img_tmp(:,:,3);
- ImgR(Mask) = ImgR_tmp(Mask);
- ImgG(Mask) = ImgG_tmp(Mask);
- ImgB(Mask) = ImgB_tmp(Mask);
- Depth(Mask) = Depth_tmp(Mask);
- Img(:,:,1) = ImgR;
- Img(:,:,2) = ImgG;
- Img(:,:,3) = ImgB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement