지우개 도구처럼 만들려고합니다. 사용자가 손가락을 텍스처로 드래그하면 해당 위치에서 텍스처가 투명 해집니다. 나는 아래의 코드를 사용하여 이것을 시도했다. (나는 온라인 예제를 발견하고 조금 수정했다.)하지만 너무 느리다. 배경 텍스처를 그릴 때 브러쉬 텍스처를 사용하고 있습니다.이 문제의 또 다른 해결책이 있습니까? 어쩌면 일부 셰이더를 사용하면 더 빨라지 겠지만 어떻게해야할지 모르겠다. 어떤 도움Unity3d -이 코드가 iPhone에서 너무 느립니다.
void Start()
{
stencilUV = new Color[stencil.width * stencil.height];
tex = (Texture2D)Instantiate(paintMaterial.mainTexture);
}
void Update()
{
RaycastHit hit;
if (Input.touchCount == 0) return;
//if (!Input.GetMouseButton(0)) return;
if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
{
pixelUV = hit.textureCoord;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;
CreateStencil((int)pixelUV.x, (int)pixelUV.y, stencil);
}
}
void CreateStencil(int x, int y, Texture2D texture)
{
paintMaterial.mainTexture = tex;
for (int xPix = 0; xPix<texture.width; xPix++)
{
for (int yPix=0;yPix<texture.height; yPix++)
{
stencilUV[i] = tex.GetPixel((x - texture.width/2) + xPix,
(y - texture.height/2) + yPix);
stencilUV[i].a = 0;//1-color.a;
i++;
}
}
i=0;
tex.SetPixels(x-texture.width/2, y-texture.height/2, texture.width, texture.height, stencilUV);
tex.Apply();
}