public void Setup(Camera myCam, RenderTargetIdentifier source, UnityEngine.Rendering.Universal.RenderTargetHandle destination, Transform lightSource, Color treshold, Color clr) { this.myCam = myCam; this.source = source; this.destination = destination; this.lightSource = lightSource; this.treshold = treshold; this.clr = clr; }
public void Setup(Camera myCam, RenderTargetIdentifier source, UnityEngine.Rendering.Universal.RenderTargetHandle destination) { this.myCam = myCam; this.source = source; this.destination = destination; }
void RenderLightShaft(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, RenderTexture source, RenderTargetIdentifier src, UnityEngine.Rendering.Universal.RenderTargetHandle destination, Material mat, Material clearMat, Transform lightSource, Color treshold, Color clr) { int divider = 4; if (EnviroSkyMgr.instance.LightShaftsSettings.resolution == EnviroPostProcessing.SunShaftsResolution.Normal) { divider = 2; } else if (EnviroSkyMgr.instance.LightShaftsSettings.resolution == EnviroPostProcessing.SunShaftsResolution.High) { divider = 1; } Vector3 v = Vector3.one * 0.5f; if (lightSource) { v = myCam.WorldToViewportPoint(lightSource.position); } else { v = new Vector3(0.5f, 0.5f, 0.0f); } int rtW = source.width / divider; int rtH = source.height / divider; RenderTextureDescriptor textureDescriptor = source.descriptor; textureDescriptor.width = rtW; textureDescriptor.height = rtH; RenderTexture lrColorB; RenderTexture lrDepthBuffer; // VR Usage lrDepthBuffer = RenderTexture.GetTemporary(textureDescriptor); // mask out everything except the skybox // we have 2 methods, one of which requires depth buffer support, the other one is just comparing images mat.SetVector("_BlurRadius4", new Vector4(1.0f, 1.0f, 0.0f, 0.0f) * EnviroSkyMgr.instance.LightShaftsSettings.blurRadius); mat.SetVector("_SunPosition", new Vector4(v.x, v.y, v.z, EnviroSkyMgr.instance.LightShaftsSettings.maxRadius)); mat.SetVector("_SunThreshold", treshold); Graphics.Blit(source, lrDepthBuffer, mat, 2); // paint a small black small border to get rid of clamping problems if (myCam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Mono) { DrawBorder(lrDepthBuffer, clearMat); } // radial blur: radialBlurIterations = Mathf.Clamp(radialBlurIterations, 1, 4); float ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (1.0f / 768.0f); mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f)); mat.SetVector("_SunPosition", new Vector4(v.x, v.y, v.z, EnviroSkyMgr.instance.LightShaftsSettings.maxRadius)); for (int it2 = 0; it2 < radialBlurIterations; it2++) { // each iteration takes 2 * 6 samples // we update _BlurRadius each time to cheaply get a very smooth look // VR USAGE lrColorB = RenderTexture.GetTemporary(textureDescriptor); Graphics.Blit(lrDepthBuffer, lrColorB, mat, 1); RenderTexture.ReleaseTemporary(lrDepthBuffer); ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (((it2 * 2.0f + 1.0f) * 6.0f)) / 768.0f; mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f)); // VR USAGE lrDepthBuffer = RenderTexture.GetTemporary(textureDescriptor); Graphics.Blit(lrColorB, lrDepthBuffer, mat, 1); RenderTexture.ReleaseTemporary(lrColorB); ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (((it2 * 2.0f + 2.0f) * 6.0f)) / 768.0f; mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f)); } // put together: if (v.z >= 0.0f) { mat.SetVector("_SunColor", new Vector4(clr.r, clr.g, clr.b, clr.a) * EnviroSkyMgr.instance.LightShaftsSettings.intensity); } else { mat.SetVector("_SunColor", Vector4.zero); // no backprojection ! } mat.SetTexture("_ColorBuffer", lrDepthBuffer); //FINAL // Graphics.Blit(source, destination, mat, (EnviroSkyMgr.instance.LightShaftsSettings.screenBlendMode == EnviroPostProcessing.ShaftsScreenBlendMode.Screen) ? 0 : 4); blitPassFinal.Setup(src, destination); renderer.EnqueuePass(blitPassFinal); RenderTexture.ReleaseTemporary(lrDepthBuffer); }
/// <summary> /// Configure the pass with the source and destination to execute on. /// </summary> /// <param name="source">Source Render Target</param> /// <param name="destination">Destination Render Target</param> public void Setup(RenderTargetIdentifier source, UnityEngine.Rendering.Universal.RenderTargetHandle destination, RenderTexture setTexTo) { this.source = source; this.destination = destination; this.setMainTexTo = setTexTo; }