예제 #1
0
        Vector2 GenerateRandomOffset()
        {
            var offset = new Vector2(
                HaltonSeq.Get((sampleIndex & 1023) + 1, 2) - 0.5f,
                HaltonSeq.Get((sampleIndex & 1023) + 1, 3) - 0.5f
                );

            if (++sampleIndex >= k_SampleCount)
            {
                sampleIndex = 0;
            }

            return(offset);
        }
예제 #2
0
            Vector2 GenerateRandomOffset()
            {
                // The variance between 0 and the actual halton sequence values reveals noticeable instability
                // in Unity's shadow maps, so we avoid index 0.
                var offset = new Vector2(
                    HaltonSeq.Get((sampleIndex & 1023) + 1, 2) - 0.5f,
                    HaltonSeq.Get((sampleIndex & 1023) + 1, 3) - 0.5f
                    );

                if (++sampleIndex >= k_SampleCount)
                {
                    sampleIndex = 0;
                }

                return(offset);
            }
예제 #3
0
        public override void Render(PostProcessRenderContext context)
        {
            float realtimeSinceStartup = Time.realtimeSinceStartup;
            float z = HaltonSeq.Get(m_SampleIndex & 0x3FF, 2);
            float w = HaltonSeq.Get(m_SampleIndex & 0x3FF, 3);

            if (++m_SampleIndex >= 1024)
            {
                m_SampleIndex = 0;
            }
            if (m_GrainLookupRT == null || !m_GrainLookupRT.IsCreated())
            {
                RuntimeUtilities.Destroy(m_GrainLookupRT);
                m_GrainLookupRT = new RenderTexture(128, 128, 0, GetLookupFormat())
                {
                    filterMode = FilterMode.Bilinear,
                    wrapMode   = TextureWrapMode.Repeat,
                    anisoLevel = 0,
                    name       = "Grain Lookup Texture"
                };
                m_GrainLookupRT.Create();
            }
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.grainBaker);

            propertySheet.properties.Clear();
            propertySheet.properties.SetFloat(ShaderIDs.Phase, realtimeSinceStartup % 10f);
            context.command.BeginSample("GrainLookup");
            context.command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, m_GrainLookupRT, propertySheet, base.settings.colored.value ? 1 : 0);
            context.command.EndSample("GrainLookup");
            PropertySheet uberSheet = context.uberSheet;

            uberSheet.EnableKeyword("GRAIN");
            uberSheet.properties.SetTexture(ShaderIDs.GrainTex, m_GrainLookupRT);
            uberSheet.properties.SetVector(ShaderIDs.Grain_Params1, new Vector2(base.settings.lumContrib.value, base.settings.intensity.value * 20f));
            uberSheet.properties.SetVector(ShaderIDs.Grain_Params2, new Vector4((float)context.width / (float)m_GrainLookupRT.width / base.settings.size.value, (float)context.height / (float)m_GrainLookupRT.height / base.settings.size.value, z, w));
        }