Esempio n. 1
0
 static void AddSliderProperty(this PropertyCollector collector, string referenceName, string displayName, float defaultValue, Vector2 range, HLSLDeclaration declarationType = HLSLDeclaration.DoNotDeclare)
 {
     collector.AddShaderProperty(new Vector1ShaderProperty
     {
         floatType               = FloatType.Slider,
         rangeValues             = range,
         value                   = defaultValue,
         overrideReferenceName   = referenceName,
         hidden                  = true,
         overrideHLSLDeclaration = true,
         hlslDeclarationOverride = declarationType,
         displayName             = displayName,
     });
 }
Esempio n. 2
0
        public static void AddDoubleSidedProperty(PropertyCollector collector, DoubleSidedMode mode = DoubleSidedMode.Enabled)
        {
            var normalMode = ConvertDoubleSidedModeToDoubleSidedNormalMode(mode);

            collector.AddToggleProperty("_DoubleSidedEnable", mode != DoubleSidedMode.Disabled);
            collector.AddShaderProperty(new Vector1ShaderProperty
            {
                enumNames             = { "Flip", "Mirror", "None" }, // values will be 0, 1 and 2
                floatType             = FloatType.Enum,
                overrideReferenceName = "_DoubleSidedNormalMode",
                hidden = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
                value = (int)normalMode
            });
            collector.AddShaderProperty(new Vector4ShaderProperty
            {
                overrideReferenceName = "_DoubleSidedConstants",
                hidden = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.UnityPerMaterial,
                value = new Vector4(1, 1, -1, 0)
            });
        }
Esempio n. 3
0
        public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode)
        {
            // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off.
            // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105
            // The user will then need to explicitly disable emissive GI if it is not needed.
            // To be able to automatically disable emission based on the ShaderGraph config when emission is black,
            // we will need a more general way to communicate this to the engine (not directly tied to a material property).
            collector.AddShaderProperty(new ColorShaderProperty()
            {
                overrideReferenceName = "_EmissionColor",
                hidden = true,
                value  = new Color(1.0f, 1.0f, 1.0f, 1.0f)
            });

            base.CollectShaderProperties(collector, generationMode);
        }
Esempio n. 4
0
        public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
        {
            var inputTextureName = unityInputTexture;

            if (generationMode == GenerationMode.Preview && !string.IsNullOrEmpty(unityPreviewInputTexture))
            {
                inputTextureName = unityPreviewInputTexture;
            }

            properties.AddShaderProperty(new TextureShaderProperty()
            {
                displayName           = "Main Texture",
                overrideReferenceName = inputTextureName,
                generatePropertyBlock = false
            });
        }
Esempio n. 5
0
        public static void AddTessellationShaderProperties(PropertyCollector collector, TessellationMode tessellationMode,
                                                           float tessellationFactorMinDistance, float tessellationFactorMaxDistance, float tessellationFactorTriangleSize,
                                                           float tessellationShapeFactor, float tessellationBackFaceCullEpsilon, float tessellationMaxDisplacement)
        {
            collector.AddShaderProperty(new Vector1ShaderProperty
            {
                overrideReferenceName = kTessellationMode,
                floatType             = FloatType.Enum,
                value      = (int)tessellationMode,
                enumNames  = { "None", "Phong" },
                enumValues = { (int)TessellationMode.None, (int)TessellationMode.Phong },
                hidden     = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
            });

            collector.AddFloatProperty(kTessellationFactorMinDistance, tessellationFactorMinDistance, HLSLDeclaration.UnityPerMaterial);
            collector.AddFloatProperty(kTessellationFactorMaxDistance, tessellationFactorMaxDistance, HLSLDeclaration.UnityPerMaterial);
            collector.AddFloatProperty(kTessellationFactorTriangleSize, tessellationFactorTriangleSize, HLSLDeclaration.UnityPerMaterial);
            collector.AddSliderProperty(kTessellationShapeFactor, "Tessellation shape factor", tessellationShapeFactor, new Vector2(0.0f, 1.0f), HLSLDeclaration.UnityPerMaterial);
            collector.AddSliderProperty(kTessellationBackFaceCullEpsilon, "Tessellation back face epsilon", tessellationBackFaceCullEpsilon, new Vector2(-1.0f, 0.0f), HLSLDeclaration.UnityPerMaterial);
            collector.AddFloatProperty(kTessellationMaxDisplacement, tessellationMaxDisplacement, HLSLDeclaration.UnityPerMaterial);
        }
Esempio n. 6
0
        public static void AddBlendingStatesShaderProperties(
            PropertyCollector collector, SurfaceType surface, BlendMode blend, int sortingPriority,
            bool alphaToMask, bool transparentZWrite, TransparentCullMode transparentCullMode,
            OpaqueCullMode opaqueCullMode, CompareFunction zTest,
            bool backThenFrontRendering, bool fogOnTransparent)
        {
            collector.AddFloatProperty("_SurfaceType", (int)surface);
            collector.AddFloatProperty("_BlendMode", (int)blend, HLSLDeclaration.UnityPerMaterial);

            // All these properties values will be patched with the material keyword update
            collector.AddFloatProperty("_SrcBlend", 1.0f);
            collector.AddFloatProperty("_DstBlend", 0.0f);
            collector.AddFloatProperty("_AlphaSrcBlend", 1.0f);
            collector.AddFloatProperty("_AlphaDstBlend", 0.0f);
            collector.AddToggleProperty("_AlphaToMask", alphaToMask);
            collector.AddToggleProperty("_AlphaToMaskInspectorValue", alphaToMask);
            collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? transparentZWrite : true);
            collector.AddToggleProperty(kTransparentZWrite, transparentZWrite);
            collector.AddFloatProperty("_CullMode", (int)CullMode.Back);
            collector.AddIntProperty(kTransparentSortPriority, sortingPriority);
            collector.AddToggleProperty(kEnableFogOnTransparent, fogOnTransparent);
            collector.AddFloatProperty("_CullModeForward", (int)CullMode.Back);
            collector.AddShaderProperty(new Vector1ShaderProperty
            {
                overrideReferenceName = kTransparentCullMode,
                floatType             = FloatType.Enum,
                value      = (int)transparentCullMode,
                enumNames  = { "Front", "Back" },
                enumValues = { (int)TransparentCullMode.Front, (int)TransparentCullMode.Back },
                hidden     = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
            });
            collector.AddShaderProperty(new Vector1ShaderProperty
            {
                overrideReferenceName = kOpaqueCullMode,
                floatType             = FloatType.Enum,
                value                   = (int)opaqueCullMode,
                enumType                = EnumType.CSharpEnum,
                cSharpEnumType          = typeof(OpaqueCullMode),
                hidden                  = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
            });

            // Add ZTest properties:
            collector.AddIntProperty("_ZTestDepthEqualForOpaque", (int)CompareFunction.LessEqual);
            collector.AddShaderProperty(new Vector1ShaderProperty
            {
                overrideReferenceName = kZTestTransparent,
                floatType             = FloatType.Enum,
                value                   = (int)zTest,
                enumType                = EnumType.CSharpEnum,
                cSharpEnumType          = typeof(CompareFunction),
                hidden                  = true,
                overrideHLSLDeclaration = true,
                hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
            });

            collector.AddToggleProperty(kTransparentBackfaceEnable, backThenFrontRendering);
        }