void LateUpdate() { UpdateKeywords(); // Shader properties float motion = CalculateMotion(Time.deltaTime); _matTunnel.SetFloat(_propFxInner, motion); _matTunnel.SetFloat(_propFxOuter, motion - effectFeather); _matTunnel.SetFloat(_propOverlay, effectOverlay); switch (backgroundMode) { case BackgroundMode.COLOR: _matTunnel.SetColor(_propColor, effectColor); break; case BackgroundMode.CAGE_COLOR: case BackgroundMode.BLUR: case BackgroundMode.CAGE_SKYBOX: case BackgroundMode.SKYBOX: Color bkg = applyColorToBackground ? effectColor : Color.white; bkg.a = effectColor.a; _matTunnel.SetColor(_propColor, bkg); break; } switch (backgroundMode) { case BackgroundMode.SKYBOX: _matTunnel.SetTexture(_propSkybox, effectSkybox); break; case BackgroundMode.CAGE_SKYBOX: _matSkysphere.SetTexture(_propSkybox, effectSkybox); break; } // Update cage objects if necessary if (usingCage && cageUpdateEveryFrame) { UpdateCage(); } if (_lastMaskMode != maskMode) { ResetMaskCommandBuffer(); } if (_lastBlurKernel != blurSamples || !Mathf.Approximately(_lastBlurRadius, blurDistance)) { UpdateBlurKernel(); } bool di = _drawIris; if (_wasDrawingIrisEarly != di) { if (_camHasIrisBuffer && !di) { ToggleIrisCommandBuffer(false); } else if (!_camHasIrisBuffer && di) { ToggleIrisCommandBuffer(true); } _wasDrawingIrisEarly = di; } if (di) { float inner = motion * 0.98f; // Ensure iris is always a little bigger than image effect aperture _matIris.SetFloat(_propFxInner, inner); _matIris.SetFloat(_propFxOuter, inner - effectFeather); } // Check counter-velocity modes bool resetCm = false; if (_lastCvMode != counterVelocityMode) { resetCm = true; _lastCvMode = counterVelocityMode; } if (counterVelocityMode == CounterVelocityMode.REAL) { if (counterVelocityResetTime > 0 && Time.time >= _timeToResetCounterVelocity) { resetCm = true; _timeToResetCounterVelocity = Time.time + counterVelocityResetTime; } if (counterVelocityResetDistance > 0 && _cmPos.sqrMagnitude >= (counterVelocityResetDistance * counterVelocityResetDistance)) { resetCm = true; } } if (resetCm) { ResetCounterMotion(); } // Fog Shader.SetGlobalFloat(_globPropFogDensity, cageFogDensity); Shader.SetGlobalFloat(_globPropFogPower, cageFogPower); Shader.SetGlobalFloat(_globPropFogBlend, cageFogBlend); Shader.SetGlobalColor(_globPropFogColor, effectColor); _hasDrawnThisFrame = false; // Flag for once-per-frame things in Draw }
/// <summary> /// Override some or all settings using a TunnellingPreset asset. /// </summary> public void ApplyPreset(TunnellingPreset p) { ApplyPresetBase(p); if (p.overrideEffectOverlay) { effectOverlay = p.effectOverlay; } if (p.overrideBackgroundMode) { backgroundMode = p.backgroundMode; } if (p.overrideCageDownsample) { cageDownsample = p.cageDownsample; } if (p.overrideCageAntiAliasing) { cageAntiAliasing = p.cageAntiAliasing; } if (p.overrideCageUpdateEveryFrame) { cageUpdateEveryFrame = p.cageUpdateEveryFrame; } if (p.overrideCageFogDensity) { cageFogDensity = p.cageFogDensity; } if (p.overrideCageFogPower) { cageFogPower = p.cageFogPower; } if (p.overrideCageFogBlend) { cageFogBlend = p.cageFogBlend; } if (p.overrideMaskMode) { maskMode = p.maskMode; } if (p.overrideBlurDownsample) { blurDownsample = p.blurDownsample; } if (p.overrideBlurDistance) { blurDistance = p.blurDistance; } if (p.overrideBlurPasses) { blurPasses = p.blurPasses; } if (p.overrideBlurSamples) { blurSamples = p.blurSamples; } if (p.overrideCounterVelocityMode) { counterVelocityMode = p.counterVelocityMode; } if (p.overrideCounterVelocityResetDistance) { counterVelocityResetDistance = p.counterVelocityResetDistance; } if (p.overrideCounterVelocityResetTime) { counterVelocityResetTime = p.counterVelocityResetTime; } if (p.overrideCounterVelocityStrength) { counterVelocityStrength = p.counterVelocityStrength; } if (p.overrideCounterVelocityPerAxis) { counterVelocityPerAxis = p.counterVelocityPerAxis; } if (p.overrideIrisZRejection) { irisZRejection = p.irisZRejection; } }