void SetTriggerTexPixel(Camera camera, ProjectorEyeTexture tex, Vector3 point, int triggerID) { Vector3 screenPoint = camera.WorldToScreenPoint(point); Texture texture = (Texture)tex.GetTexture(); int x = (int)((screenPoint.x / camera.pixelWidth) * texture.width); int y = (int)((screenPoint.y / camera.pixelHeight) * texture.height); if (x < 0.0f || y < 0.0f || x >= texture.width || y >= texture.height) { return; } Color pixelColor; if (!tex.RenderTextureSupported()) { pixelColor = ((Texture2D)texture).GetPixel(x, y); _textureRead.SetPixel(triggerID, 0, pixelColor); } else { RenderTexture.active = tex.GetRenderTexture(); _textureRead.ReadPixels(new Rect(x, y, 1, 1), triggerID, 0, false); } }
void CreateProjectorEyeTexture(bool shadow, bool light) { if (shadow) { if (_Tex != null) { _Tex.CleanUp(); } _Tex = new ProjectorEyeTexture(_ProjectorCamera, _ShadowResolutions[_GlobalShadowResolution]); _ProjectorMaterialShadow.SetTexture("_ShadowTex", _Tex.GetTexture()); } if (light) { if (_TexLight != null) { _TexLight.CleanUp(); } _TexLight = new ProjectorEyeTexture(_ProjectorCameraLight, _ShadowResolutions[_GlobalShadowResolution]); _ProjectorMaterialLight.SetTexture("_ShadowTex", _TexLight.GetTexture()); } }