Skip to content

Commit

Permalink
Merge pull request #233 from ninjamike1211/main
Browse files Browse the repository at this point in the history
refactor: Directives: move constants and shaders.properties out of Di…
  • Loading branch information
ninjamike1211 authored Jun 6, 2024
2 parents b5dda21 + 2dd6664 commit 675cf98
Show file tree
Hide file tree
Showing 66 changed files with 71 additions and 71 deletions.
8 changes: 4 additions & 4 deletions src/content/docs/reference/Buffers/colortex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ There are 16 color attachements available through the `colortex0` through `color
*Note*: The `final.fsh` program appears to write to `colortex0`, however it actually writes to a display buffer with the resolution of the Minecraft window and `RGBA` format (usually equates to `RGBA8`) regardless of the size or format of `colortex0`. If `colortex0` is set to non-clearing, any output written by `final.fsh` will not impact `colortex0`.

#### Writing to ColorTex buffers
Any [`begin`](/reference/programs/begin), [`prepare`](/reference/programs/prepare), [`gbuffers`](/reference/programs/gbuffers), [`deferred`](/reference/programs/deferred), or [`composite`](/reference/programs/composite) program can write to a colortex buffer, the buffers to write to can be selected with the [`RENDERTARGETS`](/reference/directives/constants/rendertargets) or [`DRAWBUFFERS`](/reference/directives/constants/drawbuffers) directive.
Any [`begin`](/reference/programs/begin), [`prepare`](/reference/programs/prepare), [`gbuffers`](/reference/programs/gbuffers), [`deferred`](/reference/programs/deferred), or [`composite`](/reference/programs/composite) program can write to a colortex buffer, the buffers to write to can be selected with the [`RENDERTARGETS`](/reference/constants/rendertargets) or [`DRAWBUFFERS`](/reference/constants/drawbuffers) directive.

Additionally, you can read and write to the first 6 colortex buffer in Optifine or any colortex buffer in Iris using `colorimgN` where `N` is replaced with the colortex index. This is the only way to write to colortex buffers from compute shaders, but also works in any program. For more information on image load/store, see the [Khronos Wiki](https://www.khronos.org/opengl/wiki/Image_Load_Store).

#### Buffer size
These buffers default to the display resolution, although this can be configured with the [`size.buffer`](/reference/directives/shadersproperties/buffer_size) define in shaders.properties. However, changing the buffer size will prevent any [`gbuffer`](/reference/programs/gbuffers) program from writing to the texture.
These buffers default to the display resolution, although this can be configured with the [`size.buffer`](/reference/shadersproperties/buffer_size) define in shaders.properties. However, changing the buffer size will prevent any [`gbuffer`](/reference/programs/gbuffers) program from writing to the texture.

#### Buffer format/precision
All buffers default to `RGBA` format (which is `RGBA8` on most systems), but this can be configured as described in the [Texture Formats](/reference/buffers/texture_format) section.

#### Buffer clear
By default all buffers clear their values after each frame to solid black (all 0s including alpha), except `colortex0` which clears to the [`fogColor`](/reference/uniforms/general/fogcolor) with 1.0 alpha, and `colortex1` which clears to solid white (all 1s including alpha). This clearing behavior can be configured with the [`colortexNClear`](/reference/directives/constants/buffer_clear) directive, and the clear color can be configured with the [`colortexNClearColor`](/reference/directives/constants/buffer_clear_color) directive.
By default all buffers clear their values after each frame to solid black (all 0s including alpha), except `colortex0` which clears to the [`fogColor`](/reference/uniforms/general/fogcolor) with 1.0 alpha, and `colortex1` which clears to solid white (all 1s including alpha). This clearing behavior can be configured with the [`colortexNClear`](/reference/constants/buffer_clear) directive, and the clear color can be configured with the [`colortexNClearColor`](/reference/constants/buffer_clear_color) directive.

#### Ping-Pong buffers
Each colortex sampler actually contains two buffers, which allows you to read and write to the same buffer in a composite/deferred pass. The buffer flipping behavior can be controlled with the [`flip.<program>.<buffer>`](/reference/directives/shadersproperties/buffer_flip) directive.
Each colortex sampler actually contains two buffers, which allows you to read and write to the same buffer in a composite/deferred pass. The buffer flipping behavior can be controlled with the [`flip.<program>.<buffer>`](/reference/shadersproperties/buffer_flip) directive.

#### Legacy Aliases
The first 8 colortex buffers have legacy aliases, although their names are often confusing and their use is not recommended. Except as noted below, either name can be used interchangably. The names are as follows:
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/reference/Buffers/noisetex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sidebar:

### `uniform sampler2D noisetex;`

This buffer stores a generated RGB white noise texture. The resolution of this texture can be configured with the [`noiseTextureResolution`](/reference/directives/constants/noisetextureresolution) constant, and defaults to 256x256. The texture is always square, meaning its width and height are equal.
This buffer stores a generated RGB white noise texture. The resolution of this texture can be configured with the [`noiseTextureResolution`](/reference/constants/noisetextureresolution) constant, and defaults to 256x256. The texture is always square, meaning its width and height are equal.
8 changes: 4 additions & 4 deletions src/content/docs/reference/Buffers/shadowcolor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Aside } from '@astrojs/starlight/components';
The shadow pass supplies two color attachments for outputing color/data, `shadowcolor0` and `shadowcolor1`. These samplers can be read from any program, and can be written to from the fragment stage of the [`shadow`](/reference/programs/shadow) and [`shadowcomp`](/reference/programs/shadow_comp) programs.

#### Writing to ShadowColor buffers
Any [`shadow`](/reference/programs/shadow) or [`shadowcomp`](/reference/programs/shadow_comp) program can write to a shadowcolor buffer, the buffers to write to can be selected with the [`RENDERTARGETS`](/reference/directives/constants/rendertargets) or [`DRAWBUFFERS`](/reference/directives/constants/drawbuffers) directive.
Any [`shadow`](/reference/programs/shadow) or [`shadowcomp`](/reference/programs/shadow_comp) program can write to a shadowcolor buffer, the buffers to write to can be selected with the [`RENDERTARGETS`](/reference/constants/rendertargets) or [`DRAWBUFFERS`](/reference/constants/drawbuffers) directive.

Additionally, you can read and write to `shadowcolor0` and `shadowcolor1` using the image bindings `shadowcolorimg0` through `shadowcolorimg1` in any program. This is the only way to write to shadowcolor buffers from compute shaders. For more information on image load/store, see the [Khronos Wiki](https://www.khronos.org/opengl/wiki/Image_Load_Store).

Expand All @@ -25,13 +25,13 @@ These buffers default to the shadow pass resolution, which can be controlled wit
These buffers default `RGBA` format (which defaults to `RGBA8` on most systems), but this can be configured as described in the [Texture Formats](/reference/buffers/texture_format) section.

#### Buffer clear
By default these buffers clear their values after each frame to solid white (all 1s including alpha) This clearing behavior can be configured with the [`shadowcolorNClear`](/reference/directives/constants/buffer_clear) directive, and the clear color can be configured with the [`shadowcolorNClearColor`](/reference/directives/constants/buffer_clear_color) directive.
By default these buffers clear their values after each frame to solid white (all 1s including alpha) This clearing behavior can be configured with the [`shadowcolorNClear`](/reference/constants/buffer_clear) directive, and the clear color can be configured with the [`shadowcolorNClearColor`](/reference/constants/buffer_clear_color) directive.

#### Ping-Pong buffers
Each colortex sampler actually contains two buffers, which allows you to read and write to the same buffer in a composite/deferred pass. The buffer flipping behavior can be controlled with the [`flip.<program>.<buffer>`](/reference/directives/shadersproperties/buffer_flip) directive.
Each colortex sampler actually contains two buffers, which allows you to read and write to the same buffer in a composite/deferred pass. The buffer flipping behavior can be controlled with the [`flip.<program>.<buffer>`](/reference/shadersproperties/buffer_flip) directive.

#### Legacy Alias
The sampler `shadowcolor0` is also accessible through the legacy `shadowcolor` alias.

#### Extended Shadowcolor
The [Feature Flag](/reference/directives/shadersproperties/flags) `HIGHER_SHADOWCOLOR` enables additional shadowcolor buffers, `shadowcolor2` through `shadowcolor7`. These are identical to the other shadowcolor buffers outside of their name.
The [Feature Flag](/reference/shadersproperties/flags) `HIGHER_SHADOWCOLOR` enables additional shadowcolor buffers, `shadowcolor2` through `shadowcolor7`. These are identical to the other shadowcolor buffers outside of their name.
4 changes: 2 additions & 2 deletions src/content/docs/reference/Buffers/shadowtex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ These buffers are written to by [`shadow`](/reference/programs/shadow) program,
These buffers only store information in a single channel, the red component. The shadow buffer precision is hardware/driver dependent, however most hardware uses either 24-bit or 32-bit precision. The resolution of the shadow pass can be controlled with the `shadowMapResolution` constant.

#### Hardware Sampling
[`shadowHardwareFiltering`](/reference/directives/constants/shadowhardwarefiltering) enables support hardware sampling (depth comparison mode) for hardware shadow filtering. This turns the shadowtex samplers into `sampler2DShadow` samplers, which when sampled take the full xyz coordinates of the shadow position. The passed z coordinate is then compared to the values in the buffer around the xy coordinate, and the result is the weighted average of these comparisons. This produces a filtering effect on the shadow with very little to no performance impact. More information can be found in the [Khronos Wiki](https://www.khronos.org/opengl/wiki/Sampler_Object#Comparison_mode).
[`shadowHardwareFiltering`](/reference/constants/shadowhardwarefiltering) enables support hardware sampling (depth comparison mode) for hardware shadow filtering. This turns the shadowtex samplers into `sampler2DShadow` samplers, which when sampled take the full xyz coordinates of the shadow position. The passed z coordinate is then compared to the values in the buffer around the xy coordinate, and the result is the weighted average of these comparisons. This produces a filtering effect on the shadow with very little to no performance impact. More information can be found in the [Khronos Wiki](https://www.khronos.org/opengl/wiki/Sampler_Object#Comparison_mode).

When hardware sampling is used, the texture read no longer returns the distance stored in the buffer, but the result of a filtering depth comparison. This prevents its use in algorithms such as PCSS that rely on the actual value stored in the buffer. However Iris enables the use of separate buffers for hardware sampling, `shadowtex0HW` and `shadowtex1HW`, while retaining the original functionality on the base shadowtex buffers. This requires the [`SEPARATE_HARDWARE_SAMPLERS`](/reference/directives/shadersproperties/flags) feature flag as well as setting [`shadowHardwareFiltering`](/reference/directives/constants/shadowhardwarefiltering) to true.
When hardware sampling is used, the texture read no longer returns the distance stored in the buffer, but the result of a filtering depth comparison. This prevents its use in algorithms such as PCSS that rely on the actual value stored in the buffer. However Iris enables the use of separate buffers for hardware sampling, `shadowtex0HW` and `shadowtex1HW`, while retaining the original functionality on the base shadowtex buffers. This requires the [`SEPARATE_HARDWARE_SAMPLERS`](/reference/shadersproperties/flags) feature flag as well as setting [`shadowHardwareFiltering`](/reference/constants/shadowhardwarefiltering) to true.

#### Legacy Aliases
The alias `waterShadow` points to the same buffer as `shadowtex0`. If `waterShadow` is present anywhere in the code, then the alias `shadow` will point to the same buffer as `shadowtex1`, otherwise it will point to the buffer `shadowtex0`.
2 changes: 1 addition & 1 deletion src/content/docs/reference/Buffers/texture_format.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Aside } from '@astrojs/starlight/components';

Color attachments, such as [colortex](/reference/buffers/colortex) and [shadowcolor](/reference/buffers/shadowcolor) buffers, store values in a specific format. The default format is `RGBA` (which equates to `RGBA8` on most systems), however a shader pack can specify the format and precision of each color attachment.

The format for any color attachement can be set using the [\<bufferName\>Format](/reference/directives/constants/buffer_format) directive.
The format for any color attachement can be set using the [\<bufferName\>Format](/reference/constants/buffer_format) directive.

The available texture formats and their meanings are described below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar:

#### Location: any glsl shader file

This Clear directive allows a shader pack to disable clearing for a [colortex](/reference/buffers/colortex) or [shadowcolor](/reference/buffers/shadowcolor) color attachment. This means that the values written to the texture will be retained through the next frame instead of being cleared after every frame. The value the buffer is cleared to is controlled by the [`<bufferName>ClearColor`](/reference/directives/constants/buffer_clear_color) directive.
This Clear directive allows a shader pack to disable clearing for a [colortex](/reference/buffers/colortex) or [shadowcolor](/reference/buffers/shadowcolor) color attachment. This means that the values written to the texture will be retained through the next frame instead of being cleared after every frame. The value the buffer is cleared to is controlled by the [`<bufferName>ClearColor`](/reference/constants/buffer_clear_color) directive.

Replace `<bufferName>` with the name of a sampler (e.g. `colortex2` or `shadowcolor0`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar:

#### Location: any glsl shader file

The ClearColor directive is used when clearing is enabled, and it defines the value stored in a [colortex](/reference/buffers/colortex) or [shadowcolor](/reference/buffers/shadowcolor) buffer after the clear operation (see [buffer clear](/reference/directives/constants/buffer_clear)).
The ClearColor directive is used when clearing is enabled, and it defines the value stored in a [colortex](/reference/buffers/colortex) or [shadowcolor](/reference/buffers/shadowcolor) buffer after the clear operation (see [buffer clear](/reference/constants/buffer_clear)).

Replace `<bufferName>` with the name of a sampler (e.g. `colortex2` or `shadowcolor0`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ sidebar:

#### Location: any fragment stage (.fsh) of any program

The legacy version of the [`RENDERTARGETS`](/reference/directives/constants/rendertargets) directive. This directive can only reference indicies 0 through 9, so `colortex10` through `colortex15` cannot be bound with this directive. Because of this, it is recommended to use [`RENDERTARGETS`](/reference/directives/constants/rendertargets) directive instead as that can access all available buffers.
The legacy version of the [`RENDERTARGETS`](/reference/constants/rendertargets) directive. This directive can only reference indicies 0 through 9, so `colortex10` through `colortex15` cannot be bound with this directive. Because of this, it is recommended to use [`RENDERTARGETS`](/reference/constants/rendertargets) directive instead as that can access all available buffers.

To use this directive replace `XYZ` with the sequence of indices of color attachments. For example, putting `/* DRAWBUFFERS:0178 */` in `composite.fsh` would configure that program to write to `colortex0`, `colortex1`, `colortex7`, and `colortex8`. The comment can be placed anywhere in the `.fsh` file.

More information on how this buffer applies to outputing values is in the [`RENDERTARGETS`](/reference/directives/constants/rendertargets) section.
More information on how this buffer applies to outputing values is in the [`RENDERTARGETS`](/reference/constants/rendertargets) section.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar:

#### Location: any fragment stage (.fsh) of any program

This directive is used to configure which color attachments a fragment program outputs to. Replace `X,Y,Z` with the comma separated list of indices of color attachments. For example, putting `/* RENDERTARGETS: 0,3,7,13 */` in `composite.fsh` would configure that program to write to `colortex0`, `colortex3`, `colortex7`, and `colortex13`. The comment can be placed anywhere in the `.fsh` file. If the directive (or the [`DRAWBUFFERS`](/reference/directives/constants/drawbuffers) directive) is not found in the file, the first 8 buffers will be bound.
This directive is used to configure which color attachments a fragment program outputs to. Replace `X,Y,Z` with the comma separated list of indices of color attachments. For example, putting `/* RENDERTARGETS: 0,3,7,13 */` in `composite.fsh` would configure that program to write to `colortex0`, `colortex3`, `colortex7`, and `colortex13`. The comment can be placed anywhere in the `.fsh` file. If the directive (or the [`DRAWBUFFERS`](/reference/constants/drawbuffers) directive) is not found in the file, the first 8 buffers will be bound.

**Note**: This directive must include the multi-line comments and should be on its own line.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ sidebar:

Sets the radius of the [shadow pass](/reference/programs/shadow) in blocks. The default value is 160 blocks.

By default this does not cull geometry outside that distance, only applying a scaling factor to the shadow projection matrix. However setting [`shadowDistanceRenderMul`](/reference/directives/constants/shadowdistancerendermul) to a positive value will apply culling.
By default this does not cull geometry outside that distance, only applying a scaling factor to the shadow projection matrix. However setting [`shadowDistanceRenderMul`](/reference/constants/shadowdistancerendermul) to a positive value will apply culling.
15 changes: 15 additions & 0 deletions src/content/docs/reference/Constants/shadowDistanceRenderMul.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: shadowDistanceRenderMul
description: shadowDistanceRenderMul
sidebar:
label: shadowDistanceRenderMul
order: 3
---

### `const float shadowDistanceRenderMul = -1.0;`

#### Location: any glsl file

Sets the culling distance multiplier for the [shadow pass](/reference/programs/shadow).

By default this value is `-1`, which means geometry outside the [`shadowDistance`](/reference/constants/shadowdistance) are not culled. Setting this to a positive value applies culling to geometry outside `shadowDistance * shadowDistanceRenderMul` blocks from the camera. For example, `1.0` culls outside [`shadowDistance`](/reference/constants/shadowdistance), `0.5` culls outside half of [`shadowDistance`](/reference/constants/shadowdistance), and `2.0` culls outside twice [`shadowDistance`](/reference/constants/shadowdistance). `shadowDistanceRenderMul` has no effect on the scale of geometry in the [shadow pass](/reference/programs/shadow).
18 changes: 18 additions & 0 deletions src/content/docs/reference/Constants/voxelDistance.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: voxelDistance
description: voxelDistance
sidebar:
label: voxelDistance
order: 3
badge:
text: Iris Only
variant: tip
---

### `const float voxelDistance = 160.0;`

#### Location: composite, deferred, final, prepare

Setting [`shadow.culling = reversed`](/reference/shadersproperties/shadow_culling) in shaders.properties will create an area around the player where geometry in the shadow pass will not be culled. Outside this area, geometry will be culled as if shadow culling was enabled. This "unculled" distance is controled with `const float voxelDistance`, and the culled distance is controlled as normal with `const float shadowDistance` (and cannot be lower than `voxelDistance`). This feature is intended for packs which utilize both voxelization and a shadow map.

It is also recommended (but not required) to use the feature flag [`REVERSED_CULLING`](/reference/shadersproperties/flags) to avoid compatibility issues with older Iris versions.
Loading

0 comments on commit 675cf98

Please sign in to comment.