public void TestShaderCompilation() { Init(); var generics = new string[3]; generics[0] = "Texturing.Texture1"; generics[1] = "TEXCOORD0"; generics[2] = "float4(2.0,1,1,1)"; var compilerParameters = new CompilerParameters(); compilerParameters.Set(EffectSourceCodeKeys.Enable, true); compilerParameters.EffectParameters.Profile = GraphicsProfile.Level_11_0; var mixinSource = new ShaderMixinSource { Name = "TestShaderCompilationGenericClass" }; mixinSource.Mixins.Add(new ShaderClassSource("GenericClass2", generics)); var log = new CompilerResults(); var compiler = new EffectCompiler(TestHelper.CreateDatabaseProvider().FileProvider); compiler.SourceDirectories.Add("shaders"); var effectByteCode = compiler.Compile(mixinSource, compilerParameters.EffectParameters, compilerParameters); }
protected CompilerParameters GetDefaultCompilerParameters() { var compilerParameters = new CompilerParameters(); compilerParameters.Set(CompilerParameters.GraphicsProfileKey, GraphicsDevice.Features.Profile); return(compilerParameters); }
public void TestMixinAndComposeKeys() { var compiler = new EffectCompiler(TestHelper.CreateDatabaseProvider().FileProvider) { UseFileSystem = true }; var currentPath = Core.PlatformFolders.ApplicationBinaryDirectory; compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\Stride.Graphics\Shaders")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\Stride.Shaders.Tests\GameAssets\Mixins")); var compilerParameters = new CompilerParameters { EffectParameters = { Platform = GraphicsPlatform.Direct3D11 } }; var subCompute1Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute1"); var subCompute2Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute2"); var subComputesKey = TestABC.TestParameters.UseComputeColorRedirect.ComposeWith("SubComputes[0]"); compilerParameters.Set(subCompute1Key, true); compilerParameters.Set(subComputesKey, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("test_mixin_compose_keys"), compilerParameters); Assert.False(results.HasErrors); var mainBytecode = results.Bytecode.WaitForResult(); Assert.False(mainBytecode.CompilationLog.HasErrors); Assert.NotNull(mainBytecode.Bytecode.Reflection.ConstantBuffers); Assert.Single(mainBytecode.Bytecode.Reflection.ConstantBuffers); var cbuffer = mainBytecode.Bytecode.Reflection.ConstantBuffers[0]; Assert.NotNull(cbuffer.Members); Assert.Equal(2, cbuffer.Members.Length); // Check that ComputeColor2.Color is correctly composed for variables var computeColorSubCompute2 = ComputeColor2Keys.Color.ComposeWith("SubCompute1"); var computeColorSubComputes = ComputeColor2Keys.Color.ComposeWith("ColorRedirect.SubComputes[0]"); var members = cbuffer.Members.Select(member => member.KeyInfo.KeyName).ToList(); Assert.Contains(computeColorSubCompute2.Name, members); Assert.Contains(computeColorSubComputes.Name, members); }
public void TestMixinAndComposeKeys() { var compiler = new EffectCompiler { UseFileSystem = true }; compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Paradox.Graphics\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Paradox.Shaders.Tests\GameAssets\Mixins"); var compilerParameters = new CompilerParameters { Platform = GraphicsPlatform.Direct3D11 }; var subCompute1Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute1"); var subCompute2Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute2"); var subComputesKey = TestABC.TestParameters.UseComputeColorRedirect.ComposeWith("SubComputes[0]"); compilerParameters.Set(subCompute1Key, true); compilerParameters.Set(subComputesKey, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("test_mixin_compose_keys"), compilerParameters); Assert.IsFalse(results.HasErrors); var mainBytecode = results.Bytecode.WaitForResult(); Assert.IsFalse(mainBytecode.CompilationLog.HasErrors); Assert.NotNull(mainBytecode.Bytecode.Reflection.ConstantBuffers); Assert.AreEqual(1, mainBytecode.Bytecode.Reflection.ConstantBuffers.Count); var cbuffer = mainBytecode.Bytecode.Reflection.ConstantBuffers[0]; Assert.NotNull(cbuffer.Members); Assert.AreEqual(2, cbuffer.Members.Length); // Check that ComputeColor2.Color is correctly composed for variables var computeColorSubCompute2 = ComputeColor2Keys.Color.ComposeWith("SubCompute1"); var computeColorSubComputes = ComputeColor2Keys.Color.ComposeWith("ColorRedirect.SubComputes[0]"); var members = cbuffer.Members.Select(member => member.Param.KeyName).ToList(); Assert.IsTrue(members.Contains(computeColorSubCompute2.Name)); Assert.IsTrue(members.Contains(computeColorSubComputes.Name)); }
/// <inheritdoc/> public override void Load() { base.Load(); useMultipleRenderTargets = GraphicsDevice.Features.Profile >= GraphicsProfile.Level_10_0; for (var maxBlendCount = 2; maxBlendCount < 5; ++maxBlendCount) { var compilerParameter = new CompilerParameters(); var compilerParameterChild = new ShaderMixinParameters[maxBlendCount]; for (var i = 0; i < maxBlendCount; ++i) { var param = new ShaderMixinParameters(); param.Add(CubemapBlendRenderer.CubemapKey, GetTextureCubeKey(i)); compilerParameterChild[i] = param; } compilerParameter.Set(CubemapBlendRenderer.Cubemaps, compilerParameterChild); compilerParameter.Set(CubemapBlendRenderer.CubemapCount, maxBlendCount); compilerParameter.Set(CubemapBlendRenderer.UseMultipleRenderTargets, useMultipleRenderTargets); cubemapBlendEffects.Add(maxBlendCount, EffectSystem.LoadEffect("CubemapBlendEffect", compilerParameter)); } }
protected Graphics.Effect ComputeMeshFallbackEffect(RenderObject renderObject, [NotNull] RenderEffect renderEffect, RenderEffectState renderEffectState) { try { var renderMesh = (RenderMesh)renderObject; bool hasDiffuseMap = renderMesh.MaterialPass.Parameters.ContainsKey(MaterialKeys.DiffuseMap); var fallbackMaterial = hasDiffuseMap ? fallbackTextureMaterial : fallbackColorMaterial; // High priority var compilerParameters = new CompilerParameters { EffectParameters = { TaskPriority = -1 } }; // Support skinning if (renderMesh.Mesh.Skinning != null && renderMesh.Mesh.Skinning.Bones.Length <= 56) { compilerParameters.Set(MaterialKeys.HasSkinningPosition, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningPosition)); compilerParameters.Set(MaterialKeys.HasSkinningNormal, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningNormal)); compilerParameters.Set(MaterialKeys.HasSkinningTangent, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningTangent)); compilerParameters.Set(MaterialKeys.SkinningMaxBones, 56); } // Set material permutations compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageSurfaceShaders)); compilerParameters.Set(MaterialKeys.PixelStageStreamInitializer, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageStreamInitializer)); // Set lighting permutations (use custom white light, since this effect will not be processed by the lighting render feature) compilerParameters.Set(LightingKeys.EnvironmentLights, new ShaderSourceCollection { new ShaderClassSource("LightConstantWhite") }); // Initialize parameters with material ones (need a CopyTo?) renderEffect.FallbackParameters = new ParameterCollection(renderMesh.MaterialPass.Parameters); // Don't show selection wireframe/highlights as compiling var ignoreState = renderEffect.EffectSelector.EffectName.EndsWith(".Wireframe") || renderEffect.EffectSelector.EffectName.EndsWith(".Highlight") || renderEffect.EffectSelector.EffectName.EndsWith(".Picking"); // Also set a value so that we know something is loading (green glowing FX) or error (red glowing FX) if (!ignoreState) { if (renderEffectState == RenderEffectState.Compiling) { compilerParameters.Set(SceneEditorParameters.IsEffectCompiling, true); } else if (renderEffectState == RenderEffectState.Error) { compilerParameters.Set(SceneEditorParameters.IsEffectError, true); } } if (renderEffectState == RenderEffectState.Error) { // Retry every few seconds renderEffect.RetryTime = DateTime.UtcNow + TimeSpan.FromSeconds(5); } return(EffectSystem.LoadEffect(renderEffect.EffectSelector.EffectName, compilerParameters).WaitForResult()); } catch { // TODO: Log or rethrow? renderEffect.State = RenderEffectState.Error; return(null); } }
public void TestMaterial() { var compiler = new EffectCompiler { UseFileSystem = true }; compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Paradox.Graphics\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Paradox.Engine\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Core"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Lights"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Materials"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shadows"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\ComputeColor"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Skinning"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shading"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Transformation"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Utils"); var compilerParameters = new CompilerParameters { Platform = GraphicsPlatform.Direct3D11 }; var layers = new MaterialBlendLayers(); layers.Add(new MaterialBlendLayer { BlendMap = new ComputeFloat(0.5f), Material = AttachedReferenceManager.CreateSerializableVersion <Material>(Guid.Empty, "fake") }); var materialAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color4.White) }, DiffuseModel = new MaterialDiffuseLambertModelFeature() }, Layers = layers }; var fakeAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color.Blue) }, } }; var context = new MaterialGeneratorContext { FindAsset = reference => fakeAsset }; var result = MaterialGenerator.Generate(new MaterialDescriptor { Attributes = materialAsset.Attributes, Layers = materialAsset.Layers }, context, "TestMaterial"); compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, result.Material.Parameters.Get(MaterialKeys.PixelStageSurfaceShaders)); var directionalLightGroup = new ShaderClassSource("LightDirectionalGroup", 1); compilerParameters.Set(LightingKeys.DirectLightGroups, new List <ShaderSource> { directionalLightGroup }); //compilerParameters.Set(LightingKeys.CastShadows, false); //compilerParameters.Set(MaterialParameters.HasSkinningPosition, true); //compilerParameters.Set(MaterialParameters.HasSkinningNormal, true); compilerParameters.Set(MaterialKeys.HasNormalMap, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("ParadoxEffectBase"), compilerParameters); Assert.IsFalse(results.HasErrors); }
public void TestMaterial() { var compiler = new EffectCompiler { UseFileSystem = true }; var currentPath = Core.PlatformFolders.ApplicationBinaryDirectory; compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Graphics\Shaders")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Shaders")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Core")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Lights")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Shadows")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Materials\Shaders")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Materials\ComputeColors\Shaders")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Skinning")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Shading")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Transformation")); compiler.SourceDirectories.Add(Path.Combine(currentPath, @"..\..\sources\engine\SiliconStudio.Xenko.Engine\Rendering\Utils")); var compilerParameters = new CompilerParameters { EffectParameters = { Platform = GraphicsPlatform.OpenGL } }; var layers = new MaterialBlendLayers(); layers.Add(new MaterialBlendLayer { BlendMap = new ComputeFloat(0.5f), Material = AttachedReferenceManager.CreateProxyObject <Material>(AssetId.Empty, "fake") }); var materialAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color4.White) }, DiffuseModel = new MaterialDiffuseLambertModelFeature() }, Layers = layers }; var fakeAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color.Blue) }, } }; var context = new MaterialGeneratorContext { FindAsset = reference => fakeAsset }; var result = MaterialGenerator.Generate(new MaterialDescriptor { Attributes = materialAsset.Attributes, Layers = materialAsset.Layers }, context, "TestMaterial"); compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, result.Material.Parameters.Get(MaterialKeys.PixelStageSurfaceShaders)); var directionalLightGroup = new ShaderClassSource("LightDirectionalGroup", 1); compilerParameters.Set(LightingKeys.DirectLightGroups, new ShaderSourceCollection { directionalLightGroup }); //compilerParameters.Set(LightingKeys.CastShadows, false); //compilerParameters.Set(MaterialParameters.HasSkinningPosition, true); //compilerParameters.Set(MaterialParameters.HasSkinningNormal, true); compilerParameters.Set(MaterialKeys.HasNormalMap, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("XenkoEffectBase"), compilerParameters); Assert.IsFalse(results.HasErrors); }