Skip to content

Custom Shaders

tobspr edited this page Aug 15, 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

When 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:

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