Skip to content

Commit 2675be5

Browse files
committed
Add tutorial and docs about using shader source code in materials
1 parent 751b631 commit 2675be5

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

manual/graphics/materials/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Speaking more technically, when light from the scene hits the surface, a Materia
1717
* [Layered Materials](layered-materials/index.md)
1818
* [Instanced Materials](instanced-materials/index.md)
1919
* [Material Functions](material-functions.md)
20+
* [Shader Code in Materials](shader-code-in-material.md)
398 KB
Loading
764 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Shader Code in Materials
2+
3+
This page shows how to use HLSL shader code inside [Materials](basics/index.md) and [Material Functions](material-functions.md).
4+
5+
Flax uses **HLSL** as a shading language as it's very popular in the industry and supports all major graphics rendering features. Additionally, engine will automatically compile HLSL shaders into target platform such as Vulkan or PS4 with full runtime support.
6+
To learn about HLSL syntax see [Reference for HLSL](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-reference) and [Programming guide for HLSL](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-pguide).
7+
8+
For better understanding how shaders are handled by the engine see dedicated documentation section [here](../shaders/index.md).
9+
10+
## Custom Code
11+
12+
![Custom Code node](media/custom-code-node.png)
13+
14+
Custom Code node allows to write raw HLSL code which operates on fixed inputs and outputs. It's rather simple solution for small code chunks that can implement dynamic branching, dynamic loops or invoke shader functions from external sources (eg. shader library files).
15+
16+
## Global Custom Code
17+
18+
![Global Custom Code node](media/custom-global-code-node.png)
19+
20+
Global Custom Code node is more robust as it inlines code at a specific location in the material template. For example, it can inject global preprocessor macros, inject custom header file includes, add shader resources binding, or declare global functions.
21+
22+
Use **Location** dropdown to properly define place of code injection. You can see it in generated shader source code (click on toolbar button).
23+
24+
This node provides an easy way to include custom `.hlsl` files from the project source code folder which can implement certain functionalities in text-based format. To do so, create a shader file in `_project_/Source/Shaders`. Then you can include it via: `#include "./_project_name__/MyFile.hlsl"`. Where `_project_name__` is name of the project from the `_project_.flaxproj` file. This allows to include shaders from plugin projects. See [this page](../shaders/index.md) to learn more (esp. `Including shader files` and `Using shaders` sections).

manual/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
### [Layered Materials](graphics/materials/layered-materials/index.md)
9191
### [Instanced Materials](graphics/materials/instanced-materials/index.md)
9292
### [Material Functions](graphics/materials/material-functions.md)
93+
### [Shader Code in Materials](graphics/materials/shader-code-in-material.md)
9394
## [Decals](graphics/decals/index.md)
9495
### [Decal Actor](graphics/decals/decal.md)
9596
### [How to create a decal](graphics/decals/create-decal.md)

0 commit comments

Comments
 (0)