public void Visit(MaterialGeneratorContext context)
        {
            var alpha = Alpha ?? new ComputeFloat(0.5f);
            var tint = Tint ?? new ComputeColor(Color.White);

            // Use pre-multiplied alpha to support both additive and alpha blending
            var blendDesc = new BlendStateDescription(Blend.One, Blend.InverseSourceAlpha);
            context.Material.HasTransparency = true;
            context.Parameters.Set(Effect.BlendStateKey, BlendState.NewFake(blendDesc));

            var alphaColor = alpha.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseSpecularAlphaBlendMap, MaterialKeys.DiffuseSpecularAlphaBlendValue, Color.White));

            var mixin = new ShaderMixinSource();
            mixin.Mixins.Add(new ShaderClassSource("ComputeColorMaterialAlphaBlend"));
            mixin.AddComposition("color", alphaColor);

            context.SetStream(MaterialShaderStage.Pixel, AlphaBlendStream.Stream, MaterialStreamType.Float2, mixin);
            context.SetStream(AlphaBlendColorStream.Stream, tint, MaterialKeys.AlphaBlendColorMap, MaterialKeys.AlphaBlendColorValue, Color.White);

            if (!context.Tags.Get(HasFinalCallback))
            {
                context.Tags.Set(HasFinalCallback, true);
                context.AddFinalCallback(MaterialShaderStage.Pixel, AddDiffuseSpecularAlphaBlendColor);
            }
        }
        private void AddSpecularHighlightsShiftNoiseTexture(MaterialGeneratorContext context, ShaderMixinSource shaderSource)
        {
            MaterialComputeColorKeys materialComputeColorKeys = new MaterialComputeColorKeys(PrimarySpecularReflectionNoiseTexture,
                                                                                             PrimarySpecularReflectionNoiseValue);
            var computeColorSource = HairSpecularHighlightsShiftNoise.GenerateShaderSource(context, materialComputeColorKeys);

            shaderSource.AddComposition("SpecularHighlightsShiftNoiseTexture", computeColorSource);
        }
Exemplo n.º 3
0
        public ShaderSource GetMarchingShader(int attrID)
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(new ShaderClassSource("VoxelMarchSetHemisphere6"));
            mixin.AddComposition("Marcher", Marcher.GetMarchingShader(attrID));
            return(mixin);
        }
Exemplo n.º 4
0
        virtual public ShaderSource GetSamplingShader()
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(Sampler);
            mixin.AddComposition("storage", storageTex.GetSamplingShader());
            return(mixin);
        }
Exemplo n.º 5
0
        public ShaderSource GetShader()
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(source);
            mixin.AddComposition("layout", VoxelLayout.GetShaderFloat4(Modifiers));
            return(mixin);
        }
Exemplo n.º 6
0
        public override ShaderSource GetVoxelizationShader()
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(source);
            mixin.AddComposition("layout", VoxelLayout.GetVoxelizationShader(Modifiers));
            return(mixin);
        }
Exemplo n.º 7
0
        public void Apply(ShaderMixinSource mixin)
        {
            var writermixin = new ShaderMixinSource();

            writermixin.Mixins.Add((ShaderClassSource)TempStorageFormat.GetShader());
            writermixin.AddComposition("writer", Filter.GetShader());
            mixin.AddComposition("writer", writermixin);
        }
Exemplo n.º 8
0
        private void AddSecondarySpecularGlintsNoiseTexture(MaterialGeneratorContext context, ShaderMixinSource shaderSource)
        {
            MaterialComputeColorKeys materialComputeColorKeys = new MaterialComputeColorKeys(SecondarySpecularReflectionNoiseTexture,
                                                                                             SecondarySpecularReflectionNoiseValue);
            var computeColorSource = HairSecondarySpecularGlintsNoise.GenerateShaderSource(context, materialComputeColorKeys);

            shaderSource.AddComposition("SecondarySpecularGlintsNoiseTexture", computeColorSource);
        }
        protected override void GenerateShaderCompositions(MaterialGeneratorContext context, ShaderMixinSource shaderSource)
        {
            base.GenerateShaderCompositions(context, shaderSource);

            if (RampFunction != null)
            {
                shaderSource.AddComposition("celLightFunction", RampFunction.Generate(context));
            }
        }
Exemplo n.º 10
0
        public void TestRenaming()
        {
            var color1Mixin = new ShaderClassSource("ComputeColorFixed", "Material.DiffuseColorValue");
            var color2Mixin = new ShaderClassSource("ComputeColorFixed", "Material.SpecularColorValue");
            
            var compMixin = new ShaderMixinSource();
            compMixin.Mixins.Add(new ShaderClassSource("ComputeColorMultiply"));
            compMixin.AddComposition("color1", color1Mixin);
            compMixin.AddComposition("color2", color2Mixin);

            var mixinSource = new ShaderMixinSource { Name = "testRenaming", UsedParameters = MixinParameters };
            mixinSource.Mixins.Add(new ShaderClassSource("ShadingBase"));
            mixinSource.Mixins.Add(new ShaderClassSource("AlbedoFlatShading"));
            mixinSource.AddComposition("albedoDiffuse", compMixin);

            var byteCode = Compiler.Compile(mixinSource, new CompilerParameters());
            Assert.IsNotNull(byteCode);
        }
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            // TODO: Look through the compositions and don't add the discard mixin if it has already been added?
            // TODO: That doesn't seem to work well because the diffuse shader doesn't get recreated when the specular one is being recreated... unless I'm wrong about that.

            var shaderSource = new ShaderMixinSource();

            shaderSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceShadingSpecularHair", (int)ShadingModel, DebugRenderPasses));

            shaderSource.AddComposition("hairLightAttenuationFunction", LightAttenuationFunction.Generate(context));
            shaderSource.AddComposition("hairDirectionFunction", HairDirectionFunction.Generate(context));
            shaderSource.AddComposition("hairShadowingFunction", HairShadowingFunction.Generate(context));
            shaderSource.AddComposition("environmentFunction", Environment.Generate(context));

            AddSpecularHighlightsShiftNoiseTexture(context, shaderSource);
            AddSecondarySpecularGlintsNoiseTexture(context, shaderSource);

            HairShared.SetMaterialPassParameters(context, shaderSource, AlphaThreshold); // Set the rendering parameters and generate the pass-dependent compositions.

            // Set the additional parameters used only in the specular shading model:
            var parameters = context.MaterialPass.Parameters;

            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairScalesAngle, MathUtil.DegreesToRadians(ScalesAngle));
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularShiftRatio, SpecularShiftRatio);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularColor1, SpecularColor1);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularColor2, SpecularColor2);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularExponent1, SpecularExponent1);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularExponent2, SpecularExponent2);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularScale1, SpecularScale1);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairSpecularScale2, SpecularScale2);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairShiftNoiseScale, ShiftNoiseScale);
            parameters.Set(MaterialSurfaceShadingSpecularHairKeys.HairGlintsNoiseStrength, GlintsNoiseStrength);
            parameters.Set(MaterialKeys.UsePixelShaderWithDepthPass, true); // Indicates that the material requries the full pixel shader durin the depth-only passes (Z prepass or shadow map rendering).

            if (DebugRenderPasses)
            {
                parameters.Set(MaterialHairSharedKeys.PassID, context.PassIndex);   // For debugging the different hair passes.
            }

            var shaderBuilder = context.AddShading(this);

            shaderBuilder.LightDependentSurface = shaderSource;
        }
Exemplo n.º 12
0
        private void AddMetalFlakesGlossiness(MaterialGeneratorContext context)
        {
            var surfaceToEyeDistance = LODDistance.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue, Color.White));

            // Metal Flakes Glossiness Feature
            context.UseStream(MaterialShaderStage.Pixel, "matGlossiness");

            var baseGlossinessComputeColorMap = BasePaintGlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));

            var mixinGlossiness = new ShaderMixinSource();

            // Computes glossiness factor for the metal flakes layer (based on the eye to surface distance and the base glossiness value)
            mixinGlossiness.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMapMetalFlakes", BasePaintGlossinessInvert));

            mixinGlossiness.AddComposition("glossinessMap", baseGlossinessComputeColorMap);
            mixinGlossiness.AddComposition("surfaceToEyeDistanceFactor", surfaceToEyeDistance);

            context.AddShaderSource(MaterialShaderStage.Pixel, mixinGlossiness);
        }
Exemplo n.º 13
0
        private void AddMetalFlakesDiffuse(MaterialGeneratorContext context)
        {
            var surfaceToEyeDistance = LODDistance.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue, Color.White));

            // Diffuse Feature (interpolated by the 'regular' diffuse map)
            var metalFlakesComputeColorSource = MetalFlakesDiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));

            var mixinDiffuse = new ShaderMixinSource();

            // Diffuse uses a custom shader (to perform the interpolation)
            mixinDiffuse.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuseMetalFlakes"));

            mixinDiffuse.AddComposition("diffuseMap", metalFlakesComputeColorSource);
            mixinDiffuse.AddComposition("surfaceToEyeDistanceFactor", surfaceToEyeDistance);

            context.UseStream(MaterialShaderStage.Pixel, MaterialDiffuseMapFeature.DiffuseStream.Stream);
            context.UseStream(MaterialShaderStage.Pixel, MaterialDiffuseMapFeature.ColorBaseStream.Stream);

            context.AddShaderSource(MaterialShaderStage.Pixel, mixinDiffuse);
        }
        public override ShaderSource GetSamplingShader()
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(sampler);
            if (CoverageTex != null)
            {
                mixin.AddComposition("storage", CoverageTex.GetSamplingShader());
            }
            return(mixin);
        }
Exemplo n.º 15
0
        // TODO Quantify/clean all the functions
        private void AddBaseDiffuse(MaterialGeneratorContext context)
        {
            var computeColorDiffuse = BasePaintDiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
            var mixinBaseDiffuse    = new ShaderMixinSource();

            mixinBaseDiffuse.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
            mixinBaseDiffuse.AddComposition("diffuseMap", computeColorDiffuse);
            context.UseStream(MaterialShaderStage.Pixel, MaterialDiffuseMapFeature.DiffuseStream.Stream);
            context.UseStream(MaterialShaderStage.Pixel, MaterialDiffuseMapFeature.ColorBaseStream.Stream);
            context.AddShaderSource(MaterialShaderStage.Pixel, mixinBaseDiffuse);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Build the ShaderMixinSource to evaluate the binaryNode.
        /// </summary>
        /// <param name="binaryNode">The MaterialBinaryNode binaryNode used as source to find the ShaderMixinSource.</param>
        /// <returns>The corresponding ShaderMixinSource.</returns>
        private ShaderSource GetShaderSource(MaterialBinaryNode binaryNode)
        {
            var leftShaderSource  = GetShaderSource(binaryNode.LeftChild);
            var rightShaderSource = GetShaderSource(binaryNode.RightChild);

            var shaderSource = new ShaderClassSource(GetCorrespondingShaderSourceName(binaryNode.Operand));
            var mixin        = new ShaderMixinSource();

            mixin.Mixins.Add(shaderSource);
            if (leftShaderSource != null)
            {
                mixin.AddComposition(BackgroundCompositionName, leftShaderSource);
            }
            if (binaryNode.Operand != MaterialBinaryOperand.None && binaryNode.Operand != MaterialBinaryOperand.Opaque && rightShaderSource != null)
            {
                mixin.AddComposition(ForegroundCompositionName, rightShaderSource);
            }

            return(mixin);
        }
Exemplo n.º 17
0
        private void AddClearCoatGlossinessMap(MaterialGeneratorContext context)
        {
            // Glossiness Feature
            context.UseStream(MaterialShaderStage.Pixel, "matGlossiness");
            var clearCoatGlossinessComputeColorMap = ClearCoatGlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));
            var mixinGlossiness = new ShaderMixinSource();

            mixinGlossiness.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMap", ClearCoatGlossinessInvert));
            mixinGlossiness.AddComposition("glossinessMap", clearCoatGlossinessComputeColorMap);
            context.AddShaderSource(MaterialShaderStage.Pixel, mixinGlossiness);
        }
Exemplo n.º 18
0
        public override ShaderSource GenerateShaderSource(ShaderGeneratorContext context, MaterialComputeColorKeys baseKeys)
        {
            var leftShaderSource  = LeftChild?.GenerateShaderSource(context, baseKeys);
            var rightShaderSource = RightChild?.GenerateShaderSource(context, baseKeys);

            var shaderSource = new ShaderClassSource(GetCorrespondingShaderSourceName(Operator));
            var mixin        = new ShaderMixinSource();

            mixin.Mixins.Add(shaderSource);
            if (leftShaderSource != null)
            {
                mixin.AddComposition(BackgroundCompositionName, leftShaderSource);
            }
            if (rightShaderSource != null)
            {
                mixin.AddComposition(ForegroundCompositionName, rightShaderSource);
            }

            return(mixin);
        }
Exemplo n.º 19
0
 public void Visit(MaterialGeneratorContext context)
 {
     if (MetalnessMap != null)
     {
         var computeColorSource = MetalnessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.MetalnessMap, MaterialKeys.MetalnessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceMetalness"));
         mixin.AddComposition("metalnessMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, "matSpecular");
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
 public void Visit(MaterialGeneratorContext context)
 {
     if (MetalnessMap != null)
     {
         var computeColorSource = MetalnessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.MetalnessMap, MaterialKeys.MetalnessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceMetalness"));
         mixin.AddComposition("metalnessMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, "matSpecular");
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
Exemplo n.º 21
0
        public void TestRenaming()
        {
            var color1Mixin = new ShaderClassSource("ComputeColorFixed", "Material.DiffuseColorValue");
            var color2Mixin = new ShaderClassSource("ComputeColorFixed", "Material.SpecularColorValue");

            var compMixin = new ShaderMixinSource();

            compMixin.Mixins.Add(new ShaderClassSource("ComputeColorMultiply"));
            compMixin.AddComposition("color1", color1Mixin);
            compMixin.AddComposition("color2", color2Mixin);

            var mixinSource = new ShaderMixinSource();

            mixinSource.Mixins.Add(new ShaderClassSource("ShadingBase"));
            mixinSource.Mixins.Add(new ShaderClassSource("AlbedoFlatShading"));
            mixinSource.AddComposition("albedoDiffuse", compMixin);

            var byteCode = Compiler.Compile(mixinSource, "testRenaming", MixinParameters, null, null, ResultLogger);

            Assert.IsNotNull(byteCode);
        }
Exemplo n.º 22
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            var shaderSource = new ShaderMixinSource();

            shaderSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceShadingDiffuseCelShading", IsEnergyConservative, FakeNDotL));
            if (RampFunction != null)
            {
                shaderSource.AddComposition("celLightFunction", RampFunction.Generate(context));
            }

            context.AddShading(this, shaderSource);
        }
 public override void VisitFeature(MaterialGeneratorContext context)
 {
     if (GlossinessMap != null)
     {
         context.UseStream(MaterialShaderStage.Pixel, GlossinessStream.Stream);
         var computeColorSource = GlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMap", Invert));
         mixin.AddComposition("glossinessMap", computeColorSource);
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
Exemplo n.º 24
0
        private void AddClearCoatMetalnessMap(MaterialGeneratorContext context)
        {
            // Metalness Feature
            var clearCoatMetalness = ClearCoatMetalnessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.MetalnessMap, MaterialKeys.MetalnessValue));

            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceMetalness"));
            mixin.AddComposition("metalnessMap", clearCoatMetalness);
            context.UseStream(MaterialShaderStage.Pixel, "matSpecular");
            context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
        }
 public override void VisitFeature(MaterialGeneratorContext context)
 {
     if (GlossinessMap != null)
     {
         context.UseStream(MaterialShaderStage.Pixel, GlossinessStream.Stream);
         var computeColorSource = GlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMap", Invert));
         mixin.AddComposition("glossinessMap", computeColorSource);
         context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
     }
 }
Exemplo n.º 26
0
 public void Visit(MaterialGeneratorContext context)
 {
     if (DiffuseMap != null)
     {
         var computeColorSource = DiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
         mixin.AddComposition("diffuseMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, DiffuseStream.Stream);
         context.UseStream(MaterialShaderStage.Pixel, ColorBaseStream.Stream);
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
        protected virtual void GenerateShaderCompositions(MaterialGeneratorContext context, ShaderMixinSource shaderSource)
        {
            if (Fresnel != null)
            {
                shaderSource.AddComposition("fresnelFunction", Fresnel.Generate(context));
            }

            if (Visibility != null)
            {
                shaderSource.AddComposition("geometricShadowingFunction", Visibility.Generate(context));
            }

            if (NormalDistribution != null)
            {
                shaderSource.AddComposition("normalDistributionFunction", NormalDistribution.Generate(context));
            }

            if (Environment != null)
            {
                shaderSource.AddComposition("environmentFunction", Environment.Generate(context));
            }
        }
Exemplo n.º 28
0
 public void Visit(MaterialGeneratorContext context)
 {
     if (DiffuseMap != null)
     {
         var computeColorSource = DiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
         mixin.AddComposition("diffuseMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, DiffuseStream.Stream);
         context.UseStream(MaterialShaderStage.Pixel, ColorBaseStream.Stream);
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            var shaderSource = new ShaderMixinSource();

            shaderSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceShadingDiffuseHair", IsEnergyConservative, (int)ShadingModel, DebugRenderPasses));

            shaderSource.AddComposition("hairLightAttenuationFunction", LightAttenuationFunction.Generate(context));
            shaderSource.AddComposition("hairDirectionFunction", HairDirectionFunction.Generate(context));
            shaderSource.AddComposition("hairShadowingFunction", HairShadowingFunction.Generate(context));

            HairShared.SetMaterialPassParameters(context, shaderSource, AlphaThreshold); // Set the rendering parameters and generate the pass-dependent compositions.

            context.Parameters.Set(MaterialKeys.UsePixelShaderWithDepthPass, true);      // Indicates that material requries using the pixel shader stage during the depth-only pass (Z prepass or shadow map rendering).

            if (DebugRenderPasses)
            {
                context.Parameters.Set(MaterialHairSharedKeys.PassID, context.PassIndex);   // For debugging the different hair passes.
            }

            var shaderBuilder = context.AddShading(this);

            shaderBuilder.LightDependentSurface = shaderSource;
        }
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            var shaderSource = new ShaderMixinSource();

            shaderSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceShadingSpecularMicrofacet"));

            if (Fresnel != null)
            {
                shaderSource.AddComposition("fresnelFunction", Fresnel.Generate());
            }

            if (Visibility != null)
            {
                shaderSource.AddComposition("geometricShadowingFunction", Visibility.Generate());
            }

            if (NormalDistribution != null)
            {
                shaderSource.AddComposition("normalDistributionFunction", NormalDistribution.Generate());
            }

            context.AddShading(this, shaderSource);
        }
Exemplo n.º 31
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);
                context.Parameters.Set(MaterialKeys.SkipTangents, SkipTangents);

                var normalMap = NormalMap;
                // Workaround to make sure that normal map are setup
                var computeTextureColor = normalMap as ComputeTextureColor;
                if (computeTextureColor != null)
                {
                    if (computeTextureColor.FallbackValue.Value == Color.White)
                    {
                        computeTextureColor.FallbackValue.Value = DefaultNormalColor;
                    }
                }
                else
                {
                    var computeColor = normalMap as ComputeColor;
                    if (computeColor != null)
                    {
                        if (computeColor.Value == Color.Black || computeColor.Value == Color.White)
                        {
                            computeColor.Value = DefaultNormalColor;
                        }
                    }
                    else
                    {
                        var computeFloat4 = normalMap as ComputeFloat4;
                        if (computeFloat4 != null)
                        {
                            if (computeFloat4.Value == Vector4.Zero)
                            {
                                computeFloat4.Value = DefaultNormalColor.ToVector4();
                            }
                        }
                    }
                }

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, DefaultNormalColor, false));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
            }
        }
Exemplo n.º 32
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, new Color(0x80, 0x80, 0xFF, 0xFF)));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
            }
        }
        } = new ComputeColor(new Color4(1.0f, 0.37f, 0.3f, 1.0f));                                                // Default falloff for skin.

        public ShaderSource Generate(MaterialGeneratorContext context)
        {
            var shaderSource = new ShaderMixinSource();

            MaterialComputeColorKeys materialComputeColorKeys = new MaterialComputeColorKeys(FalloffTexture, FalloffValue, DefaultProfileColor);

            // Add the shader for computing the transmittance using the custom scattering profile:
            if (FalloffMap is ComputeTextureColor ||
                FalloffMap is ComputeBinaryColor ||
                FalloffMap is ComputeShaderClassColor ||
                FalloffMap is ComputeVertexStreamColor)
            {
                var computeColorSource = FalloffMap.GenerateShaderSource(context, materialComputeColorKeys);
                shaderSource.AddComposition("FalloffMap", computeColorSource);

                // Use the expensive pixel shader because the scattering falloff can vary per pixel because we're using a texture:
                shaderSource.Mixins.Add(new ShaderClassSource("MaterialSubsurfaceScatteringScatteringProfileCustomVarying"));
            }
            else
            {
                Vector3 falloff = new Vector3(1.0f);

                ComputeColor falloffComputeColor = FalloffMap as ComputeColor;
                if (falloffComputeColor != null)
                {
                    falloff.X = falloffComputeColor.Value.R;
                    falloff.Y = falloffComputeColor.Value.G;
                    falloff.Z = falloffComputeColor.Value.B;
                }

                ComputeFloat4 falloffComputeFloat4 = FalloffMap as ComputeFloat4;
                if (falloffComputeFloat4 != null)
                {
                    falloff.X = falloffComputeFloat4.Value.X;
                    falloff.Y = falloffComputeFloat4.Value.Y;
                    falloff.Z = falloffComputeFloat4.Value.Z;
                }

                // Use the precomputed pixel shader because the scattering falloff is constant across pixels because we're using a texture:
                Vector4[] scatteringProfile = SubsurfaceScatteringKernelGenerator.CalculateTransmittanceProfile(falloff);   // Applied during forward pass.

                context.MaterialPass.Parameters.Set(MaterialSubsurfaceScatteringScatteringProfileCustomUniformKeys.ScatteringProfile, scatteringProfile);

                shaderSource.Mixins.Add(new ShaderClassSource("MaterialSubsurfaceScatteringScatteringProfileCustomUniform"));
            }

            return(shaderSource);
        }
Exemplo n.º 34
0
        private void AddClearCoatNormalMap(MaterialGeneratorContext context)
        {
            var computeColorKeys   = new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, MaterialNormalMapFeature.DefaultNormalColor, false);
            var computeColorSource = OrangePeelNormalMap.GenerateShaderSource(context, computeColorKeys);

            // Orange Peel Normal Map
            var mixinNormalMap = new ShaderMixinSource();

            // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
            context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, "matNormal", new ShaderClassSource("MaterialStreamNormalBlend"));
            context.Parameters.Set(MaterialKeys.HasNormalMap, true);

            mixinNormalMap.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", OrangePeelIsXYNormal, OrangePeelScaleAndBias));

            mixinNormalMap.AddComposition("normalMap", computeColorSource);
            context.AddShaderSource(MaterialShaderStage.Pixel, mixinNormalMap);
        }
Exemplo n.º 35
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            if (DiffuseMap != null)
            {
                Vector4 diffuseMin = Vector4.Zero;
                Vector4 diffuseMax = Vector4.One;
                DiffuseMap.ClampFloat4(ref diffuseMin, ref diffuseMax);

                var computeColorSource = DiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
                mixin.AddComposition("diffuseMap", computeColorSource);
                context.UseStream(MaterialShaderStage.Pixel, DiffuseStream.Stream);
                context.UseStream(MaterialShaderStage.Pixel, ColorBaseStream.Stream);
                context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
            }
        }
Exemplo n.º 36
0
        private void Generate(MaterialShaderStage stage, MaterialGeneratorContext context)
        {
            if (!context.HasSurfaceShaders(stage))
            {
                return;
            }

            // Blend setup for this layer
            context.SetStream(stage, BlendStream, BlendMap, MaterialKeys.BlendMap, MaterialKeys.BlendValue);

            // Generate a dynamic shader name
            // Create a mixin
            var shaderMixinSource = new ShaderMixinSource();
            shaderMixinSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceStreamsBlend"));

            // Add all streams
            foreach (var stream in context.Streams[stage])
            {
                shaderMixinSource.AddCompositionToArray("blends", context.GetStreamBlendShaderSource(stream));
            }

            var materialBlendLayerMixin = context.GenerateSurfaceShader(stage);

            // Add the shader to the mixin
            shaderMixinSource.AddComposition("layer", materialBlendLayerMixin);

            context.ResetSurfaceShaders(stage);
            context.AddSurfaceShader(stage, shaderMixinSource);
        }
Exemplo n.º 37
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);

                var normalMap = NormalMap;
                // Workaround to make sure that normal map are setup 
                var computeTextureColor = normalMap as ComputeTextureColor;
                if (computeTextureColor != null)
                {
                    if (computeTextureColor.FallbackValue.Value == Color.White)
                    {
                        computeTextureColor.FallbackValue.Value = DefaultNormalColor;
                    }
                }
                else
                {
                    var computeColor = normalMap as ComputeColor;
                    if (computeColor != null)
                    {
                        if (computeColor.Value == Color.Black || computeColor.Value == Color.White)
                        {
                            computeColor.Value = DefaultNormalColor;
                        }
                    }
                }

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, DefaultNormalColor, false));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
            }
        }
        public void SetStream(MaterialShaderStage stage, string stream, MaterialStreamType streamType, ShaderSource classSource)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            // Blend stream is not part of the stream used
            if (stream != MaterialBlendLayer.BlendStream)
            {
                GetContextPerStage(stage).Streams.Add(stream);
            }

            string channel;
            switch (streamType)
            {
                case MaterialStreamType.Float:
                    channel = "r";
                    break;
                case MaterialStreamType.Float2:
                    channel = "rg";
                    break;
                case MaterialStreamType.Float3:
                    channel = "rgb";
                    break;
                case MaterialStreamType.Float4:
                    channel = "rgba";
                    break;
                default:
                    throw new NotSupportedException("StreamType [{0}] is not supported".ToFormat(streamType));
            }

            var mixin = new ShaderMixinSource();
            mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceSetStreamFromComputeColor", stream, channel));
            mixin.AddComposition("computeColorSource", classSource);

            GetContextPerStage(stage).ShaderSources.Add(mixin);
        }
Exemplo n.º 39
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, new Color(0x80, 0x80, 0xFF, 0xFF)));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
            }
        }