The material editor is opened when double-clicking on an asset of type “material” (with the “.pkma” file extension) inside the content browser.
When creating a custom material, there are two things to consider:
- What rendering features are available when this material will be applied to a renderer
- How will this material look in PopcornFX Editor (and in your engine if you rely on PK-SampleLib and PK-RHI SDK libraries to render particles)
- List of available rendering features in the selected rendering interface
- Preview of properties from that rendering feature
- List of rendering features in this custom material. Features can be manually added or drag&drop-ed from section #1. A material can contain features from various .pkri files.
- Preview of available properties on the renderer if this material is applied (and all features are enabled).
Mandatory in section #3 determines whether the rendering feature is enabled by default (and can’t be disabled). In this material, GeometryBillboard, Transparent, Diffuse and EnableRendering are considered the minimum features for this material.
IMPORTANT: It is mandatory that each feature set contains one Geometry* rendering feature (with Mandatory enabled). This feature determines the kind of renderer this material will be compatible with.
- Shader editor type (Available types are Source, PreprocessorIn, PreprocessorOut). Source is the source shader editing mode.
- Type of renderer this material is compatible with, this is because GeometryBillboard is a rendering feature from this feature set.
- Fragment shader path, it is possible that several .pkma files use a common .frag file
- Shader defines available to this fragment shader. There will be one per rendering feature (apart from Geometry* which are mandory) and can be used in the shader code to #ifdef code.
- Available samplers, driven by the .pkri’s rendering feature properties (see rendering feature)
- Generic scene info data
- Per renderer constants, those are rendering feature properties of “Property” type
- Fragment input data, this contains both generic rendering data (fragWorldPosition, ..), mesh rendering data (fragUV0, ..) and per particle “additional inputs” (fragAtlasID, fragColor, fragTextureID, ..)
- Fragment shader expected output
A vertex and fragment shader editor are available to write the shaders, so artists work with a preview of their effects matching the final game engine’s viewport.
IMPORTANT: In v2.4, those shaders are only used for rendering in PK-Editor and any engine integration using PK-SampleLib’s RHI implementation. Those shaders will not be exported to the game engine, so the integrators will have to re-create those materials in the final game engine.
When in the “Source” view mode, saving (Ctrl+S) will trigger an asynchronous shader compilation of all shader permutations (there will be a lot, depending on the number of rendering features in the material).
Note: Shader compilation currently will freeze/slow the UI for several frames. This is a known issue in 2.4.0 and will be addressed in a 2.4 patch.
Writing custom shaders often come with errors. Two additional views are available to inspect those:
- PreprocessorIn -> Final generated shader, passed to mcpp
- PreprocessorOut -> Final shader, passed to the shader compiler
- Switching the view to “Preprocessor in”, we now see the shader (for the selected permutation in #2) before it’s being preprocessed by mcpp
- List of shader permutations generated for this material (combination of all possible rendering features, enabled or not)
This view helps viewing the final generated shader, before it’s preprocessed.
Shader compiler in
This view shows what comes in the shader compiler, after the shader has been preprocessed. This is the final shader code.
Hovering a shader permutation displays the shader error (if any), allowing to find the issue.