Esempio n. 1
0
        public static void AddBlendingStatesShaderProperties(
            PropertyCollector collector, SurfaceType surface, BlendMode blend, int sortingPriority,
            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(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);
        }
Esempio n. 2
0
        public static void AddStencilShaderProperties(PropertyCollector collector, bool splitLighting, bool receiveSSR, bool recieveSSRTransparent = false)
        {
            BaseLitGUI.ComputeStencilProperties(receiveSSR, splitLighting, out int stencilRef, out int stencilWriteMask,
                                                out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer,
                                                out int stencilRefMV, out int stencilWriteMaskMV
                                                );

            // All these properties values will be patched with the material keyword update
            collector.AddIntProperty("_StencilRef", stencilRef);
            collector.AddIntProperty("_StencilWriteMask", stencilWriteMask);
            // Depth prepass
            collector.AddIntProperty("_StencilRefDepth", stencilRefDepth);             // Nothing
            collector.AddIntProperty("_StencilWriteMaskDepth", stencilWriteMaskDepth); // StencilUsage.TraceReflectionRay
            // Motion vector pass
            collector.AddIntProperty("_StencilRefMV", stencilRefMV);                   // StencilUsage.ObjectMotionVector
            collector.AddIntProperty("_StencilWriteMaskMV", stencilWriteMaskMV);       // StencilUsage.ObjectMotionVector
            // Distortion vector pass
            collector.AddIntProperty("_StencilRefDistortionVec", (int)StencilUsage.DistortionVectors);
            collector.AddIntProperty("_StencilWriteMaskDistortionVec", (int)StencilUsage.DistortionVectors);
            // Gbuffer
            collector.AddIntProperty("_StencilWriteMaskGBuffer", stencilWriteMaskGBuffer);
            collector.AddIntProperty("_StencilRefGBuffer", stencilRefGBuffer);
            collector.AddIntProperty("_ZTestGBuffer", 4);

            collector.AddToggleProperty(kUseSplitLighting, splitLighting);
            collector.AddToggleProperty(kReceivesSSR, receiveSSR);
            collector.AddToggleProperty(kReceivesSSRTransparent, recieveSSRTransparent);
        }
Esempio n. 3
0
        public static void AddStencilShaderProperties(PropertyCollector collector, SystemData systemData, LightingData lightingData, bool splitLighting)
        {
            bool ssrStencil = false;

            if (lightingData != null)
            {
                ssrStencil = systemData.surfaceType == SurfaceType.Opaque ? lightingData.receiveSSR : lightingData.receiveSSRTransparent;
                bool receiveSSROpaque      = lightingData.receiveSSR;
                bool receiveSSRTransparent = lightingData.receiveSSRTransparent;
                bool receiveDecals         = lightingData.receiveDecals;
                bool blendPreserveSpecular = lightingData.blendPreserveSpecular;

                // Don't add those property on Unlit
                collector.AddToggleProperty(kUseSplitLighting, splitLighting);
                collector.AddToggleProperty(kReceivesSSR, receiveSSROpaque);
                collector.AddToggleProperty(kReceivesSSRTransparent, receiveSSRTransparent);
                collector.AddToggleProperty(kEnableBlendModePreserveSpecularLighting, blendPreserveSpecular);
                collector.AddToggleProperty(kSupportDecals, receiveDecals);
            }

            // Configure render state
            BaseLitGUI.ComputeStencilProperties(ssrStencil, splitLighting, out int stencilRef, out int stencilWriteMask,
                                                out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer,
                                                out int stencilRefMV, out int stencilWriteMaskMV
                                                );

            // All these properties values will be patched with the material keyword update
            collector.AddIntProperty("_StencilRef", stencilRef);
            collector.AddIntProperty("_StencilWriteMask", stencilWriteMask);
            // Depth prepass
            collector.AddIntProperty("_StencilRefDepth", stencilRefDepth);             // Nothing
            collector.AddIntProperty("_StencilWriteMaskDepth", stencilWriteMaskDepth); // StencilUsage.TraceReflectionRay
            // Motion vector pass
            collector.AddIntProperty("_StencilRefMV", stencilRefMV);                   // StencilUsage.ObjectMotionVector
            collector.AddIntProperty("_StencilWriteMaskMV", stencilWriteMaskMV);       // StencilUsage.ObjectMotionVector
            // Distortion vector pass
            collector.AddIntProperty("_StencilRefDistortionVec", (int)StencilUsage.DistortionVectors);
            collector.AddIntProperty("_StencilWriteMaskDistortionVec", (int)StencilUsage.DistortionVectors);
            // Gbuffer
            collector.AddIntProperty("_StencilWriteMaskGBuffer", stencilWriteMaskGBuffer);
            collector.AddIntProperty("_StencilRefGBuffer", stencilRefGBuffer);
            collector.AddIntProperty("_ZTestGBuffer", 4);
        }