Write Test

This section describes the write test process used on generated fragment information to determine if a fragment should be written to the framebuffer.

The framebuffer is a memory region for temporarily storing data output from the fragment shader.
Values for fragments for which processing by fragment using the blender has ended are stored here.

The table below gives an overview of the three buffers that collectively make up the framebuffer.

Buffer Type Usage
Color Buffer Renders fragment values that contain color and alpha values.
Stencil Buffer Stores information that limits the area being rendered. This is used during stencil tests.
Depth Buffer Stores information about the depth from the camera. This is used during depth tests.

Types of Write Test

The write test takes generated fragment information as a reference value and determines whether to actually write it to the framebuffer. This is carried out for each fragment. Specify the standard by which to judge fragments in CreativeStudio. Fragments that do not meet the standard are excluded from rendering.

The table below lists the conditions by which a fragment is judged during blending.

Conditions Description
Alpha test An alpha test compares a fragment's alpha value with the reference value set for the alpha test.
Stencil test A stencil test compares the value set for the fragment stencil test with the value in the stencil buffer to write to. If the fragment passes, the value in the stencil buffer is overwritten with the fragment value.
Depth test A depth test compares the per-fragment depth value indicating the distance from the camera with the value in the depth buffer to write to. If the fragment passes, the value in the depth buffer is overwritten with the fragment value.

Write tests are carried out in alpha test → depth test → stencil test order.

Alpha test

The alpha test compares the alpha values of fragments against a reference value to determine which fragments to use.
If the test results do not satisfy conditions, the fragment is removed as a rendering target.
Fragments that meet the conditions pass the alpha test and will be used, so their status is shown as passed.
Fragments that have passed this test are handed on to the Stencil Test process.
This is used to express translucency in textures and other images that use alpha values.

Alpha Test Comparison Functions

The alpha value is information stored in a fragment that indicates that fragment's transparency.
The values range from 0 (fully transparent) to 1 (fully opaque).

The alpha test reference value is a value that can be set using CreativeStudio for comparison with the alpha value for each fragment.

The alpha test comparison function is a formula used to compare the reference value with the alpha value of each fragment.
With CreativeStudio, you can select from eight different comparison functions.

The table below gives the different alpha test comparison functions and a description of each.

Comparison function Function Name Description
All fail NEVER Never passes.
All pass ALWAYS Always passes.
Pass if less than the reference value LESS Passes if the fragment alpha value is less than the reference value.
Pass if less than or equal to the reference value L_EQUAL Passes if the fragment alpha value is less than or equal to the reference value.
Pass if equal to the reference value EQUAL Passes if the fragment alpha value is equal to the reference value.
Pass if greater than or equal to the reference value G_EQUAL Passes if the fragment alpha value is greater than or equal to the reference value.
Pass if greater than the reference value GREATER Passes if the fragment alpha value is greater than the reference value.
Pass if not equal to the reference value NOT_EQUAL Passes if the fragment alpha value is not equal to the reference value.

The table figure below depicts the flow of the alpha test process.

Alpha test

Stencil test

The stencil test compares the value in the stencil buffer with a stencil reference value to determine which fragments to use.
If the test results do not satisfy conditions, the fragment is removed as a rendering target.
Fragments that meet the conditions pass the alpha test and will be used, so their status is shown as passed.
Fragments that have passed through are handed on to the depth test process.
In addition, the stencil buffer can be updated using the value for a fragment that has passed through.
The stencil test is primarily used by the mask process, which limits the region to be rendered.

Stencil Test Comparison Functions

The stencil test reference value is a value that can be set using CreativeStudio for comparison with the value in the stencil buffer.

The stencil buffer is a memory region that stores a mask limiting the region to be rendered stored in the fragment.

The stencil test comparison function is a formula used to compare the reference value with the value in the stencil buffer.
With CreativeStudio, you can select from eight different comparison functions.

The table below gives the different stencil test comparison functions and a description of each.

Comparison function Function Name Description
All fail NEVER Never passes.
All pass ALWAYS Always passes.
Pass if less than the stencil buffer value LESS Passes if the reference value is less than the stencil buffer value.
Pass if less than or equal to stencil buffer value L_EQUAL Passes if the reference value is less than or equal to the stencil buffer value.
Pass if equal to stencil buffer value EQUAL Passes if the reference value is equal to the stencil buffer value.
Pass if greater than or equal to stencil buffer value G_EQUAL Passes if the reference value is greater than or equal to the stencil buffer value.
Pass if greater than stencil buffer value GREATER Passes if the reference value is greater than the stencil buffer value.
Pass if not equal to stencil buffer value NOT_EQUAL Passes if the reference value is not equal to the stencil buffer value.

Detailed Control of the Stencil Test

With the stencil test, you can specify in detail the range of stencil values to be tested using the value set for the test mask. The default value is 255, which specifies the entire range.

Processing After Stencil Test and Depth Test Comparison

It is possible to determine at the fragment level what to do with the frame buffer regarding fragments that have been determined for use by the stencil test.
To update the stencil buffer value, the result of both the stencil test and the depth test are required.

The possible results for a given fragment when using a comparison test that combines the stencil test and depth test have been gathered together in the following table.

Item Description
When the stencil test fails: This is the processing when a fragment fails the stencil test. Subsequent depth test processing is not carried out.
When the depth test fails: This is the processing when a fragment has been determined for use by the stencil test, but failes the depth test.
When the depth test succeeds: This is the processing when a fragment has been determined for use by both the stencil test and depth test.

The stencil buffer value existing in the same location as the associated fragment can be updated based on the result of stencil test and depth test comparison. With CreativeStudio, you can select the operation to perform for the stencil value at this time from one of eight different functions

The following table lists the functions that can be used on stencil values.

Item Function Name Description
Store current value KEEP This is the default setting. Stores the current stencil value. The stencil buffer value is not updated.
Replace with zero ZERO Updates the stencil buffer value to 0.
Replace with reference value REPLACE Updates the stencil buffer value using the stencil test reference value.
Increase (extreme clamping) INCR Increases the stencil buffer value by 1.
The stencil value is clamped to 0 or 1 less than the nth power of 2. (Where n is the number of bits of the stencil buffer.)
Increase (extreme wraparound) INCR_WRAP Increases the stencil buffer value by 1.
However, if the stencil buffer value exceeds 1 and is increased, the value is wrapped.
Decrease (extreme clamping) DECR Decreases the stencil buffer value by 1.
The stencil value is clamped to 0 or 1 less than the nth power of 2. (Where n is the number of bits of the stencil buffer.)
Decrease (extreme wraparound) DECR_WRAP Decreases the stencil buffer value by 1.
However, if the stencil buffer value exceeds 0 and is decreased, the value is wrapped.
Invert all bits INVERT Inverts the stencil buffer value at the bit unit level.

A bit unit is the minimum unit of data handled.

The table figure below depicts the flow of the stencil test process.

Stencil test

Depth test

The term depth test refers to the process used to determine fragments to be used based on the result of comparing the depth value of the fragment with the depth value of the depth buffer.
If the test results do not satisfy conditions, the fragment is removed as a rendering target.
If test results satisfy conditions, the status of fragments selected for use are said to have passed. Fragments that have passed through undergo a blender process and are written to the frame buffer. The depth buffer can also be updated using the depth values of fragments that have passed by enabling a depth mask. This is usually used in hidden surface removal, when hidden polygons are excluded from processing.

Depth Test Comparison Functions

The depth value is information stored in a fragment that indicates that fragment's distance from the camera. This is also called depth information.
Small values indicate that the fragment is closer to the viewpoint, while large values indicate that the fragment is farther away.

The depth buffer is a memory region for storing depth values.

The depth test comparison function is a formula used to compare the depth buffer value with the depth value of each fragment.
With CreativeStudio, you can select from eight different comparison functions.

The table below gives the different depth test comparison functions and a description of each.

Comparison function Function Name Description
All fail NEVER Never passes.
All pass ALWAYS Always passes.
Pass if less than depth buffer value LESS Passes if the depth value of the fragment is less than the depth buffer value.
Pass if less than or equal to depth buffer value L_EQUAL Passes if the depth value of the fragment is less than or equal to the depth buffer value.
Pass if equal to depth buffer value EQUAL Passes if the depth value of the fragment is equal to the depth buffer value.
Pass if greater than or equal to depth buffer value G_EQUAL Passes if the depth value of the fragment is greater than or equal to the depth buffer value.
Pass if greater than depth buffer value GREATER Passes if the depth value of the fragment is greater than the depth buffer value.
Pass if not equal to depth buffer value NOT_EQUAL Passes if the depth value of the fragment is not equal to the depth buffer value.

The figure below shows how the depth test works.

Depth test

Write Test Performance

Using write tests increases processor load. Consequently, all fragment tests and operations are disabled by default.


CONFIDENTIAL