public void AddDirect(IVoxelStorer storer, IVoxelizationMethod method, RenderView view, VoxelAttribute attr, VoxelizationStage stage, bool output, bool shadows)
        {
            bool toAdd = true;

            foreach (VoxelizationPass pass in passes)
            {
                if (pass.storer.Equals(storer) &&
                    pass.method.Equals(method) &&
                    pass.view.ViewProjection == view.ViewProjection)
                {
                    pass.Add(attr, stage, output, shadows);
                    toAdd = false;
                    break;
                }
            }
            if (toAdd)
            {
                VoxelizationPass pass = new VoxelizationPass
                {
                    storer = storer,
                    method = method,
                    view   = view
                };
                pass.Add(attr, stage, output, shadows);
                passes.Add(pass);
            }
        }
Exemple #2
0
        public ShaderSource GetVoxelizationShader(VoxelizationPass pass, ProcessedVoxelVolume data)
        {
            bool              singleClip = UpdatesOneClipPerFrame();
            ShaderSource      VoxelizationMethodSource = pass.method.GetVoxelizationShader();
            ShaderMixinSource cachedMixin = new ShaderMixinSource();

            cachedMixin.Mixins.Add(storage);
            cachedMixin.AddComposition("method", VoxelizationMethodSource);
            if (singleClip)
            {
                cachedMixin.AddMacro("singleClip", true);
            }

            string IndirectStoreMacro = "";

            for (int i = 0; i < pass.AttributesIndirect.Count; i++)
            {
                string iStr = i.ToString();
                IndirectStoreMacro += $"AttributesIndirect[{iStr}].IndirectWrite(fragmentsBuffer, writeindex + {pass.AttributesIndirect[i].BufferOffset});\n";
            }

            cachedMixin.AddMacro("IndirectStoreMacro", IndirectStoreMacro);

            foreach (var attr in pass.AttributesTemp)
            {
                cachedMixin.AddCompositionToArray("AttributesTemp", attr.GetVoxelizationShader());
            }

            foreach (var attr in pass.AttributesDirect)
            {
                cachedMixin.AddCompositionToArray("AttributesDirect", attr.GetVoxelizationShader());
            }

            foreach (var attr in pass.AttributesIndirect)
            {
                cachedMixin.AddCompositionToArray("AttributesIndirect", attr.GetVoxelizationShader());
            }

            return(cachedMixin);
        }