public void Deactivate(XPerObjRenderer client) { mClientList.Remove(client); if (mClientList.Count == 0) { enabled = false; } }
void RenderOneClient(RenderTexture source, RenderTexture destination, XPerObjRenderer client) { if (client.MyType == XPerObjRenderer.EType.OutlineGlow || client.MyType == XPerObjRenderer.EType.Glow) { OnRenderOutlineGlow(source, destination, client); } else if (client.MyType == XPerObjRenderer.EType.Shine) { } }
void DownSample4x(RenderTexture source, RenderTexture dest, XPerObjRenderer client) { float off = 1.0f * client.BlurSpread; Graphics.BlitMultiTap(source, dest, mBMat, new Vector2(-off, -off), new Vector2(-off, off), new Vector2(off, off), new Vector2(off, -off) ); }
void FourTapCone(RenderTexture source, RenderTexture dest, int iteration, XPerObjRenderer client) { float off = 0.5f + iteration * client.BlurSpread; Graphics.BlitMultiTap(source, dest, mBMat, new Vector2(-off, -off), new Vector2(-off, off), new Vector2(off, off), new Vector2(off, -off) ); }
public void Activate(XPerObjRenderer client) { InitMaterials(); enabled = true; if (mClientList.Contains(client)) { Debug.LogWarning("XPerObjRenderer, can't add the same client twice, please check it!"); return; } mClientList.Add(client); }
void OnRenderOutlineGlow(RenderTexture source, RenderTexture destination, XPerObjRenderer client) { //setup second camera TempCamera.renderingPath = RenderingPath.VertexLit; TempCamera.transform.position = GetComponent <Camera>().transform.position; TempCamera.transform.rotation = GetComponent <Camera>().transform.rotation; TempCamera.fieldOfView = GetComponent <Camera>().fieldOfView; TempCamera.nearClipPlane = GetComponent <Camera>().nearClipPlane; TempCamera.farClipPlane = GetComponent <Camera>().farClipPlane; TempCamera.backgroundColor = Color.black; TempCamera.clearFlags = CameraClearFlags.SolidColor; TempCamera.cullingMask = 1 << client.SecondCameraLayer; TempCamera.hdr = false; TempCamera.depthTextureMode = DepthTextureMode.None; //IMPORTANT, OR CHANGES TO SCENE WINDOW CAUSES EDITOR CRASH, WHY? TempCamera.enabled = false; RenderTexture tempTex = RenderTexture.GetTemporary(source.width, source.height, 0); TempCamera.targetTexture = tempTex; client.SetLayer(client.SecondCameraLayer); TempCamera.RenderWithShader(WhitePassShader, ""); client.ResetLayer(); client.BlurSteps = Mathf.Clamp(client.BlurSteps, 1, 6); client.BlurSpread = Mathf.Clamp(client.BlurSpread, 0, 1.5f); //Blur int sampling = 2; RenderTexture buffer = RenderTexture.GetTemporary(source.width / sampling, source.height / sampling, 0); RenderTexture buffer2 = RenderTexture.GetTemporary(source.width / sampling, source.height / sampling, 0); // Copy source to the 4x4 smaller texture. DownSample4x(tempTex, buffer, client); // Blur the small texture bool oddEven = true; for (int i = 0; i < client.BlurSteps; i++) { if (oddEven) { FourTapCone(buffer, buffer2, i, client); } else { FourTapCone(buffer2, buffer, i, client); } oddEven = !oddEven; } mMat.SetTexture("_WhiteTex", tempTex); mMat.SetColor("_OutlineColor", client.CurrentColor); mMat.SetFloat("_Mult", client.OutlineStrength); if (oddEven) { mMat.SetTexture("_BlurTex", buffer); } else { mMat.SetTexture("_BlurTex", buffer2); } if (client.MyType == XPerObjRenderer.EType.OutlineGlow) { mMat.SetFloat("_Strength", client.OutlineStrength); Graphics.Blit(source, destination, mMat, 0); } else { mMat.SetFloat("_Strength", client.GlowStrength); Graphics.Blit(source, destination, mMat, 1); } RenderTexture.ReleaseTemporary(buffer); RenderTexture.ReleaseTemporary(buffer2); RenderTexture.ReleaseTemporary(tempTex); }