private void BlurFog(RenderTexture fogTarget1, RenderTexture fogTarget2) { if (!m_BlurEnabled) { return; } ApplyBlurMaterial.SetFloat(ShaderIDs.BlurDepthFalloff, m_BlurDepthFallOff); Vector4 blurOffsets = new Vector4(0, m_BlurOffsets.x, m_BlurOffsets.y, m_BlurOffsets.z); ApplyBlurMaterial.SetVector(ShaderIDs.BlurOffsets, blurOffsets); Vector4 blurWeights = new Vector4(m_BlurWeights.x + m_BlurWeights.y + m_BlurWeights.z, m_BlurWeights.x, m_BlurWeights.y, m_BlurWeights.z); ApplyBlurMaterial.SetVector(ShaderIDs.BlurWeights, blurWeights); for (int i = 0; i < m_BlurIterations; ++i) { ApplyBlurMaterial.SetVector(ShaderIDs.BlurDir, new Vector2(0, 1)); Graphics.Blit(fogTarget1, fogTarget2, ApplyBlurMaterial); ApplyBlurMaterial.SetVector(ShaderIDs.BlurDir, new Vector2(1, 0)); Graphics.Blit(fogTarget1, fogTarget2, ApplyBlurMaterial); } }
private void BlurFog(RenderTexture fogTarget1, RenderTexture fogTarget2) { if (!_BlurEnabled) { return; } ApplyBlurMaterial.SetFloat("_BlurDepthFalloff", _BlurDepthFalloff); var BlurOffsets = new Vector4(0, // initial sample is always at the center _BlurOffsets.x, _BlurOffsets.y, _BlurOffsets.z); ApplyBlurMaterial.SetVector("_BlurOffsets", BlurOffsets); // x is sum of all weights var BlurWeightsWithTotal = new Vector4(_BlurWeights.x + _BlurWeights.y + _BlurWeights.z, _BlurWeights.x, _BlurWeights.y, _BlurWeights.z); ApplyBlurMaterial.SetVector("_BlurWeights", BlurWeightsWithTotal); for (var i = 0; i < _BlurIterations; i++) { // vertical blur ApplyBlurMaterial.SetVector("BlurDir", new Vector2(0, 1)); Graphics.Blit(fogTarget1, fogTarget2, ApplyBlurMaterial); // horizontal blur ApplyBlurMaterial.SetVector("BlurDir", new Vector2(1, 0)); Graphics.Blit(fogTarget2, fogTarget1, ApplyBlurMaterial); } }