示例#1
0
        private static SamplerBase CreateSampler(SamplerType samplerType, int numSamples, int numSets = 83)
        {
            SamplerBase sampler = null;

            switch (samplerType)
            {
            case SamplerType.Hammersley:
                sampler = new HammersleySampler(numSamples, numSets);
                break;

            case SamplerType.Jittered:
                sampler = new JitteredSampler(numSamples, numSets);
                break;

            case SamplerType.Random:
                sampler = new RandomSampler(numSamples, numSets);
                break;

            case SamplerType.Regular:
                sampler = new RegularSampler(numSamples, numSets);
                break;

            default:
                sampler = new RegularSampler(numSamples, numSets);
                break;
            }

            return(sampler);
        }
示例#2
0
        public void Init(Shader bakeShader, Shader mixShader, BakeSettings settings)
        {
            m_Camera = GetComponent <Camera>();

            m_CommandBuffer = new CommandBuffer();
            m_Camera.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque, m_CommandBuffer);

            m_BakeMaterial = new Material(bakeShader);
            m_MixMaterial  = new Material(mixShader);

            float weight = 1.0f / (settings.numSamples * 3);

            m_MixMaterial.SetFloat("_MixFactor", weight);
            m_BakeMaterial.SetFloat("_TraceRadius", settings.traceRadius);
            m_BakeMaterial.SetFloat("_CullBack", settings.cullBack ? 1.0f : 0.0f);

            m_PreTex = RenderTexture.GetTemporary(settings.aoMapSize, settings.aoMapSize);
            m_PreTex.DiscardContents(true, true);

            m_Settings = settings;

            m_Sampler = CreateSampler(settings.samplerType, settings.numSamples);
        }