Skip to content

Commit 67e62ec

Browse files
committed
add custom fragment shaders
1 parent 646f154 commit 67e62ec

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

source/fragment_shader/index.rst

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Fragment Shader
2+
===============
3+
4+
The :doc:`/types/Renderable/index` :doc:`/entity_component_system/component/index` accepts custom fragment shaders.
5+
6+
These fragment shaders are written in GLSL and have some special variables.
7+
8+
Inputs
9+
------
10+
11+
.. list-table::
12+
:width: 100%
13+
:header-rows: 1
14+
:class: code-table
15+
16+
* - Name
17+
- Type
18+
- Description
19+
* - NtshEngn_position
20+
- vec3
21+
- The fragment's position, in **world-space**.
22+
* - NtshEngn_normal
23+
- vec3
24+
- The fragment's normal.
25+
* - NtshEngn_tangent
26+
- vec3
27+
- The fragment's tangent.
28+
* - NtshEngn_bitangent
29+
- vec3
30+
- The fragment's bitangent.
31+
* - NtshEngn_uv
32+
- vec2
33+
- The fragment's texture coordinates.
34+
* - NtshEngn_tbn
35+
- mat3
36+
- The fragment's Tangent-Bitangent-Normal matrix.
37+
* - NtshEngn_diffuseTextureSampler
38+
- sampler2D
39+
- The object's material's diffuse texture.
40+
* - NtshEngn_normalTextureSampler
41+
- sampler2D
42+
- The object's material's normal texture.
43+
* - NtshEngn_metalnessTextureSampler
44+
- sampler2D
45+
- The object's material's metalness texture.
46+
* - NtshEngn_roughnessTextureSampler
47+
- sampler2D
48+
- The object's material's roughness texture.
49+
* - NtshEngn_occlusionTextureSampler
50+
- sampler2D
51+
- The object's material's occlusion texture.
52+
* - NtshEngn_emissiveTextureSampler
53+
- sampler2D
54+
- The object's material's emissive texture.
55+
* - NtshEngn_emissiveFactor
56+
- float
57+
- The object's material's metalness factor.
58+
* - NtshEngn_alphaCutoff
59+
- float
60+
- The object's material's alpha cutoff.
61+
* - NtshEngn_scaleUV
62+
- vec2
63+
- The object's material's UV scale.
64+
* - NtshEngn_offsetUV
65+
- vec2
66+
- The object's material's UV offset.
67+
* - NtshEngn_useTriplanarMapping
68+
- bool
69+
- ``true`` if the object's material uses triplanar mapping, else, ``false``.
70+
* - NtshEngn_directionalLightCount
71+
- uint
72+
- The number of directional lights in the scene.
73+
* - NtshEngn_directionalLight(i)
74+
- :doc:`/types/Light/index`
75+
- The *i*th directional light.
76+
* - NtshEngn_pointLightCount
77+
- uint
78+
- The number of point lights in the scene.
79+
* - NtshEngn_pointLight(i)
80+
- :doc:`/types/Light/index`
81+
- The *i*th point light.
82+
* - NtshEngn_spotLightCount
83+
- uint
84+
- The number of spot lights in the scene.
85+
* - NtshEngn_spotLight(i)
86+
- :doc:`/types/Light/index`
87+
- The *i*th spot light.
88+
* - NtshEngn_ambientLightCount
89+
- uint
90+
- The number of ambient lights in the scene.
91+
* - NtshEngn_ambientLight(i)
92+
- :doc:`/types/Light/index`
93+
- The *i*th ambient light.
94+
* - NtshEngn_time
95+
- float
96+
- The time since the application's launch, in **seconds**.
97+
* - NtshEngn_cameraPosition
98+
- vec3
99+
- The camera's position, in **world-space**.
100+
* - NtshEngn_useReversedDepth
101+
- bool
102+
- ``true`` if the graphics module uses reversed depth (*1* is close, *0* is far), else, ``false`` (*0* is close, *1* is far).
103+
104+
Inputs
105+
------
106+
107+
.. list-table::
108+
:width: 100%
109+
:header-rows: 1
110+
:class: code-table
111+
112+
* - Name
113+
- Type
114+
- Description
115+
* - NtshEngn_outColor
116+
- vec4
117+
- The output color.
118+
* - NtshEngn_outDepth
119+
- float
120+
- The output depth.

source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ NutshellEngine
1818

1919
./asset_manager/index.rst
2020

21+
./fragment_shader/index.rst
22+
2123
./frame_limiter/index.rst
2224

2325
./job_system/index.rst

source/types/Renderable/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Variables
1818
* - material
1919
- :doc:`/types/Material/index`
2020
- The :doc:`/types/Material/index` to use.
21+
* - fragmentShader
22+
- `std::string <https://en.cppreference.com/w/cpp/string/basic_string>`_
23+
- The custom `/types/fragment_shader/index` to use. If empty, the graphics module's default fragment shader will be used.
2124

2225
Notes
2326
-----
@@ -57,3 +60,7 @@ JSON for the :doc:`/file_formats/ntsn/index` scene file format:
5760
- String
5861
- The path to the material.
5962
- Any path to a material.
63+
* - fragmentShaderPath
64+
- String
65+
- The path to the fragment shader.
66+
- Any path to a fragment shader.

0 commit comments

Comments
 (0)