예제 #1
0
        public void AddShaderProperty(CompositionManager compositor, ShaderProperty sp)
        {
            Assert.IsNotNull(sp);

            // Check if property should be shown in the inspector
            bool hide = ((int)sp.flags & (int)ShaderPropertyFlags.NonModifiableTextureData) != 0 ||
                        ((int)sp.flags & (int)ShaderPropertyFlags.HideInInspector) != 0;

            if (!hide)
            {
                // Check if property already exists / do not add duplicates
                int indx = m_ShaderProperties.FindIndex(s => s.propertyName == sp.propertyName);
                if (indx < 0)
                {
                    m_ShaderProperties.Add(sp);
                }
            }

            // For textures, check if we already have this layer in the layer list. If not, add it.
            if (sp.propertyType == ShaderPropertyType.Texture)
            {
                int indx = compositor.layers.FindIndex(s => s.name == sp.propertyName);
                if (indx < 0 && !hide)
                {
                    var newLayer = CompositorLayer.CreateOutputLayer(sp.propertyName);
                    compositor.layers.Add(newLayer);
                }
                else if (indx >= 0 && hide)
                {
                    // if a layer that was in the list is now hidden, remove it
                    compositor.RemoveLayerAtIndex(indx);
                }
            }
        }
예제 #2
0
        public static ShaderProperty Create(Shader shader, Material material, int index)
        {
            ShaderProperty sp = new ShaderProperty();

            {
                sp.propertyName = shader.GetPropertyName(index);
                sp.propertyType = shader.GetPropertyType(index);
                sp.flags        = shader.GetPropertyFlags(index);
                sp.value        = Vector4.zero;

                if (sp.propertyType == ShaderPropertyType.Range)
                {
                    sp.rangeLimits = shader.GetPropertyRangeLimits(index);
                    sp.value       = new Vector4(material.GetFloat(Shader.PropertyToID(shader.GetPropertyName(index))), 0.0f, 0.0f, 0.0f);
                }
                else if (sp.propertyType == ShaderPropertyType.Color)
                {
                    sp.value = material.GetColor(Shader.PropertyToID(shader.GetPropertyName(index)));
                }
                else if (sp.propertyType == ShaderPropertyType.Vector)
                {
                    sp.value = material.GetVector(Shader.PropertyToID(shader.GetPropertyName(index)));
                }
            }
            return(sp);
        }
예제 #3
0
        public static ShaderProperty Create(Shader shader, Material material, int index)
        {
            ShaderProperty sp = new ShaderProperty();

            {
                sp.propertyName = shader.GetPropertyName(index);
                sp.propertyType = shader.GetPropertyType(index);
                sp.flags        = shader.GetPropertyFlags(index);
                sp.value        = Vector4.zero;

                sp.canBeUsedAsRT = false;
                if (sp.propertyType == ShaderPropertyType.Texture)
                {
                    // Detect if this property corresponds to a virtual texture stack (we cannot render on those)
                    shader.FindTextureStack(index, out string stackName, out int layerIndex);
                    sp.canBeUsedAsRT = (stackName.Length == 0);

                    // Only 2D textures can be used as layers (no cube maps, 3d textures, etc)
                    sp.canBeUsedAsRT &= (shader.GetPropertyTextureDimension(index) == TextureDimension.Tex2D);
                }

                if (sp.propertyType == ShaderPropertyType.Range)
                {
                    sp.rangeLimits = shader.GetPropertyRangeLimits(index);
                    sp.value       = new Vector4(material.GetFloat(Shader.PropertyToID(shader.GetPropertyName(index))), 0.0f, 0.0f, 0.0f);
                }
                else if (sp.propertyType == ShaderPropertyType.Color)
                {
                    sp.value = material.GetColor(Shader.PropertyToID(shader.GetPropertyName(index)));
                }
                else if (sp.propertyType == ShaderPropertyType.Vector)
                {
                    sp.value = material.GetVector(Shader.PropertyToID(shader.GetPropertyName(index)));
                }
            }
            return(sp);
        }
예제 #4
0
        public void AddPropertiesFromShaderAndMaterial(CompositionManager compositor, Shader shader, Material material)
        {
            // reflect the non-texture shader properties
            List <string> propertyNames = new List <string>();
            int           propCount     = shader.GetPropertyCount();

            for (int i = 0; i < propCount; i++)
            {
                ShaderProperty sp = ShaderProperty.Create(shader, material, i);
                AddShaderProperty(compositor, sp);
                propertyNames.Add(sp.propertyName);
            }

            // remove any left-over properties that do not appear in the shader anymore
            for (int j = m_ShaderProperties.Count - 1; j >= 0; --j)
            {
                int indx = propertyNames.FindIndex(x => x == m_ShaderProperties[j].propertyName);
                if (indx < 0)
                {
                    m_ShaderProperties.RemoveAt(j);
                }
            }

            // Now remove any left-over  layers that do not appear in the shader anymore
            for (int j = compositor.layers.Count - 1; j >= 0; --j)
            {
                if (compositor.layers[j].outputTarget != CompositorLayer.OutputTarget.CameraStack)
                {
                    int indx = propertyNames.FindIndex(x => x == compositor.layers[j].name);
                    if (indx < 0)
                    {
                        compositor.RemoveLayerAtIndex(j);
                    }
                }
            }
        }