Skip to content

Custom Shaders

tobspr edited this page Aug 17, 2014 · 16 revisions

Physically Based Shading

The Pipeline uses Physically Based Shading. Your shaders have to output 4 constraints: metallic, roughness, specular, baseColor. You can find a very well explanation of them at the documentation of the UnrealEngine 4 here.

Default Shaders

In case you don't need any special features, you can just use the Default Shader, which you can get with renderPipeline.getDefaultObjectShader(). Your object should have the textures and materials applied like in Exporting from Blender. The pipeline also supports Tesselation.

Otherwise the pipeline already provides a bunch of functions which simplify the material handling. You can have a look at the default fragment shader DefaultShader.fragment, which should be pretty self explanatory. Your shader also has to set the position and normal in world space, also velocity, you can find a basic vertex shader here.

There is a material-editor planned to simplify the creation of new materials.

Loading custom shaders

You can use the builtin Shader.load to load your custom shaders. However, you cannot use includes then. For that purpose, there exists a BetterShader class, which has almost the same interface as Shader, but handles includes and also caches Shaders.

For loading a compute shader:

shader = BetterShader.loadCompute("Path/To/Compute/Shader")

For loading a regular shader, the order is: Vertex, Fragment, Geometry, Tesselation Control, Tesselation Evaluation. You don't have to provide all shaders, so you can pass only a vertex and fragment shader for example:

shader = BetterShader.loadCompute("vertex.glsl", "fragment.glsl")

You can also skip parameters, e.g. if you want to have a vertex, fragment and tesselation shader, but no geometry shader:

shader = BetterShader.loadCompute("vertex.glsl", "fragment.glsl", "", "tesscontrol.glsl", "tesseval.glsl")