public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
            {
                context.Mixin(mixin, "A");
                context.Mixin(mixin, "B");
                if (context.GetParam(TestParameters.param1))
                {
                    context.Mixin(mixin, "C");
                    mixin.AddMacro("param2", context.GetParam(TestParameters.param2));

                    {
                        var __mixinToCompose__ = "X";
                        var __subMixin = new ShaderMixinSource();
                        context.PushComposition(mixin, "x", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }
                }
                else
                {
                    context.Mixin(mixin, "D");
                    mixin.AddMacro("Test", context.GetParam(TestParameters.param3));

                    {
                        var __mixinToCompose__ = "Y";
                        var __subMixin = new ShaderMixinSource();
                        context.PushComposition(mixin, "y", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }
                }
            }
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("ThreadNumberX", context.GetParam(ComputeEffectShaderKeys.ThreadNumbers).X);
     mixin.AddMacro("ThreadNumberY", context.GetParam(ComputeEffectShaderKeys.ThreadNumbers).Y);
     mixin.AddMacro("ThreadNumberZ", context.GetParam(ComputeEffectShaderKeys.ThreadNumbers).Z);
     context.Mixin(mixin, "ComputeShaderBase");
     context.Mixin(mixin, context.GetParam(ComputeEffectShaderKeys.ComputeShaderName));
 }
Beispiel #3
0
        public void TestMacros()
        {
            // test that macros are correctly used
            var baseMixin = new ShaderMixinSource();
            baseMixin.AddMacro("SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D", 1);
            baseMixin.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin.Mixins.Add(new ShaderClassSource("TestMacros"));
            
            var macros0 = new ShaderMixinSource();
            macros0.Mixins.Add(new ShaderClassSource("MacroTest"));
            baseMixin.Compositions.Add("macros0", macros0);

            var macros1 = new ShaderMixinSource();
            macros1.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros1.Macros.Add(new ShaderMacro("MACRO_TEST", "float"));
            baseMixin.Compositions.Add("macros1", macros1);

            var macros2 = new ShaderMixinSource();
            macros2.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros2.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            baseMixin.Compositions.Add("macros2", macros2);

            var parsingResult = shaderMixinParser.Parse(baseMixin, baseMixin.Macros.ToArray());
            
            Assert.IsFalse(parsingResult.HasErrors);
            var cBufferVar = parsingResult.Shader.Declarations.OfType<ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType<Variable>().ToList();
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "int"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float4"));

            // test clash when reloading
            var baseMixin2 = new ShaderMixinSource();
            baseMixin2.AddMacro("SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D", 1);
            baseMixin2.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin2.Mixins.Add(new ShaderClassSource("TestMacros"));

            var macros3 = new ShaderMixinSource();
            macros3.Mixins.Add(new ShaderClassSource("MacroTest"));
            baseMixin2.Compositions.Add("macros0", macros3);

            var macros4 = new ShaderMixinSource();
            macros4.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros4.Macros.Add(new ShaderMacro("MACRO_TEST", "uint4"));
            baseMixin2.Compositions.Add("macros1", macros4);

            var macros5 = new ShaderMixinSource();
            macros5.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros5.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            baseMixin2.Compositions.Add("macros2", macros5);

            var parsingResult2 = shaderMixinParser.Parse(baseMixin2, baseMixin2.Macros.ToArray());

            Assert.IsFalse(parsingResult.HasErrors);
            var cBufferVar2 = parsingResult2.Shader.Declarations.OfType<ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType<Variable>().ToList();
            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "int"));
            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "uint4"));
            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "float4"));
        }
Beispiel #4
0
        public ShaderSource GetVoxelizationShader(VoxelizationPass pass, ProcessedVoxelVolume data)
        {
            bool              singleClip = UpdatesOneClipPerFrame();
            ShaderSource      VoxelizationMethodSource = pass.method.GetVoxelizationShader();
            ShaderMixinSource cachedMixin = new ShaderMixinSource();

            cachedMixin.Mixins.Add(storage);
            cachedMixin.AddComposition("method", VoxelizationMethodSource);
            if (singleClip)
            {
                cachedMixin.AddMacro("singleClip", true);
            }

            string IndirectStoreMacro = "";

            for (int i = 0; i < pass.AttributesIndirect.Count; i++)
            {
                string iStr = i.ToString();
                IndirectStoreMacro += $"AttributesIndirect[{iStr}].IndirectWrite(fragmentsBuffer, writeindex + {pass.AttributesIndirect[i].BufferOffset});\n";
            }

            cachedMixin.AddMacro("IndirectStoreMacro", IndirectStoreMacro);

            foreach (var attr in pass.AttributesTemp)
            {
                cachedMixin.AddCompositionToArray("AttributesTemp", attr.GetVoxelizationShader());
            }
            foreach (var attr in pass.AttributesDirect)
            {
                cachedMixin.AddCompositionToArray("AttributesDirect", attr.GetVoxelizationShader());
            }
            foreach (var attr in pass.AttributesIndirect)
            {
                cachedMixin.AddCompositionToArray("AttributesIndirect", attr.GetVoxelizationShader());
            }

            return(cachedMixin);
        }
Beispiel #5
0
            public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
            {
                context.Mixin(mixin, "ShaderBase");
                context.Mixin(mixin, "TransformationWAndVP");
                mixin.AddMacro("MAX_VERTEX_COUNT", 9);
                context.Mixin(mixin, "CameraCube");
                context.Mixin(mixin, "AlbedoFlatShading");
                if (context.GetParam(MaterialParameters.AlbedoDiffuse) != null)

                {
                    var __mixinToCompose__ = context.GetParam(MaterialParameters.AlbedoDiffuse);
                    var __subMixin         = new ShaderMixinSource();
                    context.PushComposition(mixin, "albedoDiffuse", __subMixin);
                    context.Mixin(__subMixin, __mixinToCompose__);
                    context.PopComposition();
                }
            }
Beispiel #6
0
        public void TestMacrosArray()
        {
            Init();

            // test that macros are correctly used through an array
            var baseMixin = new ShaderMixinSource();

            baseMixin.AddMacro("STRIDE_GRAPHICS_API_DIRECT3D", 1);
            baseMixin.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin.Mixins.Add(new ShaderClassSource("TestMacrosArray"));

            var compositionArray = new ShaderArraySource();

            var macros0 = new ShaderMixinSource();

            macros0.Mixins.Add(new ShaderClassSource("MacroTest"));
            compositionArray.Add(macros0);

            var macros1 = new ShaderMixinSource();

            macros1.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros1.Macros.Add(new ShaderMacro("MACRO_TEST", "float"));
            compositionArray.Add(macros1);

            var macros2 = new ShaderMixinSource();

            macros2.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros2.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            compositionArray.Add(macros2);

            baseMixin.Compositions.Add("macrosArray", compositionArray);

            var parsingResult = shaderMixinParser.Parse(baseMixin, baseMixin.Macros.ToArray());

            Assert.False(parsingResult.HasErrors);
            var cBufferVar = parsingResult.Shader.Declarations.OfType <ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType <Variable>().ToList();

            Assert.Equal(1, cBufferVar.Count(x => x.Type.Name.Text == "int"));
            Assert.Equal(1, cBufferVar.Count(x => x.Type.Name.Text == "float"));
            Assert.Equal(1, cBufferVar.Count(x => x.Type.Name.Text == "float4"));
        }
Beispiel #7
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     context.Mixin(mixin, "OioShaderBase");
     context.Mixin(mixin, "OioTransformationBase");
     context.Mixin(mixin, "NormalStream");
     context.Mixin(mixin, "OioTransformationWAndVP");
     if (context.GetParam(MaterialKeys.HasNormalMap))
     {
         context.Mixin(mixin, "OioNormalFromNormalMapping");
     }
     else
     {
         context.Mixin(mixin, "OioNormalFromMesh");
     }
     if (context.GetParam(MaterialKeys.HasSkinningPosition))
     {
         mixin.AddMacro("SkinningMaxBones", context.GetParam(MaterialKeys.SkinningMaxBones));
         context.Mixin(mixin, "OioTransformationSkinning");
         if (context.GetParam(MaterialKeys.HasSkinningNormal))
         {
             context.Mixin(mixin, "OioNormalMeshSkinning");
         }
         if (context.GetParam(MaterialKeys.HasSkinningTangent))
         {
             context.Mixin(mixin, "OioTangentMeshSkinning");
         }
         if (context.GetParam(MaterialKeys.HasSkinningNormal))
         {
             if (context.GetParam(MaterialKeys.HasNormalMap))
             {
                 context.Mixin(mixin, "OioNormalVSSkinningNormalMapping");
             }
             else
             {
                 context.Mixin(mixin, "OioNormalVSSkinningFromMesh");
             }
         }
     }
 }
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("INPUT_MSAA_SAMPLES", context.GetParam(MSAAResolverParams.MSAASamples));
     context.Mixin(mixin, "MSAAResolverShader", context.GetParam(MSAAResolverParams.MSAASamples), context.GetParam(MSAAResolverParams.ResolveFilterType), context.GetParam(MSAAResolverParams.ResolveFilterDiameter));
 }
Beispiel #9
0
            public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
            {
                context.Mixin(mixin, "ShaderBase");
                context.Mixin(mixin, "ShadingBase");
                var extensionPreVertexStageSurfaceShaders = context.GetParam(MaterialKeys.VertexStageSurfaceShaders);

                if (extensionPreVertexStageSurfaceShaders != null)
                {
                    context.Mixin(mixin, "MaterialSurfaceVertexStageCompositor");

                    {
                        var __mixinToCompose__ = (extensionPreVertexStageSurfaceShaders);
                        var __subMixin         = new ShaderMixinSource();
                        context.PushComposition(mixin, "materialVertexStage", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }

                    {
                        var __mixinToCompose__ = context.GetParam(MaterialKeys.VertexStageStreamInitializer);
                        var __subMixin         = new ShaderMixinSource();
                        context.PushComposition(mixin, "streamInitializerVertexStage", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }
                }
                context.Mixin(mixin, "TransformationBase");
                context.Mixin(mixin, "NormalStream");
                context.Mixin(mixin, "TransformationWAndVP");
                if (context.GetParam(MaterialKeys.HasNormalMap))
                {
                    context.Mixin(mixin, "NormalFromNormalMapping");
                }
                else
                {
                    context.Mixin(mixin, "NormalFromMesh");
                }
                if (context.GetParam(MaterialKeys.HasSkinningPosition))
                {
                    mixin.AddMacro("SkinningMaxBones", context.GetParam(MaterialKeys.SkinningMaxBones));
                    context.Mixin(mixin, "TransformationSkinning");
                    if (context.GetParam(MaterialKeys.HasSkinningNormal))
                    {
                        context.Mixin(mixin, "NormalMeshSkinning");
                    }
                    if (context.GetParam(MaterialKeys.HasSkinningTangent))
                    {
                        context.Mixin(mixin, "TangentMeshSkinning");
                    }
                    if (context.GetParam(MaterialKeys.HasSkinningNormal))
                    {
                        if (context.GetParam(MaterialKeys.HasNormalMap))
                        {
                            context.Mixin(mixin, "NormalVSSkinningNormalMapping");
                        }
                        else
                        {
                            context.Mixin(mixin, "NormalVSSkinningFromMesh");
                        }
                    }
                }
                var extensionTessellationShader = context.GetParam(MaterialKeys.TessellationShader);

                if (extensionTessellationShader != null)
                {
                    context.Mixin(mixin, (extensionTessellationShader));
                    var extensionDomainStageSurfaceShaders = context.GetParam(MaterialKeys.DomainStageSurfaceShaders);
                    if (extensionDomainStageSurfaceShaders != null)
                    {
                        context.Mixin(mixin, "MaterialSurfaceDomainStageCompositor");

                        {
                            var __mixinToCompose__ = (extensionDomainStageSurfaceShaders);
                            var __subMixin         = new ShaderMixinSource();
                            context.PushComposition(mixin, "materialDomainStage", __subMixin);
                            context.Mixin(__subMixin, __mixinToCompose__);
                            context.PopComposition();
                        }

                        {
                            var __mixinToCompose__ = context.GetParam(MaterialKeys.DomainStageStreamInitializer);
                            var __subMixin         = new ShaderMixinSource();
                            context.PushComposition(mixin, "streamInitializerDomainStage", __subMixin);
                            context.Mixin(__subMixin, __mixinToCompose__);
                            context.PopComposition();
                        }
                    }
                }
                var extensionPostVertexStage = context.GetParam(XenkoEffectBaseKeys.ExtensionPostVertexStageShader);

                if (extensionPostVertexStage != null)
                {
                    context.Mixin(mixin, (extensionPostVertexStage));
                }
                var targetExtensions = context.GetParam(XenkoEffectBaseKeys.RenderTargetExtensions);

                if (targetExtensions != null)
                {
                    context.Mixin(mixin, (targetExtensions));
                }
            }
Beispiel #10
0
        public override EffectBytecode Compile(ShaderMixinSource shaderMixinSource, string fullEffectName, ShaderMixinParameters compilerParameters, HashSet <string> modifiedShaders, HashSet <string> recentlyModifiedShaders, LoggerResult log)
        {
            // Load D3D compiler dll
            // Note: No lock, it's probably fine if it gets called from multiple threads at the same time.
            if (Platform.IsWindowsDesktop && !d3dcompilerLoaded)
            {
                NativeLibrary.PreloadLibrary("d3dcompiler_47.dll");
                d3dcompilerLoaded = true;
            }

            // Make a copy of shaderMixinSource. Use deep clone since shaderMixinSource can be altered during compilation (e.g. macros)
            var shaderMixinSourceCopy = new ShaderMixinSource();

            shaderMixinSourceCopy.DeepCloneFrom(shaderMixinSource);

            shaderMixinSource = shaderMixinSourceCopy;

            // Generate platform-specific macros
            var platform = compilerParameters.Get(CompilerParameters.GraphicsPlatformKey);

            switch (platform)
            {
            case GraphicsPlatform.Direct3D11:
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D", 1);
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D11", 1);
                break;

            case GraphicsPlatform.OpenGL:
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL", 1);
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLCORE", 1);
                break;

            case GraphicsPlatform.OpenGLES:
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL", 1);
                shaderMixinSource.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES", 1);
                break;

            default:
                throw new NotSupportedException();
            }

            // Generate the AST from the mixin description
            if (shaderMixinParser == null)
            {
                shaderMixinParser = new ShaderMixinParser();
                shaderMixinParser.SourceManager.LookupDirectoryList = SourceDirectories; // TODO: temp
                shaderMixinParser.SourceManager.UrlToFilePath       = UrlToFilePath;     // TODO: temp
            }

            if (recentlyModifiedShaders != null && recentlyModifiedShaders.Count > 0)
            {
                shaderMixinParser.DeleteObsoleteCache(GetShaderNames(recentlyModifiedShaders));
                recentlyModifiedShaders.Clear();
            }
            var parsingResult = shaderMixinParser.Parse(shaderMixinSource, shaderMixinSource.Macros.ToArray(), modifiedShaders);

            // Copy log from parser results to output
            CopyLogs(parsingResult, log);

            // Return directly if there are any errors
            if (parsingResult.HasErrors)
            {
                return(null);
            }

            // Convert the AST to HLSL
            var writer = new SiliconStudio.Shaders.Writer.Hlsl.HlslWriter {
                EnablePreprocessorLine = false
            };

            writer.Visit(parsingResult.Shader);
            var shaderSourceText = writer.Text;

            // -------------------------------------------------------
            // Save shader log
            // TODO: TEMP code to allow debugging generated shaders on Windows Desktop
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
            var shaderId = ObjectId.FromBytes(Encoding.UTF8.GetBytes(shaderSourceText));

            var logDir = "log";
            if (!Directory.Exists(logDir))
            {
                Directory.CreateDirectory(logDir);
            }
            var shaderSourceFilename = Path.Combine(logDir, "shader_" + shaderId);
            lock (WriterLock) // protect write in case the same shader is created twice
            {
                if (!File.Exists(shaderSourceFilename))
                {
                    var builder = new StringBuilder();
                    builder.AppendLine("/***** Used Parameters *****");
                    builder.Append(" * EffectName: ");
                    builder.AppendLine(fullEffectName ?? "");
                    WriteParameters(builder, compilerParameters, 0, false);
                    builder.AppendLine(" ***************************/");
                    builder.Append(shaderSourceText);
                    File.WriteAllText(shaderSourceFilename, builder.ToString());
                }
            }
#endif
            // -------------------------------------------------------

            var bytecode = new EffectBytecode {
                Reflection = parsingResult.Reflection, HashSources = parsingResult.HashSources
            };

            // Select the correct backend compiler
            IShaderCompiler compiler;
            switch (platform)
            {
            case GraphicsPlatform.Direct3D11:
                compiler = new Direct3D.ShaderCompiler();
                break;

            case GraphicsPlatform.OpenGL:
            case GraphicsPlatform.OpenGLES:
                compiler = new OpenGL.ShaderCompiler();
                break;

            default:
                throw new NotSupportedException();
            }

            var shaderStageBytecodes = new List <ShaderBytecode>();

            foreach (var stageBinding in parsingResult.EntryPoints)
            {
                // Compile
                var result = compiler.Compile(shaderSourceText, stageBinding.Value, stageBinding.Key, compilerParameters, bytecode.Reflection, shaderSourceFilename);
                result.CopyTo(log);

                if (result.HasErrors)
                {
                    continue;
                }

                // -------------------------------------------------------
                // Append bytecode id to shader log
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
                lock (WriterLock) // protect write in case the same shader is created twice
                {
                    if (File.Exists(shaderSourceFilename))
                    {
                        // Append at the end of the shader the bytecodes Id
                        File.AppendAllText(shaderSourceFilename, "\n// {0} {1}".ToFormat(stageBinding.Key, result.Bytecode.Id));
                    }
                }
#endif
                // -------------------------------------------------------

                shaderStageBytecodes.Add(result.Bytecode);

                // When this is a compute shader, there is no need to scan other stages
                if (stageBinding.Key == ShaderStage.Compute)
                {
                    break;
                }
            }

            // Get the current time of compilation
            bytecode.Time = DateTime.Now;

            // In case of Direct3D, we can safely remove reflection data as it is entirely resolved at compile time.
            if (platform == GraphicsPlatform.Direct3D11)
            {
                CleanupReflection(bytecode.Reflection);
            }

            bytecode.Stages = shaderStageBytecodes.ToArray();
            return(bytecode);
        }
Beispiel #11
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("CONVOLVE_VERTICAL", 1);
     context.Mixin(mixin, "SSLRBlurPass");
 }
Beispiel #12
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("FXAA_GREEN_AS_LUMA", context.GetParam(FXAAEffect.GreenAsLumaKey));
     mixin.AddMacro("FXAA_QUALITY__PRESET", context.GetParam(FXAAEffect.QualityKey));
     context.Mixin(mixin, "FXAAShader");
 }
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("INPUT_MSAA_SAMPLES", context.GetParam(MSAAResolverParams.MSAASamples));
     context.Mixin(mixin, "MSAADepthResolverShader");
 }
Beispiel #14
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("UsesSoftEdge", context.GetParam(ParticleBaseKeys.UsesSoftEdge));
     context.Mixin(mixin, "ParticleBase");
 }
            public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
            {
                context.Mixin(mixin, "ShaderBase");
                context.Mixin(mixin, "ShadingBase");
                var extensionPreVertexStageSurfaceShaders = context.GetParam(MaterialKeys.VertexStageSurfaceShaders);
                if (extensionPreVertexStageSurfaceShaders != null)
                {
                    context.Mixin(mixin, "MaterialSurfaceVertexStageCompositor");

                    {
                        var __mixinToCompose__ = (extensionPreVertexStageSurfaceShaders);
                        var __subMixin = new ShaderMixinSource();
                        context.PushComposition(mixin, "materialVertexStage", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }

                    {
                        var __mixinToCompose__ = context.GetParam(MaterialKeys.VertexStageStreamInitializer);
                        var __subMixin = new ShaderMixinSource();
                        context.PushComposition(mixin, "streamInitializerVertexStage", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }
                }
                context.Mixin(mixin, "TransformationBase");
                context.Mixin(mixin, "NormalStream");
                context.Mixin(mixin, "TransformationWAndVP");
                if (context.GetParam(MaterialKeys.HasNormalMap))
                {
                    context.Mixin(mixin, "NormalFromNormalMapping");
                }
                else
                {
                    context.Mixin(mixin, "NormalFromMesh");
                }
                if (context.GetParam(MaterialKeys.HasSkinningPosition))
                {
                    mixin.AddMacro("SkinningMaxBones", context.GetParam(MaterialKeys.SkinningMaxBones));
                    context.Mixin(mixin, "TransformationSkinning");
                    if (context.GetParam(MaterialKeys.HasSkinningNormal))
                    {
                        context.Mixin(mixin, "NormalMeshSkinning");
                    }
                    if (context.GetParam(MaterialKeys.HasSkinningTangent))
                    {
                        context.Mixin(mixin, "TangentMeshSkinning");
                    }
                    if (context.GetParam(MaterialKeys.HasSkinningNormal))
                    {
                        if (context.GetParam(MaterialKeys.HasNormalMap))
                        {
                            context.Mixin(mixin, "NormalVSSkinningNormalMapping");
                        }
                        else
                        {
                            context.Mixin(mixin, "NormalVSSkinningFromMesh");
                        }
                    }
                }
                var extensionTessellationShader = context.GetParam(MaterialKeys.TessellationShader);
                if (extensionTessellationShader != null)
                {
                    context.Mixin(mixin, (extensionTessellationShader));
                    var extensionDomainStageSurfaceShaders = context.GetParam(MaterialKeys.DomainStageSurfaceShaders);
                    if (extensionDomainStageSurfaceShaders != null)
                    {
                        context.Mixin(mixin, "MaterialSurfaceDomainStageCompositor");

                        {
                            var __mixinToCompose__ = (extensionDomainStageSurfaceShaders);
                            var __subMixin = new ShaderMixinSource();
                            context.PushComposition(mixin, "materialDomainStage", __subMixin);
                            context.Mixin(__subMixin, __mixinToCompose__);
                            context.PopComposition();
                        }

                        {
                            var __mixinToCompose__ = context.GetParam(MaterialKeys.DomainStageStreamInitializer);
                            var __subMixin = new ShaderMixinSource();
                            context.PushComposition(mixin, "streamInitializerDomainStage", __subMixin);
                            context.Mixin(__subMixin, __mixinToCompose__);
                            context.PopComposition();
                        }
                    }
                }
                var extensionPostVertexStage = context.GetParam(XenkoEffectBaseKeys.ExtensionPostVertexStageShader);
                if (extensionPostVertexStage != null)
                {
                    context.Mixin(mixin, (extensionPostVertexStage));
                }
            }
Beispiel #16
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("FXAA_GREEN_AS_LUMA", context.GetParam(FXAAEffect.GreenAsLumaKey));
     mixin.AddMacro("FXAA_QUALITY__PRESET", context.GetParam(FXAAEffect.QualityKey));
     context.Mixin(mixin, "FXAAShader");
 }
Beispiel #17
0
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("SSSS_FOLLOW_SURFACE", context.GetParam(SubsurfaceScatteringKeys.FollowSurface));
     context.Mixin(mixin, "SubsurfaceScatteringBlurShader", context.GetParam(SubsurfaceScatteringKeys.BlurHorizontally), context.GetParam(SubsurfaceScatteringKeys.KernelSizeJittering), context.GetParam(SubsurfaceScatteringKeys.OrthographicProjection), context.GetParam(SubsurfaceScatteringKeys.MaxMaterialCount), context.GetParam(SubsurfaceScatteringKeys.KernelLength), context.GetParam(SubsurfaceScatteringKeys.RenderMode));
 }
            public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
            {
                context.Mixin(mixin, "ShaderBase");
                context.Mixin(mixin, "TransformationWAndVP");
                mixin.AddMacro("MAX_VERTEX_COUNT", 9);
                context.Mixin(mixin, "CameraCube");
                context.Mixin(mixin, "AlbedoFlatShading");
                if (context.GetParam(MaterialParameters.AlbedoDiffuse) != null)

                    {
                        var __mixinToCompose__ = context.GetParam(MaterialParameters.AlbedoDiffuse);
                        var __subMixin = new ShaderMixinSource();
                        context.PushComposition(mixin, "albedoDiffuse", __subMixin);
                        context.Mixin(__subMixin, __mixinToCompose__);
                        context.PopComposition();
                    }
            }
 public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)
 {
     mixin.AddMacro("UsesSoftEdge", context.GetParam(ParticleBaseKeys.UsesSoftEdge));
     context.Mixin(mixin, "ParticleBase");
 }
Beispiel #20
0
        public void TestMacros()
        {
            // test that macros are correctly used
            var baseMixin = new ShaderMixinSource();

            baseMixin.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D", 1);
            baseMixin.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin.Mixins.Add(new ShaderClassSource("TestMacros"));

            var macros0 = new ShaderMixinSource();

            macros0.Mixins.Add(new ShaderClassSource("MacroTest"));
            baseMixin.Compositions.Add("macros0", macros0);

            var macros1 = new ShaderMixinSource();

            macros1.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros1.Macros.Add(new ShaderMacro("MACRO_TEST", "float"));
            baseMixin.Compositions.Add("macros1", macros1);

            var macros2 = new ShaderMixinSource();

            macros2.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros2.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            baseMixin.Compositions.Add("macros2", macros2);

            var parsingResult = shaderMixinParser.Parse(baseMixin, baseMixin.Macros.ToArray());

            Assert.IsFalse(parsingResult.HasErrors);
            var cBufferVar = parsingResult.Shader.Declarations.OfType <ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType <Variable>().ToList();

            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "int"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float4"));

            // test clash when reloading
            var baseMixin2 = new ShaderMixinSource();

            baseMixin2.AddMacro("SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D", 1);
            baseMixin2.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin2.Mixins.Add(new ShaderClassSource("TestMacros"));

            var macros3 = new ShaderMixinSource();

            macros3.Mixins.Add(new ShaderClassSource("MacroTest"));
            baseMixin2.Compositions.Add("macros0", macros3);

            var macros4 = new ShaderMixinSource();

            macros4.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros4.Macros.Add(new ShaderMacro("MACRO_TEST", "uint4"));
            baseMixin2.Compositions.Add("macros1", macros4);

            var macros5 = new ShaderMixinSource();

            macros5.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros5.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            baseMixin2.Compositions.Add("macros2", macros5);

            var parsingResult2 = shaderMixinParser.Parse(baseMixin2, baseMixin2.Macros.ToArray());

            Assert.IsFalse(parsingResult.HasErrors);
            var cBufferVar2 = parsingResult2.Shader.Declarations.OfType <ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType <Variable>().ToList();

            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "int"));
            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "uint4"));
            Assert.AreEqual(1, cBufferVar2.Count(x => x.Type.Name.Text == "float4"));
        }
Beispiel #21
0
        public void TestMacrosArray()
        {
            // test that macros are correctly used through an array
            var baseMixin = new ShaderMixinSource();
            baseMixin.AddMacro("SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D", 1);
            baseMixin.Macros.Add(new ShaderMacro("MACRO_TEST", "int"));
            baseMixin.Mixins.Add(new ShaderClassSource("TestMacrosArray"));

            var compositionArray = new ShaderArraySource();

            var macros0 = new ShaderMixinSource();
            macros0.Mixins.Add(new ShaderClassSource("MacroTest"));
            compositionArray.Add(macros0);

            var macros1 = new ShaderMixinSource();
            macros1.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros1.Macros.Add(new ShaderMacro("MACRO_TEST", "float"));
            compositionArray.Add(macros1);

            var macros2 = new ShaderMixinSource();
            macros2.Mixins.Add(new ShaderClassSource("MacroTest"));
            macros2.Macros.Add(new ShaderMacro("MACRO_TEST", "float4"));
            compositionArray.Add(macros2);
            
            baseMixin.Compositions.Add("macrosArray", compositionArray);

            var parsingResult = shaderMixinParser.Parse(baseMixin, baseMixin.Macros.ToArray());

            Assert.IsFalse(parsingResult.HasErrors);
            var cBufferVar = parsingResult.Shader.Declarations.OfType<ConstantBuffer>().First(x => x.Name == "Globals").Members.OfType<Variable>().ToList();
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "int"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float"));
            Assert.AreEqual(1, cBufferVar.Count(x => x.Type.Name.Text == "float4"));
        }