コード例 #1
0
        void SetupLayersKeywords(Material material)
        {
            if (numLayer == 4)
            {
                SetKeyword(material, "_LAYEREDLIT_4_LAYERS", true);
                SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false);
            }
            else if (numLayer == 3)
            {
                SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false);
                SetKeyword(material, "_LAYEREDLIT_3_LAYERS", true);
            }
            else
            {
                SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false);
                SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false);
            }

            const string kLayerMappingTriplanar = "_LAYER_MAPPING_TRIPLANAR_";

            for (int i = 0; i < numLayer; ++i)
            {
                // We setup the masking map based on the enum for each layer.
                // using mapping mask allow to reduce the number of generated combination for a very small increase in ALU
                string             layerUVBaseParam             = string.Format("{0}{1}", kUVBase, i);
                LayerUVBaseMapping layerUVBaseMapping           = (LayerUVBaseMapping)material.GetFloat(layerUVBaseParam);
                string             layerUVDetailParam           = string.Format("{0}{1}", kUVDetail, i);
                UVDetailMapping    layerUVDetailMapping         = (UVDetailMapping)material.GetFloat(layerUVDetailParam);
                string             currentLayerMappingTriplanar = string.Format("{0}{1}", kLayerMappingTriplanar, i);

                float X, Y, Z, W;
                X = (layerUVBaseMapping == LayerUVBaseMapping.UV0) ? 1.0f : 0.0f;
                Y = (layerUVBaseMapping == LayerUVBaseMapping.UV1) ? 1.0f : 0.0f;
                Z = (layerUVBaseMapping == LayerUVBaseMapping.UV2) ? 1.0f : 0.0f;
                W = (layerUVBaseMapping == LayerUVBaseMapping.UV3) ? 1.0f : 0.0f;
                layerUVMappingMask[i].colorValue   = new Color(X, Y, Z, W);
                layerUVMappingPlanar[i].floatValue = (layerUVBaseMapping == LayerUVBaseMapping.Planar) ? 1.0f : 0.0f;

                SetKeyword(material, currentLayerMappingTriplanar, layerUVBaseMapping == LayerUVBaseMapping.Triplanar);

                X = (layerUVDetailMapping == UVDetailMapping.UV0) ? 1.0f : 0.0f;
                Y = (layerUVDetailMapping == UVDetailMapping.UV1) ? 1.0f : 0.0f;
                Z = (layerUVDetailMapping == UVDetailMapping.UV2) ? 1.0f : 0.0f;
                W = (layerUVDetailMapping == UVDetailMapping.UV3) ? 1.0f : 0.0f;
                layerUVDetailsMappingMask[i].colorValue = new Color(X, Y, Z, W);
            }
        }
コード例 #2
0
ファイル: LayeredLitUI.cs プロジェクト: sjb8100/SRP
        bool DoLayerGUI(AssetImporter materialImporter, int layerIndex)
        {
            bool result = false;

            Material material = m_MaterialEditor.target as Material;

            bool mainLayerInfluenceEnable = useMainLayerInfluence.floatValue > 0.0f;

            EditorGUILayout.LabelField(styles.layerLabels[layerIndex], styles.layerLabelColors[layerIndex]);

            EditorGUI.indentLevel++;

            EditorGUI.BeginChangeCheck();
            m_MaterialLayers[layerIndex] = EditorGUILayout.ObjectField(styles.materialLayerText, m_MaterialLayers[layerIndex], typeof(Material), true) as Material;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(materialImporter, "Change layer material");
                SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex);
                result = true;
            }

            EditorGUI.BeginChangeCheck();
            m_MaterialEditor.ShaderProperty(layerUVBase[layerIndex], styles.UVBaseText);
            if (EditorGUI.EndChangeCheck())
            {
                SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex);
                result = true;
            }

            if (((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Planar) ||
                ((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Triplanar))
            {
                EditorGUI.indentLevel++;
                m_MaterialEditor.ShaderProperty(layerTexWorldScale[layerIndex], styles.layerTexWorldScaleText);
                EditorGUI.indentLevel--;

                if (((LayerUVBaseMapping)layerUVBase[layerIndex].floatValue == LayerUVBaseMapping.Planar))
                {
                    GUILayout.Label("       " + styles.UVDetailText.text + ": Planar");
                }
                else
                {
                    GUILayout.Label("       " + styles.UVDetailText.text + ": Triplanar");
                }
            }
            else
            {
                EditorGUI.indentLevel++;
                m_MaterialEditor.ShaderProperty(layerTiling[layerIndex], styles.layerTilingText);
                EditorGUI.indentLevel--;

                EditorGUI.BeginChangeCheck();
                m_MaterialEditor.ShaderProperty(layerUVDetail[layerIndex], styles.UVDetailText);
                if (EditorGUI.EndChangeCheck())
                {
                    SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex);
                    result = true;
                }
            }

            // We setup the masking map based on the enum for each layer.
            // using mapping mask allow to reduce the number of generated combination for a very small increase in ALU
            LayerUVBaseMapping layerUVBaseMapping = (LayerUVBaseMapping)layerUVBase[layerIndex].floatValue;

            float X, Y, Z, W;

            X = (layerUVBaseMapping == LayerUVBaseMapping.UV0) ? 1.0f : 0.0f;
            Y = (layerUVBaseMapping == LayerUVBaseMapping.UV1) ? 1.0f : 0.0f;
            Z = (layerUVBaseMapping == LayerUVBaseMapping.UV2) ? 1.0f : 0.0f;
            W = (layerUVBaseMapping == LayerUVBaseMapping.UV3) ? 1.0f : 0.0f;
            layerUVMappingMask[layerIndex].colorValue = (layerIndex == 0) ? new Color(1.0f, 0.0f, 0.0f, 0.0f) : new Color(X, Y, Z, W); // Special case for Main Layer and Blend Mask, only UV0. As Layer0 is share by both here, need to force X to 1.0 in all case

            UVDetailMapping layerUVDetailMapping = (UVDetailMapping)layerUVDetail[layerIndex].floatValue;

            X = (layerUVDetailMapping == UVDetailMapping.UV0) ? 1.0f : 0.0f;
            Y = (layerUVDetailMapping == UVDetailMapping.UV1) ? 1.0f : 0.0f;
            Z = (layerUVDetailMapping == UVDetailMapping.UV2) ? 1.0f : 0.0f;
            W = (layerUVDetailMapping == UVDetailMapping.UV3) ? 1.0f : 0.0f;
            layerUVDetailsMappingMask[layerIndex].colorValue = new Color(X, Y, Z, W);

            bool useDensityModeEnable = useDensityMode.floatValue != 0.0f;

            if (useDensityModeEnable)
            {
                EditorGUILayout.LabelField(styles.densityOpacityInfluenceText, EditorStyles.boldLabel);

                EditorGUI.indentLevel++;
                m_MaterialEditor.ShaderProperty(opacityAsDensity[layerIndex], styles.opacityAsDensityText);
                m_MaterialEditor.ShaderProperty(minimumOpacity[layerIndex], styles.minimumOpacityText);
                EditorGUI.indentLevel--;
            }

            // Display height control if they have a meaning
            if ((tessellationMode != null && ((TessellationMode)tessellationMode.floatValue == TessellationMode.Displacement || (TessellationMode)tessellationMode.floatValue == TessellationMode.DisplacementPhong)) ||
                (enablePerPixelDisplacement.floatValue > 0.0f) ||
                (useHeightBasedBlend.floatValue > 0.0f)
                )
            {
                EditorGUILayout.LabelField(styles.heightControlText, EditorStyles.boldLabel);

                EditorGUI.indentLevel++;
                m_MaterialEditor.ShaderProperty(heightFactor[layerIndex], styles.heightFactorText);
                layerHeightAmplitude[layerIndex].floatValue = material.GetFloat(kHeightAmplitude + layerIndex) * heightFactor[layerIndex].floatValue;
                m_MaterialEditor.ShaderProperty(heightCenterOffset[layerIndex], styles.heightCenterOffsetText);
                layerCenterOffset[layerIndex].floatValue = material.GetFloat(kHeightCenter + layerIndex) + heightCenterOffset[layerIndex].floatValue;
                EditorGUI.indentLevel--;
            }


            // influence
            if (layerIndex > 0)
            {
                int paramIndex = layerIndex - 1;

                bool heightBasedBlendEnable = useHeightBasedBlend.floatValue > 0.0f;
                if (heightBasedBlendEnable)
                {
                    EditorGUI.indentLevel++;
                    m_MaterialEditor.ShaderProperty(blendUsingHeight[paramIndex], styles.blendUsingHeight);
                    EditorGUI.indentLevel--;
                }

                if (mainLayerInfluenceEnable)
                {
                    EditorGUILayout.LabelField(styles.mainLayerInfluenceText, EditorStyles.boldLabel);

                    EditorGUI.indentLevel++;

                    m_MaterialEditor.ShaderProperty(inheritBaseColor[paramIndex], styles.inheritBaseColorText);
                    EditorGUI.indentLevel++;
                    m_MaterialEditor.ShaderProperty(inheritBaseColorThreshold[paramIndex], styles.inheritBaseColorThresholdText);
                    EditorGUI.indentLevel--;
                    m_MaterialEditor.ShaderProperty(inheritBaseNormal[paramIndex], styles.inheritBaseNormalText);
                    // Main height influence is only available if the shader use the heightmap for displacement (per vertex or per level)
                    // We always display it as it can be tricky to know when per pixel displacement is enabled or not
                    m_MaterialEditor.ShaderProperty(inheritBaseHeight[paramIndex], styles.inheritBaseHeightText);

                    EditorGUI.indentLevel--;
                }
            }

            EditorGUI.indentLevel--;

            if (layerIndex == 0)
            {
                EditorGUILayout.Space();
            }

            return(result);
        }