Custom color transforms
AdvancedProgrammer custom color transform effects. For example, you can create:
- -
1. Create a shader
- Xenko Visual Studio extension installed. This is necessary to convert the shader files from XSL (Xenko shading language) to
.csfiles. - (Open in IDE) to open your project in Visual Studio.
- Solution Explorer, right-click the project (eg MyGame.Game) and select New item.
- Class.
- Name field, specify a name with the extension .xksl (eg MyColorTransformShader.xksl), and click Add.
.csfile from the.xkslfile. The Solution Explorer lists it as a child of the.xsklfile. .xkslfile, remove the existing lines, and write your shader. Shading language.MyColorparameter:shader MyColorTransformShader : ColorTransformShader{ [Color] float4 MyColor; override float4 Compute(float4 color) { return color * MyColor; }};
Note
MyColorTransformShaderin the code above) is the same as the filename (eg MyColorTransformShader.xksl).2. Create a C# class
- Solution Explorer, right-click the project (eg MyGame.Game) and select Add > New item.
- Class, specify a name (eg MyColorTransform.cs), and click Add.
Open the file and write the class.
MyColorTransform, which uses the shader and supplies a value for the colorMyColor(defined in the shader).using Xenko.Core;using Xenko.Core.Mathematics;using Xenko.Rendering;using Xenko.Rendering.Images;namespace MyGame{ [DataContract("MyColorTransform")] public class MyColorTransform : ColorTransform { /// <inheritdoc /> public MyColorTransform() : base("MyColorTransformShader") { } public Color4 MyColor { get; set; } public override void UpdateParameters(ColorTransformContext context) { Parameters.Set(MyColorTransformShaderKeys.MyColor, MyColor); // Copy parameters to parent base.UpdateParameters(context); } }}
Note
MyColorTransformin the class above) is the same as the filename (eg MyColorTransform.cs). - File > Save All).
- In Game Studio, reload the assemblies.
Asset View lists the class and effect shader in the same directory as your scripts (eg MyGame.Game).
Note
In some situations, Game Studio incorrectly detects the shader as a script, as in the screenshot below: File > Reload project).3. Use a custom color transform
- Asset View (in the bottom pane by default), double-click the Graphics Compositor asset. graphics compositor editor opens.
- Post-processing effects node.
- Property Grid, under Color transforms, click (Change) and select your color transform (eg MyColorTransform).
-
-
When you adjust the properties, Game Studio updates the effect automatically.
Warning
Unfortunately, this part of Game Studio has a memory leak problem. Every time you change a value in the graphics compositor, it uses 60MB of memory. To prevent Game Studio using too much memory, we recommend you restart it after you change a property a few times. This is a known issue.See also
- Shading language
- Custom shaders
- Graphics compositor
- Post effects
- Color transforms
- Xenko Visual Studio extension
