private void CommandBuffer_Rebuild(AmplifyOcclusionBase.TargetDesc target) { bool flag = this.PerPixelNormals == AmplifyOcclusionBase.PerPixelNormalSource.GBuffer || this.PerPixelNormals == AmplifyOcclusionBase.PerPixelNormalSource.GBufferOctaEncoded; CameraEvent cameraEvent = (!flag) ? CameraEvent.BeforeImageEffectsOpaque : CameraEvent.AfterLighting; if (this.ApplyMethod == AmplifyOcclusionBase.ApplicationMethod.Debug) { CommandBuffer cb = this.CommandBuffer_AllocateRegister(cameraEvent); this.CommandBuffer_FillComputeOcclusion(cb, target); this.CommandBuffer_FillApplyDebug(cb, target); } else { bool logTarget = !this.m_camera.allowHDR && flag; cameraEvent = ((this.ApplyMethod != AmplifyOcclusionBase.ApplicationMethod.Deferred) ? cameraEvent : CameraEvent.BeforeReflections); CommandBuffer cb = this.CommandBuffer_AllocateRegister(cameraEvent); this.CommandBuffer_FillComputeOcclusion(cb, target); if (this.ApplyMethod == AmplifyOcclusionBase.ApplicationMethod.PostEffect) { this.CommandBuffer_FillApplyPostEffect(cb, target, logTarget); } else if (this.ApplyMethod == AmplifyOcclusionBase.ApplicationMethod.Deferred) { this.CommandBuffer_FillApplyDeferred(cb, target, logTarget); } } }
private void CommandBuffer_FillApplyDebug(CommandBuffer cb, AmplifyOcclusionBase.TargetDesc target) { cb.SetGlobalTexture("_AO_OcclusionTexture", this.m_occlusionRT); this.SetBlitTarget(cb, BuiltinRenderTextureType.CameraTarget, target.fullWidth, target.fullHeight); this.PerformBlit(cb, this.m_occlusionMat, 36); cb.SetRenderTarget(null); }
private void CommandBuffer_FillApplyDeferred(CommandBuffer cb, AmplifyOcclusionBase.TargetDesc target, bool logTarget) { cb.SetGlobalTexture("_AO_OcclusionTexture", this.m_occlusionRT); this.m_applyDeferredTargets[0] = BuiltinRenderTextureType.GBuffer0; this.m_applyDeferredTargets[1] = ((!logTarget) ? BuiltinRenderTextureType.CameraTarget : BuiltinRenderTextureType.GBuffer3); if (!logTarget) { this.SetBlitTarget(cb, this.m_applyDeferredTargets, target.fullWidth, target.fullHeight); this.PerformBlit(cb, this.m_occlusionMat, 37); } else { int num = this.SafeAllocateTemporaryRT(cb, "_AO_GBufferAlbedo", target.fullWidth, target.fullHeight, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, FilterMode.Point); int num2 = this.SafeAllocateTemporaryRT(cb, "_AO_GBufferEmission", target.fullWidth, target.fullHeight, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, FilterMode.Point); cb.Blit(this.m_applyDeferredTargets[0], num); cb.Blit(this.m_applyDeferredTargets[1], num2); cb.SetGlobalTexture("_AO_GBufferAlbedo", num); cb.SetGlobalTexture("_AO_GBufferEmission", num2); this.SetBlitTarget(cb, this.m_applyDeferredTargets, target.fullWidth, target.fullHeight); this.PerformBlit(cb, this.m_occlusionMat, 38); this.SafeReleaseTemporaryRT(cb, num); this.SafeReleaseTemporaryRT(cb, num2); } cb.SetRenderTarget(null); }
private void UpdateGlobalShaderConstants(AmplifyOcclusionBase.TargetDesc target) { float num = this.m_camera.fieldOfView * 0.0174532924f; Vector2 vector = new Vector2(1f / Mathf.Tan(num * 0.5f) * ((float)target.height / (float)target.width), 1f / Mathf.Tan(num * 0.5f)); Vector2 vector2 = new Vector2(1f / vector.x, 1f / vector.y); float num2; if (this.m_camera.orthographic) { num2 = (float)target.height / this.m_camera.orthographicSize; } else { num2 = (float)target.height / (Mathf.Tan(num * 0.5f) * 2f); } float num3 = Mathf.Clamp(this.Bias, 0f, 1f); this.FadeStart = Mathf.Max(0f, this.FadeStart); this.FadeLength = Mathf.Max(0.01f, this.FadeLength); float y = (!this.FadeEnabled) ? 0f : (1f / this.FadeLength); Shader.SetGlobalMatrix("_AO_CameraProj", GL.GetGPUProjectionMatrix(Matrix4x4.Ortho(0f, 1f, 0f, 1f, -1f, 100f), false)); Shader.SetGlobalMatrix("_AO_CameraView", this.m_camera.worldToCameraMatrix); Shader.SetGlobalVector("_AO_UVToView", new Vector4(2f * vector2.x, -2f * vector2.y, -1f * vector2.x, 1f * vector2.y)); Shader.SetGlobalFloat("_AO_HalfProjScale", 0.5f * num2); Shader.SetGlobalFloat("_AO_Radius", this.Radius); Shader.SetGlobalFloat("_AO_PowExponent", this.PowerExponent); Shader.SetGlobalFloat("_AO_Bias", num3); Shader.SetGlobalFloat("_AO_Multiplier", 1f / (1f - num3)); Shader.SetGlobalFloat("_AO_BlurSharpness", this.BlurSharpness); Shader.SetGlobalColor("_AO_Levels", new Color(this.Tint.r, this.Tint.g, this.Tint.b, this.Intensity)); Shader.SetGlobalVector("_AO_FadeParams", new Vector2(this.FadeStart, y)); Shader.SetGlobalVector("_AO_FadeValues", new Vector3(this.FadeToIntensity, this.FadeToRadius, this.FadeToPowerExponent)); }
private void CommandBuffer_FillApplyPostEffect(CommandBuffer cb, AmplifyOcclusionBase.TargetDesc target, bool logTarget) { cb.SetGlobalTexture("_AO_OcclusionTexture", this.m_occlusionRT); if (!logTarget) { this.SetBlitTarget(cb, BuiltinRenderTextureType.CameraTarget, target.fullWidth, target.fullHeight); this.PerformBlit(cb, this.m_occlusionMat, 39); } else { int num = this.SafeAllocateTemporaryRT(cb, "_AO_GBufferEmission", target.fullWidth, target.fullHeight, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, FilterMode.Point); cb.Blit(BuiltinRenderTextureType.GBuffer3, num); cb.SetGlobalTexture("_AO_GBufferEmission", num); this.SetBlitTarget(cb, BuiltinRenderTextureType.GBuffer3, target.fullWidth, target.fullHeight); this.PerformBlit(cb, this.m_occlusionMat, 40); this.SafeReleaseTemporaryRT(cb, num); } cb.SetRenderTarget(null); }
private void CommandBuffer_FillComputeOcclusion(CommandBuffer cb, AmplifyOcclusionBase.TargetDesc target) { this.CheckMaterial(); this.CheckRandomData(); cb.SetGlobalVector("_AO_Buffer_PadScale", new Vector4(target.padRatioWidth, target.padRatioHeight, 1f / target.padRatioWidth, 1f / target.padRatioHeight)); cb.SetGlobalVector("_AO_Buffer_TexelSize", new Vector4(1f / (float)target.width, 1f / (float)target.height, (float)target.width, (float)target.height)); cb.SetGlobalVector("_AO_QuarterBuffer_TexelSize", new Vector4(1f / (float)target.quarterWidth, 1f / (float)target.quarterHeight, (float)target.quarterWidth, (float)target.quarterHeight)); cb.SetGlobalFloat("_AO_MaxRadiusPixels", (float)Mathf.Min(target.width, target.height)); if (this.m_occlusionRT == null || this.m_occlusionRT.width != target.width || this.m_occlusionRT.height != target.height || !this.m_occlusionRT.IsCreated()) { this.SafeReleaseRT(ref this.m_occlusionRT); this.m_occlusionRT = this.SafeAllocateRT("_AO_OcclusionTexture", target.width, target.height, this.m_occlusionRTFormat, RenderTextureReadWrite.Linear); } int num = -1; if (this.Downsample) { num = this.SafeAllocateTemporaryRT(cb, "_AO_SmallOcclusionTexture", target.width / 2, target.height / 2, this.m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Bilinear); } if (this.CacheAware && !this.Downsample) { int num2 = this.SafeAllocateTemporaryRT(cb, "_AO_OcclusionAtlas", target.width, target.height, this.m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Point); for (int i = 0; i < 16; i++) { this.m_depthLayerRT[i] = this.SafeAllocateTemporaryRT(cb, this.m_layerDepthNames[i], target.quarterWidth, target.quarterHeight, this.m_depthRTFormat, RenderTextureReadWrite.Linear, FilterMode.Point); this.m_normalLayerRT[i] = this.SafeAllocateTemporaryRT(cb, this.m_layerNormalNames[i], target.quarterWidth, target.quarterHeight, this.m_normalRTFormat, RenderTextureReadWrite.Linear, FilterMode.Point); this.m_occlusionLayerRT[i] = this.SafeAllocateTemporaryRT(cb, this.m_layerOcclusionNames[i], target.quarterWidth, target.quarterHeight, this.m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Point); } for (int j = 0; j < 16; j += this.m_mrtCount) { for (int k = 0; k < this.m_mrtCount; k++) { int num3 = k + j; int num4 = num3 & 3; int num5 = num3 >> 2; cb.SetGlobalVector(this.m_layerOffsetNames[k], new Vector2((float)num4 + 0.5f, (float)num5 + 0.5f)); this.m_depthTargets[k] = this.m_depthLayerRT[num3]; this.m_normalTargets[k] = this.m_normalLayerRT[num3]; } this.SetBlitTarget(cb, this.m_depthTargets, target.quarterWidth, target.quarterHeight); this.PerformBlit(cb, this.m_occlusionMat, this.m_deinterleaveDepthPass); this.SetBlitTarget(cb, this.m_normalTargets, target.quarterWidth, target.quarterHeight); this.PerformBlit(cb, this.m_occlusionMat, (int)(this.m_deinterleaveNormalPass + this.PerPixelNormals)); } for (int l = 0; l < 16; l++) { cb.SetGlobalVector("_AO_LayerOffset", new Vector2((float)(l & 3) + 0.5f, (float)(l >> 2) + 0.5f)); cb.SetGlobalVector("_AO_LayerRandom", this.m_randomData[l]); cb.SetGlobalTexture("_AO_NormalTexture", this.m_normalLayerRT[l]); cb.SetGlobalTexture("_AO_DepthTexture", this.m_depthLayerRT[l]); this.SetBlitTarget(cb, this.m_occlusionLayerRT[l], target.quarterWidth, target.quarterHeight); this.PerformBlit(cb, this.m_occlusionMat, (int)(15 + this.SampleCount)); } this.SetBlitTarget(cb, num2, target.width, target.height); for (int m = 0; m < 16; m++) { int x = (m & 3) * target.quarterWidth; int y = (m >> 2) * target.quarterHeight; this.PerformBlit(cb, this.m_occlusionLayerRT[m], target.quarterWidth, target.quarterHeight, this.m_copyMat, 0, x, y); } cb.SetGlobalTexture("_AO_OcclusionAtlas", num2); this.SetBlitTarget(cb, this.m_occlusionRT, target.width, target.height); this.PerformBlit(cb, this.m_occlusionMat, 19); for (int n = 0; n < 16; n++) { this.SafeReleaseTemporaryRT(cb, this.m_occlusionLayerRT[n]); this.SafeReleaseTemporaryRT(cb, this.m_normalLayerRT[n]); this.SafeReleaseTemporaryRT(cb, this.m_depthLayerRT[n]); } this.SafeReleaseTemporaryRT(cb, num2); } else { int pass = (int)(20 + this.SampleCount * (AmplifyOcclusionBase.SampleCountLevel) 4 + (int)this.PerPixelNormals); if (this.Downsample) { cb.Blit(null, new RenderTargetIdentifier(num), this.m_occlusionMat, pass); this.SetBlitTarget(cb, this.m_occlusionRT, target.width, target.height); this.PerformBlit(cb, num, target.width / 2, target.height / 2, this.m_occlusionMat, 41); } else { cb.Blit(null, this.m_occlusionRT, this.m_occlusionMat, pass); } } if (this.BlurEnabled) { int num6 = this.SafeAllocateTemporaryRT(cb, "_AO_TEMP", target.width, target.height, this.m_occlusionRTFormat, RenderTextureReadWrite.Linear, FilterMode.Point); for (int num7 = 0; num7 < this.BlurPasses; num7++) { this.SetBlitTarget(cb, num6, target.width, target.height); this.PerformBlit(cb, this.m_occlusionRT, target.width, target.height, this.m_blurMat, (this.BlurRadius - 1) * 2); this.SetBlitTarget(cb, this.m_occlusionRT, target.width, target.height); this.PerformBlit(cb, num6, target.width, target.height, this.m_blurMat, 1 + (this.BlurRadius - 1) * 2); } this.SafeReleaseTemporaryRT(cb, num6); } if (this.Downsample && num >= 0) { this.SafeReleaseTemporaryRT(cb, num); } cb.SetRenderTarget(null); }