private void GaussianBlur(POSTFX_GAUSSIAN_BLUR_DIRECTION dir, POSTFX_GUASSIAN_BLUR_MODE mode, RenderTexture src, RenderTexture dst, float sigma, float ramp = 1.0f) { _GaussianBlurMaterial.SetVector("_BlurKernel", GenerateGaussianBlurKernel(mode, sigma)); if (dir == POSTFX_GAUSSIAN_BLUR_DIRECTION.HORIZONTAL) { _GaussianBlurMaterial.SetVector("_StepSize", new Vector2(_GBlurModifier / src.width, 0.0f)); } else { _GaussianBlurMaterial.SetVector("_StepSize", new Vector2(0.0f, _GBlurModifier / src.height)); } if (mode == POSTFX_GUASSIAN_BLUR_MODE.TAP_7_RAMP || mode == POSTFX_GUASSIAN_BLUR_MODE.TAP_3_RAMP) { _GaussianBlurMaterial.SetFloat("_Ramp", ramp); } Graphics.Blit(src, dst, _GaussianBlurMaterial, (int)mode); }
private static Vector4 GenerateGaussianBlurKernel(POSTFX_GUASSIAN_BLUR_MODE mode, float sigma) { float lowEndFake = 1.0f; if (GameFlowControlManager.Instance == null || GameFlowControlManager.Instance.m_StateMachine == null) { } else { PerformanceInfo.ePOSTFX_QUALITY fxquality = PerformanceManager.Instance.PerformanceInfo.EnvironmentInfoForScene(GameFlowControlManager.Instance.m_StateMachine.ActiveStateName).postFXQuality; if (fxquality == PerformanceInfo.ePOSTFX_QUALITY.Medium) { lowEndFake *= 1.8f; } } sigma *= lowEndFake; // any questions about the fake values in rendersettings,find hank. Vector4 res = Vector4.zero; if (mode == POSTFX_GUASSIAN_BLUR_MODE.TAP_3 || mode == POSTFX_GUASSIAN_BLUR_MODE.TAP_3_RAMP) { res.x = Mathf.Exp(-0.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); res.y = Mathf.Exp(-1.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); float t = res.y + res.x + res.y; res /= t; } else { res.x = Mathf.Exp(-0.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); res.y = Mathf.Exp(-1.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); res.z = Mathf.Exp(-4.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); res.w = Mathf.Exp(-9.0f / (2.0f * sigma * sigma)) / (2.0f * Mathf.PI * sigma * sigma); float t = res.w + res.z + res.y + res.x + res.y + res.z + res.w; res /= t; } return(res); }