void OnValidate() { if (Application.isPlaying) { ApplyGammaCorrectionValues(); } else { EyeTextureData.ResetGlobalShaderValues(); } }
private void updateGlobalShaderProperties(EyeTextureData eyeTextureData) { Shader.SetGlobalTexture("_LeapGlobalTexture", eyeTextureData.mainTexture); Shader.SetGlobalTexture("_LeapGlobalDistortion", eyeTextureData.distortion); Vector4 projection = new Vector4(); projection.x = _cachedCamera.projectionMatrix[0, 2]; projection.y = 0f; projection.z = _cachedCamera.projectionMatrix[0, 0]; projection.w = _cachedCamera.projectionMatrix[1, 1]; Shader.SetGlobalVector("_LeapGlobalProjection", projection); Shader.SetGlobalFloat("_LeapGlobalGammaCorrectionExponent", 1.0f / gammaCorrection); // Set camera parameters Shader.SetGlobalFloat("_LeapGlobalVirtualCameraV", _cachedCamera.fieldOfView); Shader.SetGlobalFloat("_LeapGlobalVirtualCameraH", Mathf.Rad2Deg * Mathf.Atan(Mathf.Tan(Mathf.Deg2Rad * _cachedCamera.fieldOfView / 2f) * _cachedCamera.aspect) * 2f); Shader.SetGlobalMatrix("_LeapGlobalInverseView", _cachedCamera.worldToCameraMatrix.inverse); }
void Start() { if (HandController.Main == null) { Debug.LogWarning("Could not find Main Hand Controller. Cannot use LeapImageRetriever if there is no Main Hand Controller!"); enabled = false; return; } float gamma = 1f; if (QualitySettings.activeColorSpace != ColorSpace.Linear) { gamma = -Mathf.Log10(Mathf.GammaToLinearSpace(0.1f)); } Shader.SetGlobalFloat("_LeapGlobalColorSpaceGamma", gamma); _eyeTextureData[0] = new EyeTextureData(); _eyeTextureData[1] = new EyeTextureData(); _cachedCamera = GetComponent<Camera>(); _controller = HandController.Main.GetLeapController(); _controller.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES); }
private void resetGlobalShaderVariants(EyeTextureData eyeTextureData) { switch (eyeTextureData.formatType) { case Image.FormatType.INFRARED: Shader.DisableKeyword(RGB_SHADER_VARIANT_NAME); Shader.EnableKeyword(IR_SHADER_VARIANT_NAME); break; case (Image.FormatType)4: Shader.DisableKeyword(IR_SHADER_VARIANT_NAME); Shader.EnableKeyword(RGB_SHADER_VARIANT_NAME); break; default: Debug.LogWarning("Unexpected format type " + eyeTextureData.formatType); break; } }
private void ensureMainTextureUpdated(Image image, EyeTextureData textureData) { int width = image.Width; int height = image.Height; if (textureData.mainTexture == null || textureData.mainTexture.width != width || textureData.mainTexture.height != height) { TextureFormat format = getTextureFormat(image); if (textureData.mainTexture != null) { DestroyImmediate(textureData.mainTexture); } textureData.mainTexture = new Texture2D(image.Width, image.Height, format, false, true); textureData.mainTexture.wrapMode = TextureWrapMode.Clamp; textureData.mainTexture.filterMode = FilterMode.Bilinear; textureData.formatType = image.Format; _mainTextureIntermediateArray = new byte[width * height * bytesPerPixel(format)]; _forceDistortionRecalc = true; resetGlobalShaderVariants(textureData); } Marshal.Copy(image.DataPointer(), _mainTextureIntermediateArray, 0, _mainTextureIntermediateArray.Length); textureData.mainTexture.LoadRawTextureData(_mainTextureIntermediateArray); textureData.mainTexture.Apply(); }
private void ensureDistortionUpdated(Image image, EyeTextureData textureData) { int width = image.DistortionWidth / 2; int height = image.DistortionHeight; if (textureData.distortion == null || textureData.distortion.width != width || textureData.distortion.height != height || textureData.formatType != image.Format) { if (textureData.distortion != null) { DestroyImmediate(textureData.distortion); } _distortionIntermediateArray = new Color32[width * height]; textureData.distortion = new Texture2D(width, height, TextureFormat.RGBA32, false, true); textureData.distortion.wrapMode = TextureWrapMode.Clamp; textureData.formatType = image.Format; _forceDistortionRecalc = true; } if (_forceDistortionRecalc) { float[] distortionData = image.Distortion; // Move distortion data to distortion texture for (int i = 0; i < distortionData.Length; i += 2) { byte b0, b1, b2, b3; encodeFloat(distortionData[i], out b0, out b1); encodeFloat(distortionData[i + 1], out b2, out b3); _distortionIntermediateArray[i / 2] = new Color32(b0, b1, b2, b3); } textureData.distortion.SetPixels32(_distortionIntermediateArray); textureData.distortion.Apply(); } }