Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LightingAssetCompiler.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Threading.Tasks;
6 
7 using SiliconStudio.Assets.Compiler;
8 using SiliconStudio.BuildEngine;
9 using SiliconStudio.Core.IO;
10 using SiliconStudio.Core.Serialization.Assets;
11 using SiliconStudio.Paradox.Effects.Data;
12 using SiliconStudio.Paradox.Shaders.Compiler;
13 
14 namespace SiliconStudio.Paradox.Assets.Effect
15 {
16  internal class LightingAssetCompiler : AssetCompilerBase<LightingAsset>
17  {
18  protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, LightingAsset asset, AssetCompilerResult result)
19  {
20  result.ShouldWaitForPreviousBuilds = false;
21  result.BuildSteps = new ListBuildStep { new LightingConfigurationCompileCommand(urlInStorage, asset, context) };
22  }
23 
24  private class LightingConfigurationCompileCommand : AssetCommand<LightingAsset>
25  {
26  private readonly AssetCompilerContext context;
27 
28  private UFile assetUrl;
29 
30  public LightingConfigurationCompileCommand(string url, LightingAsset value, AssetCompilerContext context)
31  : base(url, value)
32  {
33  this.context = context;
34  assetUrl = new UFile(url);
35  }
36 
37  protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
38  {
39  var compiler = new LightingCompileGenerator(asset, context);
40  var results = compiler.Execute();
41 
42  if (results != null && results.Count != 0)
43  {
44  // Check unrolls
45  // NOTE: this is note safe since it is possible that the parameters are overridden somewhere else... but the user should not do that
46  var configDict = new Dictionary<LightingConfigurationData, CompilerParameters>();
47  foreach (var perm in results)
48  {
49  configDict.Add(new LightingConfigurationData(perm), perm);
50  }
51  var configList = configDict.Select(x => x.Key).ToList();
52  configList.Sort((x, y) => x.TotalLightCount - y.TotalLightCount);
53  // TODO: remove duplicates
54  LightingConfigurationData.CheckUnrolls(configList.ToArray());
55 
56  var configs = new LightingConfigurationsSetData();
57  configs.Configs = configList.ToArray();
58 
59  var assetManager = new AssetManager();
60  assetManager.Save(assetUrl, configs);
61  }
62  return Task.FromResult(ResultStatus.Successful);
63  }
64  }
65  }
66 }
Result of a compilation of assets when using IAssetCompiler.Compile
Data type for SiliconStudio.Paradox.Effects.LightingConfiguration.
Definition: EngineData.cs:95
Data type for SiliconStudio.Paradox.Effects.LightingConfigurationsSet.
Definition: EngineData.cs:139
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
A command processing an Asset.
Definition: AssetCommand.cs:11
The context used when compiling an asset in a Package.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13