Linted markdown

Roger 2016-12-19 02:39:17 -05:00
parent 1a3733e03e
commit fd6457989a

@ -1,7 +1,7 @@
Starting with Dolphin 4.0-2554 there has been work done to improve post processing shaders to allow more user configurability without having to modify the shader sources themselves. In order to take advantage of these features, post processing shaders must be updated to take advantage of these new features.
Starting with Dolphin 4.0-2554 there has been work done to improve post processing shaders to allow more user configurability without having to modify the shader sources themselves. In order to take advantage of these features, post processing shaders must be updated to take advantage of these new features.
## Staying Portable
---
The first step to making a great user experience is to try and be as neutral as possible for a Direct3D or OpenGL backend. Once the post processing shaders are implemented in Direct3D, users would like their favourite shaders to work in both video backends.
Some tips for making sure your shader will compile on all backends.
@ -12,13 +12,15 @@ coordinate system using our own functions.
- We try to support GLSL 1.30 and GLSL ES 3.00 minimum. If you don't have a good reason, try to stay away from using OpenGL shader extensions. These aren't portable and we won't be able to work around them. If the functionality of the extension is absolutely necessary, try to talk with some developers to see if we can implement the functionality in both D3D and OGL in a clean fashion using our own functions.
## Configuration Setup
---
The Post Processing shader's configuration sits inside of the actual post processing shader code. It's recommended to have the configuration towards the top of the shader, outside of the main function.
There are two requirements to this
- It must be in a comment block
- It must be surrounded by [configuration] and [/configuration]
The configuration inside of of this block is similar to how Windows' INI files work and we have three sections that we support for different options.
- **[OptionBool]**
- This is a boolean option, this'll show as a checkbox in the GUI
- **[OptionRangeInteger]** or **[OptionRangeFloat]**
@ -26,6 +28,7 @@ The configuration inside of of this block is similar to how Windows' INI files w
- This will show up as one to four sliders in the GUI
Any of these options *require* all three settings set at all times
- **GUIName**
- This is a string that will show up in the GUI for that corresponding option
- **OptionName**
@ -47,6 +50,7 @@ The value of this option must be the 'OptionName' of a [OptionBool]
If you make circular dependencies of options, you reap what you sow.
[OptionRangeInteger] and [OptionRangeFloat] have other **required** settings to be set
- **MinValue**
- This is the minimum value that a integer or float range has
- In a vector each value can have a different value
@ -58,6 +62,7 @@ If you make circular dependencies of options, you reap what you sow.
- In a vector each value can have a different value
Sample Configuration
```bash
/*
[configuration]
@ -97,23 +102,29 @@ DependentOption = BEVEL
[/configuration]
*/
```
## Embedded Functions
---
```c++
float4 Sample();
```
Samples the current location, returning a vector containing the colour of the current sample
***
```c++
float4 SampleLocation(float2 location);
```
Samples a location that doesn't have to be the current sample location
location is a float vector which contains the X Y coordinates of where to sample from.
The sample range is 0.0 to 1.0 using the OpenGL coordinate system
***
```c++
float4 SampleOffset(int2 offset);
```
This samples at a offset of the current location.
The argument is a integer vector containing the X Y offset of where to sample from.
The offset is in pixels instead of using UV coordinates.
@ -121,68 +132,90 @@ This requires the offset to be a compile time constant, if it isn't then compili
This is similar to SampleLocation, except the video drivers and hardware can optimize to be faster.
This is a limitation in how large the offset can be. To be safe on all platforms, limit the offset from ranges -8 to 7.
***
```c++
float4 SampleFontLocation(float2 location);
```
This doesn't sample the framebuffer like the previous functions.
This actually samples a location from Dolphin's bitmap font that it uses for on screen text.
The best example of how to use this is to look at Dolphin's asciiart PP shader
***
```c++
float2 GetResolution();
```
Returns a float vector contain the resolution of the framebuffer
***
```c++
float2 GetInvResolution();
```
Returns a float vector containing the reciprocal of the framebuffer resolution
This can be used to quickly get a float offset from the current sample position
***
```c++
float2 GetCoordinates();
```
Returns a float vector containing the UV coordinates where we are currently sampling from
This can be used when sampling from a location offset from the current location.
Tends to be used in conjunction with GetInvResolution()
Recommended to use SampleOffset instead if the offset is a compile time constant
***
```c++
uint GetTime();
```
This returns a 32bit unsigned integer of the elapsed time since emulation has started
The time is in milliseconds
This allows for shaders that can do certain effects with the passage of time
***
```c++
void SetOutput(float4 colour);
```
The argument is a float vector containing what the resulting output should be at the current sampling location
***
```c++
bool OptionEnabled(option);
```
Returns a boolean for if a boolean option is enabled or not
This only works for the Option type configuration option
Takes the OptionName that was defined in the configuration
- Example
```c++
if (OptionEnabled(BEVEL)) { /* Do Stuff*/ }
```
***
```c++
genType GetOption(option);
```
Returns an options current setting
genType is either int, float, float2/3/4, int2/3/4
Depending on what type your option is in the configuration it'll return the correct type here
Takes the OptionName that was defined in the configuration
- Example
```c++
float3 colour_boost = GetOption(SKY_COLOR);
```
## Sample Shader
---
```c++
/*
[configuration]
@ -280,32 +313,33 @@ void main() {
if (OptionEnabled(SHARPNESS))
{
float3 s0 = SampleOffset(int2(-1, -1)).xyz;
float3 s1 = SampleOffset(int2( 1, -1)).xyz;
float3 s2 = SampleOffset(int2(-1, 1)).xyz;
float3 s3 = SampleOffset(int2( 1, 1)).xyz;
float3 blur = (curr + s0 + s1 + s2 + s3) / 5;
curr = curr + (curr - blur) * GetOption(SHARPNESS_VALUE);
float3 s0 = SampleOffset(int2(-1, -1)).xyz;
float3 s1 = SampleOffset(int2( 1, -1)).xyz;
float3 s2 = SampleOffset(int2(-1, 1)).xyz;
float3 s3 = SampleOffset(int2( 1, 1)).xyz;
float3 blur = (curr + s0 + s1 + s2 + s3) / 5;
curr = curr + (curr - blur) * GetOption(SHARPNESS_VALUE);
}
if (OptionEnabled(BEVEL))
{
float mid = dot(curr, float3(0.33, 0.33, 0.33));
float top = dot(SampleOffset(int2(0, 1)).xyz, float3(0.33, 0.33, 0.33));
float bot = dot(SampleOffset(int2(0, -1)).xyz, float3(0.33, 0.33, 0.33));
float upw = ((top - mid) + (mid - bot)) / 4 + 0.5;
float3 col = mix(GetOption(SKY_COLOR), GetOption(GROUND_COLOR), upw);
float3 shde = mix(GetOption(BASE_COLOR), col, clamp(abs(upw * 2.0 - 1.0) * 1, 0.0, 1.0));
curr = curr + shde * GetOption(SKYLIGHT_AMOUNT);
float mid = dot(curr, float3(0.33, 0.33, 0.33));
float top = dot(SampleOffset(int2(0, 1)).xyz, float3(0.33, 0.33, 0.33));
float bot = dot(SampleOffset(int2(0, -1)).xyz, float3(0.33, 0.33, 0.33));
float upw = ((top - mid) + (mid - bot)) / 4 + 0.5;
float3 col = mix(GetOption(SKY_COLOR), GetOption(GROUND_COLOR), upw);
float3 shde = mix(GetOption(BASE_COLOR), col, clamp(abs(upw * 2.0 - 1.0) * 1, 0.0, 1.0));
curr = curr + shde * GetOption(SKYLIGHT_AMOUNT);
}
if (OptionEnabled(COLOR_BOOST))
curr = curr * float3(GetOption(RED_BOOST), GetOption(GREEN_BOOST), GetOption(BLUE_BOOST));
curr = curr * float3(GetOption(RED_BOOST), GetOption(GREEN_BOOST), GetOption(BLUE_BOOST));
/* Done */
SetOutput(float4(curr, 1.0));
}
```
## Translations
---
**TBD**