コード例 #1
0
        // Token: 0x06001EE8 RID: 7912 RVA: 0x001825C0 File Offset: 0x001807C0
        public override void PopulateCommandBuffer(CommandBuffer cb)
        {
            ScreenSpaceReflectionModel.Settings settings = base.model.settings;
            Camera   camera   = this.context.camera;
            int      num      = (settings.reflection.reflectionQuality == ScreenSpaceReflectionModel.SSRResolution.High) ? 1 : 2;
            int      num2     = this.context.width / num;
            int      num3     = this.context.height / num;
            float    num4     = (float)this.context.width;
            float    num5     = (float)this.context.height;
            float    num6     = num4 / 2f;
            float    num7     = num5 / 2f;
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Screen Space Reflection");

            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._RayStepSize, settings.reflection.stepSize);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._AdditiveReflection, (settings.reflection.blendType == ScreenSpaceReflectionModel.SSRReflectionBlendType.Additive) ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._BilateralUpsampling, this.k_BilateralUpsample ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._TreatBackfaceHitAsMiss, this.k_TreatBackfaceHitAsMiss ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._AllowBackwardsRays, settings.reflection.reflectBackfaces ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._TraceBehindObjects, this.k_TraceBehindObjects ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._MaxSteps, settings.reflection.iterationCount);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._FullResolutionFiltering, 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._HalfResolution, (settings.reflection.reflectionQuality != ScreenSpaceReflectionModel.SSRResolution.High) ? 1 : 0);
            material.SetInt(ScreenSpaceReflectionComponent.Uniforms._HighlightSuppression, this.k_HighlightSuppression ? 1 : 0);
            float value = num4 / (-2f * Mathf.Tan(camera.fieldOfView / 180f * 3.14159274f * 0.5f));

            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._PixelsPerMeterAtOneMeter, value);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._ScreenEdgeFading, settings.screenEdgeMask.intensity);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._ReflectionBlur, settings.reflection.reflectionBlur);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._MaxRayTraceDistance, settings.reflection.maxDistance);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._FadeDistance, settings.intensity.fadeDistance);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._LayerThickness, settings.reflection.widthModifier);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._SSRMultiplier, settings.intensity.reflectionMultiplier);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._FresnelFade, settings.intensity.fresnelFade);
            material.SetFloat(ScreenSpaceReflectionComponent.Uniforms._FresnelFadePower, settings.intensity.fresnelFadePower);
            Matrix4x4 projectionMatrix = camera.projectionMatrix;
            Vector4   value2           = new Vector4(-2f / (num4 * projectionMatrix[0]), -2f / (num5 * projectionMatrix[5]), (1f - projectionMatrix[2]) / projectionMatrix[0], (1f + projectionMatrix[6]) / projectionMatrix[5]);
            Vector3   v = float.IsPositiveInfinity(camera.farClipPlane) ? new Vector3(camera.nearClipPlane, -1f, 1f) : new Vector3(camera.nearClipPlane * camera.farClipPlane, camera.nearClipPlane - camera.farClipPlane, camera.farClipPlane);

            material.SetVector(ScreenSpaceReflectionComponent.Uniforms._ReflectionBufferSize, new Vector2((float)num2, (float)num3));
            material.SetVector(ScreenSpaceReflectionComponent.Uniforms._ScreenSize, new Vector2(num4, num5));
            material.SetVector(ScreenSpaceReflectionComponent.Uniforms._InvScreenSize, new Vector2(1f / num4, 1f / num5));
            material.SetVector(ScreenSpaceReflectionComponent.Uniforms._ProjInfo, value2);
            material.SetVector(ScreenSpaceReflectionComponent.Uniforms._CameraClipInfo, v);
            Matrix4x4 lhs = default(Matrix4x4);

            lhs.SetRow(0, new Vector4(num6, 0f, 0f, num6));
            lhs.SetRow(1, new Vector4(0f, num7, 0f, num7));
            lhs.SetRow(2, new Vector4(0f, 0f, 1f, 0f));
            lhs.SetRow(3, new Vector4(0f, 0f, 0f, 1f));
            Matrix4x4 value3 = lhs * projectionMatrix;

            material.SetMatrix(ScreenSpaceReflectionComponent.Uniforms._ProjectToPixelMatrix, value3);
            material.SetMatrix(ScreenSpaceReflectionComponent.Uniforms._WorldToCameraMatrix, camera.worldToCameraMatrix);
            material.SetMatrix(ScreenSpaceReflectionComponent.Uniforms._CameraToWorldMatrix, camera.worldToCameraMatrix.inverse);
            RenderTextureFormat format    = this.context.isHdr ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
            int normalAndRoughnessTexture = ScreenSpaceReflectionComponent.Uniforms._NormalAndRoughnessTexture;
            int hitPointTexture           = ScreenSpaceReflectionComponent.Uniforms._HitPointTexture;
            int blurTexture            = ScreenSpaceReflectionComponent.Uniforms._BlurTexture;
            int filteredReflections    = ScreenSpaceReflectionComponent.Uniforms._FilteredReflections;
            int finalReflectionTexture = ScreenSpaceReflectionComponent.Uniforms._FinalReflectionTexture;
            int tempTexture            = ScreenSpaceReflectionComponent.Uniforms._TempTexture;

            cb.GetTemporaryRT(normalAndRoughnessTexture, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            cb.GetTemporaryRT(hitPointTexture, num2, num3, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            for (int i = 0; i < 5; i++)
            {
                cb.GetTemporaryRT(this.m_ReflectionTextures[i], num2 >> i, num3 >> i, 0, FilterMode.Bilinear, format);
            }
            cb.GetTemporaryRT(filteredReflections, num2, num3, 0, this.k_BilateralUpsample ? FilterMode.Point : FilterMode.Bilinear, format);
            cb.GetTemporaryRT(finalReflectionTexture, num2, num3, 0, FilterMode.Point, format);
            cb.Blit(BuiltinRenderTextureType.CameraTarget, normalAndRoughnessTexture, material, 6);
            cb.Blit(BuiltinRenderTextureType.CameraTarget, hitPointTexture, material, 0);
            cb.Blit(BuiltinRenderTextureType.CameraTarget, filteredReflections, material, 5);
            cb.Blit(filteredReflections, this.m_ReflectionTextures[0], material, 8);
            for (int j = 1; j < 5; j++)
            {
                int nameID = this.m_ReflectionTextures[j - 1];
                int num8   = j;
                cb.GetTemporaryRT(blurTexture, num2 >> num8, num3 >> num8, 0, FilterMode.Bilinear, format);
                cb.SetGlobalVector(ScreenSpaceReflectionComponent.Uniforms._Axis, new Vector4(1f, 0f, 0f, 0f));
                cb.SetGlobalFloat(ScreenSpaceReflectionComponent.Uniforms._CurrentMipLevel, (float)j - 1f);
                cb.Blit(nameID, blurTexture, material, 2);
                cb.SetGlobalVector(ScreenSpaceReflectionComponent.Uniforms._Axis, new Vector4(0f, 1f, 0f, 0f));
                nameID = this.m_ReflectionTextures[j];
                cb.Blit(blurTexture, nameID, material, 2);
                cb.ReleaseTemporaryRT(blurTexture);
            }
            cb.Blit(this.m_ReflectionTextures[0], finalReflectionTexture, material, 3);
            cb.GetTemporaryRT(tempTexture, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Bilinear, format);
            cb.Blit(BuiltinRenderTextureType.CameraTarget, tempTexture, material, 1);
            cb.Blit(tempTexture, BuiltinRenderTextureType.CameraTarget);
            cb.ReleaseTemporaryRT(tempTexture);
        }
コード例 #2
0
        public override void PopulateCommandBuffer(CommandBuffer cb)
        {
            ScreenSpaceReflectionModel.Settings settings = base.model.settings;
            Camera   camera = base.context.camera;
            int      num    = (settings.reflection.reflectionQuality != ScreenSpaceReflectionModel.SSRResolution.High) ? 2 : 1;
            int      width  = base.context.width / num;
            int      height = base.context.height / num;
            float    x      = base.context.width;
            float    y      = base.context.height;
            float    num6   = x / 2f;
            float    num7   = y / 2f;
            Material mat    = base.context.materialFactory.Get("Hidden/Post FX/Screen Space Reflection");

            mat.SetInt(Uniforms._RayStepSize, settings.reflection.stepSize);
            mat.SetInt(Uniforms._AdditiveReflection, (settings.reflection.blendType != ScreenSpaceReflectionModel.SSRReflectionBlendType.Additive) ? 0 : 1);
            mat.SetInt(Uniforms._BilateralUpsampling, !this.k_BilateralUpsample ? 0 : 1);
            mat.SetInt(Uniforms._TreatBackfaceHitAsMiss, !this.k_TreatBackfaceHitAsMiss ? 0 : 1);
            mat.SetInt(Uniforms._AllowBackwardsRays, !settings.reflection.reflectBackfaces ? 0 : 1);
            mat.SetInt(Uniforms._TraceBehindObjects, !this.k_TraceBehindObjects ? 0 : 1);
            mat.SetInt(Uniforms._MaxSteps, settings.reflection.iterationCount);
            mat.SetInt(Uniforms._FullResolutionFiltering, 0);
            mat.SetInt(Uniforms._HalfResolution, (settings.reflection.reflectionQuality == ScreenSpaceReflectionModel.SSRResolution.High) ? 0 : 1);
            mat.SetInt(Uniforms._HighlightSuppression, !this.k_HighlightSuppression ? 0 : 1);
            float num8 = x / (-2f * Mathf.Tan(((camera.fieldOfView / 180f) * 3.141593f) * 0.5f));

            mat.SetFloat(Uniforms._PixelsPerMeterAtOneMeter, num8);
            mat.SetFloat(Uniforms._ScreenEdgeFading, settings.screenEdgeMask.intensity);
            mat.SetFloat(Uniforms._ReflectionBlur, settings.reflection.reflectionBlur);
            mat.SetFloat(Uniforms._MaxRayTraceDistance, settings.reflection.maxDistance);
            mat.SetFloat(Uniforms._FadeDistance, settings.intensity.fadeDistance);
            mat.SetFloat(Uniforms._LayerThickness, settings.reflection.widthModifier);
            mat.SetFloat(Uniforms._SSRMultiplier, settings.intensity.reflectionMultiplier);
            mat.SetFloat(Uniforms._FresnelFade, settings.intensity.fresnelFade);
            mat.SetFloat(Uniforms._FresnelFadePower, settings.intensity.fresnelFadePower);
            Matrix4x4 projectionMatrix = camera.projectionMatrix;
            Vector4   vector           = new Vector4(-2f / (x * projectionMatrix[0]), -2f / (y * projectionMatrix[5]), (1f - projectionMatrix[2]) / projectionMatrix[0], (1f + projectionMatrix[6]) / projectionMatrix[5]);
            Vector3   vector2          = !float.IsPositiveInfinity(camera.farClipPlane) ? new Vector3(camera.nearClipPlane * camera.farClipPlane, camera.nearClipPlane - camera.farClipPlane, camera.farClipPlane) : new Vector3(camera.nearClipPlane, -1f, 1f);

            mat.SetVector(Uniforms._ReflectionBufferSize, new Vector2((float)width, (float)height));
            mat.SetVector(Uniforms._ScreenSize, new Vector2(x, y));
            mat.SetVector(Uniforms._InvScreenSize, new Vector2(1f / x, 1f / y));
            mat.SetVector(Uniforms._ProjInfo, vector);
            mat.SetVector(Uniforms._CameraClipInfo, vector2);
            Matrix4x4 matrixx2 = new Matrix4x4();

            matrixx2.SetRow(0, new Vector4(num6, 0f, 0f, num6));
            matrixx2.SetRow(1, new Vector4(0f, num7, 0f, num7));
            matrixx2.SetRow(2, new Vector4(0f, 0f, 1f, 0f));
            matrixx2.SetRow(3, new Vector4(0f, 0f, 0f, 1f));
            Matrix4x4 matrixx3 = matrixx2 * projectionMatrix;

            mat.SetMatrix(Uniforms._ProjectToPixelMatrix, matrixx3);
            mat.SetMatrix(Uniforms._WorldToCameraMatrix, camera.worldToCameraMatrix);
            mat.SetMatrix(Uniforms._CameraToWorldMatrix, camera.worldToCameraMatrix.inverse);
            RenderTextureFormat format = !base.context.isHdr ? RenderTextureFormat.ARGB32 : RenderTextureFormat.ARGBHalf;
            int nameID = Uniforms._NormalAndRoughnessTexture;
            int num10  = Uniforms._HitPointTexture;
            int num11  = Uniforms._BlurTexture;
            int num12  = Uniforms._FilteredReflections;
            int num13  = Uniforms._FinalReflectionTexture;
            int num14  = Uniforms._TempTexture;

            cb.GetTemporaryRT(nameID, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            cb.GetTemporaryRT(num10, width, height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            for (int i = 0; i < 5; i++)
            {
                cb.GetTemporaryRT(this.m_ReflectionTextures[i], width >> (i & 0x1f), height >> (i & 0x1f), 0, FilterMode.Bilinear, format);
            }
            cb.GetTemporaryRT(num12, width, height, 0, !this.k_BilateralUpsample ? FilterMode.Bilinear : FilterMode.Point, format);
            cb.GetTemporaryRT(num13, width, height, 0, FilterMode.Point, format);
            cb.Blit(2, nameID, mat, 6);
            cb.Blit(2, num10, mat, 0);
            cb.Blit(2, num12, mat, 5);
            cb.Blit(num12, this.m_ReflectionTextures[0], mat, 8);
            for (int j = 1; j < 5; j++)
            {
                int source = this.m_ReflectionTextures[j - 1];
                int num18  = j;
                cb.GetTemporaryRT(num11, width >> (num18 & 0x1f), height >> (num18 & 0x1f), 0, FilterMode.Bilinear, format);
                cb.SetGlobalVector(Uniforms._Axis, new Vector4(1f, 0f, 0f, 0f));
                cb.SetGlobalFloat(Uniforms._CurrentMipLevel, j - 1f);
                cb.Blit(source, num11, mat, 2);
                cb.SetGlobalVector(Uniforms._Axis, new Vector4(0f, 1f, 0f, 0f));
                source = this.m_ReflectionTextures[j];
                cb.Blit(num11, source, mat, 2);
                cb.ReleaseTemporaryRT(num11);
            }
            cb.Blit(this.m_ReflectionTextures[0], num13, mat, 3);
            cb.GetTemporaryRT(num14, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Bilinear, format);
            cb.Blit(2, num14, mat, 1);
            cb.Blit(num14, 2);
            cb.ReleaseTemporaryRT(num14);
        }