Пример #1
0
        public void should_discard_duplicates()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants.Prices.Types");
            includes.Add("Variants");
            includes.Add("Variants.Prices");
            includes.Add("Variants.Prices.Types");

            var paths = includes.ToList();
            Assert.Equal(1, paths.Count);
            Assert.Equal("Variants.Prices.Types", paths[0]);
        }
Пример #2
0
        public void multi_items_with_same_prefix()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants.Brands.Suppliers");
            includes.Add("Variants.Brands.Types");
            includes.Add("Variants.Categories");

            Assert.True(includes.Includes("Variants"));
            Assert.True(includes.Includes("Variants.Brands"));
            Assert.True(includes.Includes("Variants.Categories"));
            Assert.True(includes.Includes("Variants.Brands.Suppliers"));
            Assert.True(includes.Includes("Variants.Brands.Types"));
        }
Пример #3
0
        public void can_do_exact_search()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants");
            includes.Add("Categories");

            Assert.True(includes.Includes("Variants"));
            Assert.True(includes.Includes("Categories"));

            includes = new IncludeCollection();
            includes.Add("Variants.Brand");

            Assert.True(includes.Includes("Variants.Brand"));
        }
Пример #4
0
        public void prefix_search_should_base_on_dots()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants.Brands.Types");

            Assert.False(includes.Includes("Variants.Bran"));
        }
Пример #5
0
        public void can_enumerate_all_paths()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants");
            includes.Add("Categories.Types.Suppliers");
            includes.Add("Variants.Prices.Types");
            includes.Add("Brands.Categories");
            includes.Add("OrderItems");

            var paths = includes.ToList();
            Assert.Equal(4, paths.Count);
            Assert.Contains("Variants.Prices.Types", paths);
            Assert.Contains("Categories.Types.Suppliers", paths);
            Assert.Contains("Brands.Categories", paths);
            Assert.Contains("OrderItems", paths);
        }
Пример #6
0
        public override object Map(object source, object target, Type sourceType, Type targetType, string prefix, MappingContext context)
        {
            var model = base.Map(source, target, sourceType, targetType, prefix, context) as ShoppingCartItem;
            var cartItem = source as Kooboo.Commerce.Carts.ShoppingCartItem;

            // Product
            var mapper = GetMapperOrDefault(typeof(Kooboo.Commerce.Products.Product), typeof(Product));
            var propPath = prefix + "Product";
            var includes = new IncludeCollection();
            foreach (var each in context.Includes)
            {
                if (each.StartsWith(propPath) && each.Length > propPath.Length && each[propPath.Length] == '.')
                {
                    includes.Add(each.Substring(propPath.Length + 1));
                }
            }

            model.Product = mapper.Map(cartItem.ProductVariant.Product, new Product(), null, new MappingContext(context.ApiContext, includes)) as Product;

            return model;
        }
Пример #7
0
        public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "TransparentDepthPrepass",
                referenceName = "SHADERPASS_DEPTH_ONLY",
                lightMode = "TransparentDepthPrepass",
                useInPreview = true,

                validPixelBlocks = new BlockFieldDescriptor[]
                {
                    BlockFields.SurfaceDescription.Alpha,
                    HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass,
                    HDBlockFields.SurfaceDescription.DepthOffset,
                    BlockFields.SurfaceDescription.NormalTS,
                    BlockFields.SurfaceDescription.NormalWS,
                    BlockFields.SurfaceDescription.NormalOS,
                    BlockFields.SurfaceDescription.Smoothness,
                },

                // Collections
                requiredFields = TransparentDepthPrepassFields,
                renderStates = GenerateRenderState(),
                pragmas = CorePragmas.DotsInstancedInV1AndV2,
                defines = GenerateDefines(),
                keywords = CoreKeywords.HDBase,
                includes = GenerateIncludes(),
            });

            DefineCollection GenerateDefines()
            {
                var defines = new DefineCollection {
                    { RayTracingNode.GetRayTracingKeyword(), 0 }
                };

                if (supportLighting)
                {
                    defines.Add(CoreKeywordDescriptors.WriteNormalBufferDefine, 1, new FieldCondition(HDFields.DisableSSRTransparent, false));
                }

                return(defines);
            }

            RenderStateCollection GenerateRenderState()
            {
                var renderState = new RenderStateCollection
                {
                    { RenderState.Blend(Blend.One, Blend.Zero) },
                    { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) },
                    { RenderState.ZWrite(ZWrite.On) },
                    { RenderState.Stencil(new StencilDescriptor()
                        {
                            WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth,
                            Ref       = CoreRenderStates.Uniforms.stencilRefDepth,
                            Comp      = "Always",
                            Pass      = "******",
                        }) },
                };

                if (!supportLighting)
                {
                    renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal]"));
                    renderState.Add(RenderState.ColorMask("ColorMask 0 1"));
                }

                return(renderState);
            }

            IncludeCollection GenerateIncludes()
            {
                var includes = new IncludeCollection();

                includes.Add(CoreIncludes.CorePregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.CoreUtility);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph);

                return(includes);
            }
        }
Пример #8
0
        public static PassDescriptor GenerateBackThenFront(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "TransparentBackface",
                referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT",
                lightMode = "TransparentBackface",
                useInPreview = true,

                // Collections
                requiredFields = CoreRequiredFields.LitMinimal,
                renderStates = CoreRenderStates.TransparentBackface,
                pragmas = CorePragmas.DotsInstancedInV1AndV2,
                defines = CoreDefines.Forward,
                keywords = CoreKeywords.Forward,
                includes = GenerateIncludes(),
            });

            IncludeCollection GenerateIncludes()
            {
                var includes = new IncludeCollection();

                includes.Add(CoreIncludes.CorePregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kLighting, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kLightLoop, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.CoreUtility);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph);
                }
                else
                {
                    includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph);
                }

                return(includes);
            }
        }
Пример #9
0
        public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "ForwardOnly",
                referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT",
                lightMode = "ForwardOnly",
                useInPreview = true,

                // Collections
                requiredFields = supportLighting ? CoreRequiredFields.LitFull : null,
                renderStates = CoreRenderStates.Forward,
                pragmas = CorePragmas.DotsInstancedInV2Only,
                defines = supportLighting ? CoreDefines.Forward : null,
                keywords = supportLighting ? CoreKeywords.Forward : UnlitForwardKeywords,
                includes = GenerateIncludes(),

                virtualTextureFeedback = supportLighting ? false : true,
            });

            IncludeCollection GenerateIncludes()
            {
                var includes = new IncludeCollection();

                includes.Add(CoreIncludes.CorePregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kLighting, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kLightLoop, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.CoreUtility);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph);
                }
                else
                {
                    includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph);
                }

                return(includes);
            }
        }
Пример #10
0
        public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool supportForward)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "MotionVectors",
                referenceName = "SHADERPASS_MOTION_VECTORS",
                lightMode = "MotionVectors",
                useInPreview = false,

                // Collections
                requiredFields = CoreRequiredFields.LitFull,
                renderStates = GenerateRenderState(),
                defines = GenerateDefines(),
                pragmas = CorePragmas.DotsInstancedInV2Only,
                keywords = GenerateKeywords(),
                includes = GenerateIncludes(),
            });

            DefineCollection GenerateDefines()
            {
                if (!supportLighting)
                {
                    return(null);
                }

                var defines = new DefineCollection
                {
                    { RayTracingNode.GetRayTracingKeyword(), 0 },
                };

                //  #define WRITE_NORMAL_BUFFER for forward
                if (supportForward)
                {
                    defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1);
                }

                return(defines);
            }

            RenderStateCollection GenerateRenderState()
            {
                var renderState = new RenderStateCollection();

                renderState.Add(CoreRenderStates.MotionVectors);

                if (!supportLighting)
                {
                    renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1"));
                    renderState.Add(RenderState.ColorMask("ColorMask 0 2"));
                }

                return(renderState);
            }

            KeywordCollection GenerateKeywords()
            {
                var keywords = new KeywordCollection
                {
                    { CoreKeywords.HDBase },
                    { CoreKeywordDescriptors.WriteMsaaDepth },
                    { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) },
                };

                // #pragma multi_compile _ WRITE_NORMAL_BUFFER for deferred
                if (supportLighting && !supportForward)
                {
                    keywords.Add(CoreKeywordDescriptors.WriteNormalBuffer);
                }

                return(keywords);
            }

            IncludeCollection GenerateIncludes()
            {
                var includes = new IncludeCollection();

                includes.Add(CoreIncludes.CorePregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.CoreUtility);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph);

                return(includes);
            }
        }
Пример #11
0
        public static PassDescriptor GenerateDistortionPass(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "DistortionVectors",
                referenceName = "SHADERPASS_DISTORTION",
                lightMode = "DistortionVectors",
                useInPreview = true,

                // Collections
                renderStates = GenerateRenderState(),
                pragmas = CorePragmas.DotsInstancedInV1AndV2,
                defines = CoreDefines.ShaderGraphRaytracingHigh,
                keywords = CoreKeywords.HDBase,
                includes = GenerateIncludes(),
            });

            RenderStateCollection GenerateRenderState()
            {
                return(new RenderStateCollection
                {
                    { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) },
                    { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) },
                    { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) },
                    { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) },
                    { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) },
                    { RenderState.ZWrite(ZWrite.Off) },
                    { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) },
                    { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) },
                    { RenderState.Stencil(new StencilDescriptor()
                        {
                            WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec,
                            Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec,
                            Comp = "Always",
                            Pass = "******",
                        }) }
                });
            }

            IncludeCollection GenerateIncludes()
            {
                var includes = new IncludeCollection();

                includes.Add(CoreIncludes.CorePregraph);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.CoreUtility);
                if (supportLighting)
                {
                    includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph);
                    includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph);
                }
                includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph);

                return(includes);
            }
        }
Пример #12
0
            public void can_map_one_level_nested_object()
            {
                var source = new SourceProduct
                {
                    Id = 5,
                    Name = "Product name",
                    Brand = new SourceBrand { Id = 10, Name = "Nike" }
                };

                var mapper = new DefaultObjectMapper();
                var includes = new IncludeCollection();
                includes.Add("Brand");

                var context = new MappingContext(includes);
                var target = mapper.Map(source, new TargetProduct(), typeof(SourceProduct), typeof(TargetProduct), null, context) as TargetProduct;

                Assert.NotNull(target.Brand);
                Assert.Equal(10, target.Brand.Id);
                Assert.Equal("Nike", target.Brand.Name);
            }
Пример #13
0
            public void can_map_multi_level_nested_objects()
            {
                var source = new SourceOrderItem
                {
                    Id = 1,
                    Product = new SourceProduct
                    {
                        Id = 11,
                        Name = "Product 1",
                        Brand = new SourceBrand { Id = 21, Name = "Brand 1" }
                    }
                };

                var mapper = new DefaultObjectMapper();
                var includes = new IncludeCollection();
                includes.Add("Product.Brand");

                var context = new MappingContext(includes);
                var target = mapper.Map(source, new TargetOrderItem(), typeof(SourceOrderItem), typeof(TargetOrderItem), null, context) as TargetOrderItem;

                Assert.Equal(1, target.Id);
                Assert.NotNull(target.Product);
                Assert.Equal(11, target.Product.Id);
                Assert.NotNull(target.Product.Brand);
                Assert.Equal(21, target.Product.Brand.Id);
                Assert.Equal("Brand 1", target.Product.Brand.Name);
            }
Пример #14
0
            public void can_handle_null_nested_object()
            {
                var source = new SourceProduct
                {
                    Id = 1024,
                    Name = "1024 Product"
                };

                var mapper = new DefaultObjectMapper();
                var includes = new IncludeCollection();
                includes.Add("Brand");

                var context = new MappingContext(new LocalApiContext(new ApiContext(), null), includes);
                var target = mapper.Map(source, new TargetProduct(), typeof(SourceProduct), typeof(TargetProduct), null, context) as TargetProduct;

                Assert.Equal(1024, target.Id);
                Assert.Equal("1024 Product", target.Name);
                Assert.Null(target.Brand);
            }
Пример #15
0
        public void should_do_prefix_search()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants.Brand");

            Assert.True(includes.Includes("Variants"));
            Assert.False(includes.Includes("BVariants"));

            includes = new IncludeCollection();
            includes.Add("Variants.Brand.Supplier");
            Assert.True(includes.Includes("Variants"));
            Assert.True(includes.Includes("Variants.Brand"));
            Assert.True(includes.Includes("Variants.Brand.Supplier"));
        }