Debian Codegraph @

docs/CustomPipelineGraphicsMod.md

raw symbols SCIP
1 # Dolphin Custom Pipeline Specification
2
3 Dolphin provides content creators a way to overwrite its internal graphics pipeline data using graphics mods. At the moment, this supports modifying only the pixel shader. This document will describe the specification and give some examples.
4
5 ## Graphics mod metadata format
6
7 This feature is powered by graphics mods. This document assumes the user is familiar with them and will only detail the action specific data needed to trigger this capability.
8
9 The action type for this feature is `custom_pipeline`. This action has the following data:
10
11 |Identifier |Required | Since |
12 |-------------------------|---------|-------|
13 |``passes`` | **Yes** | v1 |
14
15 `passes` is an array of pass blobs. Note that at the moment, Dolphin only supports a single pass. Each pass can have the following data:
16
17 |Identifier |Required | Since |
18 |-------------------------|---------|-------|
19 |``pixel_material_asset`` | **Yes** | v1 |
20
21 Here `pixel_material_asset` is the name of a material asset.
22
23 A full example is given below:
24
25 ```json
26 {
27 "assets": [
28 {
29 "name": "material_replace_normal",
30 "data":
31 {
32 "": "normal.material.json"
33 }
34 },
35 {
36 "name": "shader_replace_normal",
37 "data":
38 {
39 "metadata": "replace_normal.shader.json",
40 "shader": "replace_normal.glsl"
41 }
42 },
43 {
44 "name": "normal_texture",
45 "data":
46 {
47 "texture": "normal_texture.png"
48 }
49 }
50 ],
51 "features": [
52 {
53 "action": "custom_pipeline",
54 "action_data": {
55 "passes": [
56 {
57 "pixel_material_asset": "material_replace_normal"
58 }
59 ]
60 },
61 "group": "PipelineTarget"
62 }
63 ],
64 "groups": [
65 {
66 "name": "PipelineTarget",
67 "targets": [
68 {
69 "texture_filename": "tex1_512x512_m_afdbe7efg332229e_14",
70 "type": "draw_started"
71 },
72 {
73 "texture_filename": "tex1_512x512_m_afdbe7efg332229e_14",
74 "type": "create_texture"
75 }
76 ]
77 }
78 ]
79 }
80 ```
81
82 ## The shader format
83
84 The shaders are written in GLSL and converted to the target shader that the backend uses internally. The user is expected to provide an entrypoint with the following signature:
85
86 ```
87 CustomShaderOutput custom_main( in CustomShaderData data )
88 ```
89
90 `CustomShaderOutput` is used to denote the final output that Dolphin will process and is what is returned by the function. It has the following structure:
91
92 |Name | Type | Since | Description |
93 |-------------------------|-------------------------|-------|-------------------------------------------------------------------------------------------------|
94 |``main_rt`` | vec4 | v1 | The main render target's output color |
95
96 `CustomShaderData` encompasses all the data that Dolphin will pass to the user (in addition to the `samp` variable outlined above which is how textures are accessed). It has the following structure:
97
98 |Name | Type | Since | Description |
99 |-----------------------------|-------------------------|-------|----------------------------------------------------------------------------------------------------------------------|
100 |``position`` | vec3 | v1 | The position of this pixel in _view space_ |
101 |``normal`` | vec3 | v1 | The normal of this pixel in _view space_ |
102 |``texcoord`` | vec3[] | v1 | An array of texture coordinates, the amount available is specified by ``texcoord_count`` |
103 |``texcoord_count`` | uint | v1 | The count of texture coordinates |
104 |``texmap_to_texcoord_index`` | uint[] | v1 | An array of texture units to texture coordinate values |
105 |``lights_chan0_color`` | CustomShaderLightData[] | v1 | An array of color lights for channel 0, the amount is specified by ``light_chan0_color_count`` |
106 |``lights_chan0_alpha`` | CustomShaderLightData[] | v1 | An array of alpha lights for channel 0, the amount is specified by ``light_chan0_alpha_count`` |
107 |``lights_chan1_color`` | CustomShaderLightData[] | v1 | An array of color lights for channel 1, the amount is specified by ``light_chan1_color_count`` |
108 |``lights_chan1_alpha`` | CustomShaderLightData[] | v1 | An array of alpha lights for channel 1, the amount is specified by ``light_chan1_alpha_count`` |
109 |``ambient_lighting`` | vec4[] | v1 | An array of ambient lighting values. Count is two, one for each color channel |
110 |``base_material`` | vec4[] | v1 | An array of the base material values. Count is two, one for each color channel |
111 |``tev_stages`` | CustomShaderTevStage[] | v1 | An array of TEV stages, the amount is specified by ``tev_stage_count`` |
112 |``tev_stage_count`` | uint | v1 | The count of TEV stages |
113 |``final_color`` | vec4 | v1 | The final color generated by Dolphin after all TEV stages are executed |
114 |``time_ms`` | uint | v1 | The time that has passed in milliseconds, since the game was started. Useful for animating |
115
116 `CustomShaderLightData` is used to denote lighting data the game is applying when rendering the specific draw call. It has the following structure:
117
118 |Name | Type | Since | Description |
119 |-------------------------|-------------------------|-------|-------------------------------------------------------------------------------------------------|
120 |``position`` | vec3 | v1 | The position of the light in _view space_ |
121 |``direction`` | vec3 | v1 | The direction in _view space_ the light is pointing (only applicable for point and spot lights) |
122 |``color`` | vec3 | v1 | The color of the light |
123 |``attenuation_type`` | uint | v1 | The attentuation type of the light. See details below |
124 |``cosatt`` | vec4 | v1 | The cos attenuation values used |
125 |``distatt`` | vec4 | v1 | The distance attenuation values used |
126
127 The `attenuation_type` is defined as a `uint` but is effecitvely an enumeration. It has the following values:
128
129 |Name | Since | Description |
130 |--------------------------------------------------|-------|-------------------------------------------------------------------------|
131 |``CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_POINT`` | v1 | This value denotes the lighting attentuation is for a point light |
132 |``CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_DIR`` | v1 | This value denotes the lighting attentuation is for a directional light |
133 |``CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_SPOT`` | v1 | This value denotes the lighting attentuation is for a directional light |
134
135
136 `CustomShaderTevStage` is used to denote the various TEV operations. Each operation describes a graphical operation that the game is applying when rendering the specific draw call. It has the following structure:
137
138 |Name | Type | Since | Description |
139 |-------------------------|----------------------------------|-------|-------------------------------------------------------------------------------|
140 |``input_color`` | CustomShaderTevStageInputColor[] | v1 | The four color inputs that are used to produce the final output of this stage |
141 |``input_alpha`` | CustomShaderTevStageInputAlpha[] | v1 | The four alpha inputs that are used to produce the final output of this stage |
142 |``texmap`` | uint | v1 | The texture unit for this stage |
143 |``output_color`` | vec4 | v1 | The final output color this stage produces |
144
145
146 `CustomShaderTevStageInputColor` is a single input TEV operation for a color value. It has the following structure:
147
148 |Name | Type | Since | Description |
149 |-------------------------|------|-------|-------------------------------------------------|
150 |``input_type`` | uint | v1 | The input type of the input. See details below |
151 |``value`` | vec3 | v1 | The value of input |
152
153 The `input_type` is defined as a `uint` but is effectively an enumeration. it has the following values:
154
155 |Name | Since | Description |
156 |--------------------------------------------------|-------|---------------------------------------------------------------------------|
157 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_PREV`` | v1 | The value is provided by the last stage |
158 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_COLOR`` | v1 | The value is provided by the color data |
159 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_TEX`` | v1 | The value is provided by a texture |
160 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_RAS`` | v1 | |
161 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_KONST`` | v1 | The value is a constant value defined by the software |
162 |``CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_NUMERIC`` | v1 | The value is a constant numeric value like vec3(0, 0, 0) or vec3(1, 1, 1) |
163
164 `CustomShaderTevStageInputAlpha` is a single input TEV operation for an alpha value. It has the following structure:
165
166 |Name | Type | Since | Description |
167 |-------------------------|------|-------|-------------------------------------------------------------------------------|
168 |``input_type`` | uint | v1 | The input type of the input. See `input_type` for color input stages |
169 |``value`` | uint | v1 | The value of input |
170
171
172 ## Examples
173
174 Below are a handful of examples.
175
176 ### Single color
177
178 The following shader displays the color red on the screen:
179
180 ```glsl
181 CustomShaderOutput custom_main( in CustomShaderData data )
182 {
183 CustomShaderOutput custom_output;
184 custom_output.main_rt = vec4(1.0, 0.0, 0.0, 1.0);
185 return custom_output;
186 }
187 ```
188
189 ### Normal
190
191 The following shader displays the normal on the screen:
192
193 ```glsl
194 CustomShaderOutput custom_main( in CustomShaderData data )
195 {
196 CustomShaderOutput custom_output;
197 custom_output.main_rt = vec4(data.normal * 0.5 + 0.5, 1);
198 return custom_output;
199 }
200 ```
201
202 ### Reading a texture
203
204 The following shader displays the contents of the texture denoted in the shader asset as `MY_TEX` with the first texture coordinate data:
205
206 ```glsl
207 CustomShaderOutput custom_main( in CustomShaderData data )
208 {
209 CustomShaderOutput custom_output;
210 custom_output.main_rt = texture(samp_MY_TEX, TEX_COORD0);
211 return custom_output;
212 }
213 ```
214
215 ### Capturing the first texture the game renders with
216
217 The following shader would display the contents of the first texture the game uses, ignoring any other operations. If no stages are available or none exist with a texture it would use the final color of all the staging operations:
218
219 ```glsl
220 CustomShaderOutput custom_main( in CustomShaderData data )
221 {
222 vec4 final_color = data.final_color;
223 uint texture_set = 0;
224 for (uint i = 0; i < data.tev_stage_count; i++)
225 {
226 // There are 4 color inputs
227 for (uint j = 0; j < 4; j++)
228 {
229 if (data.tev_stages[i].input_color[j].input_type == CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_TEX && texture_set == 0)
230 {
231 final_color = vec4(data.tev_stages[i].input_color[j].value, 1.0);
232 texture_set = 1;
233 }
234 }
235 }
236
237 CustomShaderOutput custom_output;
238 custom_output.main_rt = final_color;
239 return custom_output;
240 }
241 ```
242
243 ### Applying lighting with a point type attenuation
244
245 The following shader would apply the lighting for any point lights used during the draw for channel 0's color lights, using blue as a base color:
246
247 ```glsl
248 CustomShaderOutput custom_main( in CustomShaderData data )
249 {
250 float total_diffuse = 0;
251 for (int i = 0; i < data.light_chan0_color_count; i++)
252 {
253 if (data.lights_chan0_color[i].attenuation_type == CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_POINT)
254 {
255 vec3 light_dir = normalize(data.lights_chan0_color[i].position - data.position.xyz);
256 float attn = (dot(normal, light_dir) >= 0.0) ? max(0.0, dot(normal, data.lights_chan0_color[i].direction.xyz)) : 0.0;
257 vec3 cosAttn = data.lights_chan0_color[i].cosatt.xyz;
258 vec3 distAttn = data.lights_chan0_color[i].distatt.xyz;
259 attn = max(0.0, dot(cosAttn, vec3(1.0, attn, attn*attn))) / dot(distAttn, vec3(1.0, attn, attn * attn));
260 total_diffuse += attn * max(0.0, dot(normal, light_dir));
261 }
262 }
263
264 CustomShaderOutput custom_output;
265 custom_output.main_rt = vec4(total_diffuse * vec3(0, 0, 1), 1);
266 return custom_output;
267 }
268 ```