public void prefix_search_should_base_on_dots()
        {
            var includes = new IncludeCollection();
            includes.Add("Variants.Brands.Types");

            Assert.False(includes.Includes("Variants.Bran"));
        }
Beispiel #2
0
        public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "DepthForwardOnly",
                referenceName = "SHADERPASS_DEPTH_ONLY",
                lightMode = "DepthForwardOnly",
                useInPreview = true,

                // Collections
                requiredFields = GenerateRequiredFields(),
                renderStates = CoreRenderStates.DepthOnly,
                pragmas = CorePragmas.DotsInstancedInV2Only,
                defines = supportLighting ? CoreDefines.DepthMotionVectors : null,
                keywords = CoreKeywords.DepthMotionVectorsNoNormal,
                includes = GenerateIncludes(),
            });

            FieldCollection GenerateRequiredFields()
            {
                return(new FieldCollection()
                {
                    HDStructFields.AttributesMesh.normalOS,
                    HDStructFields.AttributesMesh.tangentOS,
                    HDStructFields.AttributesMesh.uv0,
                    HDStructFields.AttributesMesh.uv1,
                    HDStructFields.AttributesMesh.color,
                    HDStructFields.AttributesMesh.uv2,
                    HDStructFields.AttributesMesh.uv3,
                    HDStructFields.FragInputs.tangentToWorld,
                    HDStructFields.FragInputs.positionRWS,
                    HDStructFields.FragInputs.texCoord1,
                    HDStructFields.FragInputs.texCoord2,
                    HDStructFields.FragInputs.texCoord3,
                    HDStructFields.FragInputs.color,
                });
            }

            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.kShaderGraphFunctions, IncludeLocation.Pregraph);
                includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph);

                return(includes);
            }
        }
        public List <T> ToList(Query <T> query)
        {
            var items    = ToLocalQuery(query).ToList();
            var includes = new IncludeCollection(query.Includes);

            return(items.Select(it => Map(it, includes)).ToList());
        }
Beispiel #4
0
        public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "TransparentDepthPostpass",
                referenceName = "SHADERPASS_DEPTH_ONLY",
                lightMode = "TransparentDepthPostpass",
                useInPreview = true,

                validPixelBlocks = new BlockFieldDescriptor[]
                {
                    BlockFields.SurfaceDescription.Alpha,
                    HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass,
                    HDBlockFields.SurfaceDescription.DepthOffset,
                },

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

            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);
            }

            RenderStateCollection GenerateRenderState()
            {
                var renderState = new RenderStateCollection
                {
                    { RenderState.Blend(Blend.One, Blend.Zero) },
                    { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) },
                    { RenderState.ZWrite(ZWrite.On) },
                    { RenderState.ColorMask("ColorMask 0") },
                };

                return(renderState);
            }
        }
Beispiel #5
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);
            }
Beispiel #6
0
        public void prefix_search_should_base_on_dots()
        {
            var includes = new IncludeCollection();

            includes.Add("Variants.Brands.Types");

            Assert.False(includes.Includes("Variants.Bran"));
        }
Beispiel #7
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);
            }
        }
Beispiel #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);
            }
        }
        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]);
        }
        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"));
        }
Beispiel #11
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]);
        }
        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"));
        }
Beispiel #13
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"));
        }
Beispiel #14
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"));
        }
Beispiel #15
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"));
        }
        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);
        }
Beispiel #17
0
        static public PassDescriptor GenerateShadowCaster(bool supportLighting)
        {
            return(new PassDescriptor()
            {
                // Definition
                displayName = "ShadowCaster",
                referenceName = "SHADERPASS_SHADOWS",
                lightMode = "ShadowCaster",
                useInPreview = false,

                validPixelBlocks = new BlockFieldDescriptor[]
                {
                    BlockFields.SurfaceDescription.Alpha,
                    BlockFields.SurfaceDescription.AlphaClipThreshold,
                    HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow,
                    HDBlockFields.SurfaceDescription.DepthOffset,
                },

                // Collections
                renderStates = CoreRenderStates.ShadowCaster,
                pragmas = CorePragmas.DotsInstancedInV2Only,
                keywords = CoreKeywords.HDBase,
                includes = GenerateIncludes(),
            });

            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);
            }
        }
Beispiel #18
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);
        }
Beispiel #19
0
        public static PassDescriptor GenerateMETA(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "META",
                referenceName = "SHADERPASS_LIGHT_TRANSPORT",
                lightMode = "META",
                useInPreview = false,

                // We don't need any vertex inputs on meta pass:
                validVertexBlocks = new BlockFieldDescriptor[0],

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

            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.kPassLightTransport, IncludeLocation.Postgraph);

                return(includes);
            }
        }
Beispiel #20
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);
            }
        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;
        }
Beispiel #22
0
        public static PassDescriptor GenerateSceneSelection(bool supportLighting)
        {
            return(new PassDescriptor
            {
                // Definition
                displayName = "SceneSelectionPass",
                referenceName = "SHADERPASS_DEPTH_ONLY",
                lightMode = "SceneSelectionPass",
                useInPreview = false,

                // Collections
                renderStates = CoreRenderStates.SceneSelection,
                pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync,
                defines = CoreDefines.SceneSelection,
                keywords = CoreKeywords.HDBase,
                includes = GenerateIncludes(),
            });

            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);
            }
        }
        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);
        }
Beispiel #24
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);
            }
Beispiel #25
0
 public MappingContext(LocalApiContext apiContext, IncludeCollection includes)
 {
     ApiContext = apiContext;
     Includes = includes ?? new IncludeCollection();
     VisitedObjects = new HashSet<ObjectReference>();
 }
Beispiel #26
0
 public static object Map(object source, Type sourceType, Type targetType, LocalApiContext apiContext, IncludeCollection includes)
 {
     return(Map(source, Activator.CreateInstance(targetType), sourceType, targetType, apiContext, includes));
 }
Beispiel #27
0
 public static TTarget Map <TSource, TTarget>(TSource source, TTarget target, LocalApiContext apiContext, IncludeCollection includes)
 {
     return((TTarget)Map(source, target, typeof(TSource), typeof(TTarget), apiContext, includes));
 }
        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"));
        }
Beispiel #29
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);
            }
        }
Beispiel #30
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);
            }
        }
 protected virtual T Map(TSource source, IncludeCollection includes)
 {
     return(ObjectMapper.Map <TSource, T>(source, ApiContext, includes));
 }
Beispiel #32
0
 public MappingContext(LocalApiContext apiContext, IncludeCollection includes)
 {
     ApiContext     = apiContext;
     Includes       = includes ?? new IncludeCollection();
     VisitedObjects = new HashSet <ObjectReference>();
 }
Beispiel #33
0
        public static object Map(object source, object target, Type sourceType, Type targetType, LocalApiContext apiContext, IncludeCollection includes)
        {
            var mapper = GetMapper(sourceType, targetType);

            return(mapper.Map(source, target, sourceType, targetType, null, new MappingContext(apiContext, includes)));
        }
Beispiel #34
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);
            }
        }
Beispiel #35
0
 public static TTarget Map <TSource, TTarget>(TSource source, LocalApiContext apiContext, IncludeCollection includes)
 {
     return(Map <TSource, TTarget>(source, (TTarget)Activator.CreateInstance(typeof(TTarget)), apiContext, includes));
 }
            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);
            }
Beispiel #37
0
 public MappingContext(IncludeCollection includes)
     : this(null, includes)
 {
 }
            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);
            }
Beispiel #39
0
 public MappingContext(IncludeCollection includes)
     : this(null, includes)
 {
 }
            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);
            }