private Vector2 GenerateRandomOffset() { Vector2 result = new Vector2(HaltonSeq.Get((sampleIndex & 0x3FF) + 1, 2) - 0.5f, HaltonSeq.Get((sampleIndex & 0x3FF) + 1, 3) - 0.5f); if (++sampleIndex >= 8) { sampleIndex = 0; } return(result); }
Vector2 GetRandomOffset() { // 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 ); return(offset); }
public override void Render(PostProcessRenderContext context) { #if POSTFX_DEBUG_STATIC_GRAIN // Chosen by a fair dice roll float time = 4f; float rndOffsetX = 0f; float rndOffsetY = 0f; #else var time = Time.realtimeSinceStartup; var rndOffsetX = HaltonSeq.Get(m_SampleIndex & 1023, 2); var rndOffsetY = HaltonSeq.Get(m_SampleIndex & 1023, 3); if (++m_SampleIndex >= k_SampleCount) { m_SampleIndex = 0; } #endif // Generate the grain lut for the current frame first 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(); } var sheet = context.propertySheets.Get(context.resources.shaders.grainBaker); sheet.properties.Clear(); sheet.properties.SetFloat(ShaderIDs.Phase, time % 10f); context.command.BeginSample("GrainLookup"); context.command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, m_GrainLookupRT, sheet, settings.colored.value ? 1 : 0); context.command.EndSample("GrainLookup"); // Send everything to the uber shader var uberSheet = context.uberSheet; uberSheet.EnableKeyword("GRAIN"); uberSheet.properties.SetTexture(ShaderIDs.GrainTex, m_GrainLookupRT); uberSheet.properties.SetVector(ShaderIDs.Grain_Params1, new Vector2(settings.lumContrib.value, settings.intensity.value * 20f)); uberSheet.properties.SetVector(ShaderIDs.Grain_Params2, new Vector4(context.width / (float)m_GrainLookupRT.width / settings.size.value, context.height / (float)m_GrainLookupRT.height / settings.size.value, rndOffsetX, rndOffsetY)); }
Vector2 GenerateRandomOffset() { var offset = new Vector2( HaltonSeq.Get(m_SampleIndex & 1023, 2), HaltonSeq.Get(m_SampleIndex & 1023, 3) ); if (++m_SampleIndex >= k_SampleCount) { m_SampleIndex = 0; } return(offset); }
private 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((m_SampleIndex & 1023) + 1, 2) - 0.5f, HaltonSeq.Get((m_SampleIndex & 1023) + 1, 3) - 0.5f ); if (++m_SampleIndex >= k_SampleCount) { m_SampleIndex = 0; } return(offset); }