phase
Direct3D 8 - Pixel Shader - Instructions - phase
Last edited 2026-02-20
The phase instruction is intended to split a shader program into two parts; technically, there can be two programs in a single shader.
Shader instructions appearing before the phase instruction are phase 1 instructions.
All other instructions are phase 2 instructions.
Having two phase instructions increases the maximum number of instructions per shader.
An unfortunate side effect of the phase transition is that the alpha component's temporary registers do not persist throughout the transition.
In other words, the alpha component must be reinitialized after the phase instruction.
Phase only works on ps.1.4, newer and older versions of Pixel Shader do NOT support this instruction
The phase syntax looks like this:
phase;
Example code:
texture img; // <- Main texture
texture bkd; // <- Background texture
technique tech_main
{
pass P0
{
Texture[0] = <img>;
Texture[2] = <bkd>;
PixelShader = asm
{
ps.1.4; // <- Pixel shader version
// --- PHASE 1 --- //
def c0, 1.0, 1.0, 1.0, 1.0; // <- Declaration of a constant, we treat it as a color (r, g, b, a)
texld r0, t0; // <- Load the img texture
texld r1, t0; // <- Load the bkd texture
mul r0, r0, r0; // <- Assign the multiplication of colors from the img with img texture to the final result: result.rgba = img.rgba * img.rgba
phase; // <- Change from phase 1 to phase 2
// --- PHASE 2 --- //
mul r0.rgb, r0, r1; // <- Assign the multiplication of colors from the img with bkd texture to the final result: result.rgba = img.rgba * bkd.rgba
mov r0.a, c0.a; // <- Assigning a new alpha value to 1.0
};
}
}
This example requires the following in the .XML file:
- Flag <dx8>yes</dx8>
- Flag <BackgroundTexture>1</BackgroundTexture>
(More information about .XML files can be found here)
Details table:
|
Type |
Phase instructions |
Description |
Instruction slots |
ps.1.0 |
ps.1.1 |
ps.1.2 |
ps.1.3 |
ps.1.4 |
Note |
|
asm |
Transition between phase 1 and phase 2 |
0 |
No |
No |
No |
No |
Yes |
Phases allow for almost doubling the number of available instructions for ps.1.4 |
Created with the Personal Edition of HelpNDoc: Make Help Documentation a Breeze with a Help Authoring Tool