示例#1
0
            private void Initialize(IWetDecal decal)
            {
                Decal = decal;

                if (PropertyBlock != null)
                {
                    PropertyBlock.Clear();
                }

                UpdateProperties(true);
            }
示例#2
0
            public void UpdateProperties(bool batchPropertiesChanged)
            {
                var settings = Decal.Settings;

                // Move decal to appropriate batch if needed
                if (batchPropertiesChanged)
                {
                    // Find shader permutation
                    var permuatation = new MaterialPermutation(settings.Mode, settings.LayerMode, settings.LayerProjection, settings.Shape, settings.EnableJitter);

                    // Choose the smallest jitter value of the three textures (or zero if they are all null)
                    var jitter = Min(
                        settings.LayerMode == LayerMode.Triplanar ? Jitter(settings.SampleJitter, settings.XLayer.LayerMask) : null,
                        settings.LayerMode != LayerMode.None ? Jitter(settings.SampleJitter, settings.YLayer.LayerMask) : null,
                        settings.LayerMode == LayerMode.Triplanar ? Jitter(settings.SampleJitter, settings.ZLayer.LayerMask) : null
                        );

                    // Collect material properties
                    var materialProperties = new MaterialProperties(
                        settings.XLayer.LayerMask,
                        settings.XLayer.LayerMaskScaleOffset,
                        settings.YLayer.LayerMask,
                        settings.YLayer.LayerMaskScaleOffset,
                        settings.ZLayer.LayerMask,
                        settings.ZLayer.LayerMaskScaleOffset,
                        _system.SharedState.BlueNoiseRGBA,
                        new Vector2(29, 31),
                        jitter
                        );

                    // Update batch
                    if (_batch != null)
                    {
                        _batch.Remove(this);
                    }

                    _batch = _system.SharedState.FindBatch(permuatation, materialProperties);
                    _batch.Add(this);
                }

                // Update instance properties struct
                _properties.Saturation    = settings.Saturation;
                _properties.Fadeout       = settings.EdgeFadeoff;
                _properties.EdgeSharpness = settings.FaceSharpness;

                if (settings.LayerMode != LayerMode.None)
                {
                    settings.YLayer.EvaluateRanges(out _properties.YLayer);
                }

                if (settings.LayerMode == LayerMode.Triplanar)
                {
                    settings.XLayer.EvaluateRanges(out _properties.XLayer);
                    settings.ZLayer.EvaluateRanges(out _properties.ZLayer);
                }

                // Update material properties block if running non-instanced
                if (!RenderSettings.Instance.EnableInstancing)
                {
                    if (PropertyBlock == null)
                    {
                        PropertyBlock = new MaterialPropertyBlock();
                    }

                    PropertyBlock.Clear();
                    _properties.LoadInto(PropertyBlock, settings.LayerMode);
                }
            }