Direct3D 8 - Pixel Shader - Instructions - bem

Last edited 2026-02-20


The bem instruction is used to distort texCoord based on a different texture


The bem syntax looks like this:

bem r.xy, x, y;


r.xy: Register where the information is to be saved (Final result only for the x and y vector)

x: First input register (r#)

y: The second input register (r#) that applies the offset.


Rules for using bem:

    1. bem must appear in the first phase of a shader (that is, before a phase marker).
    2. bem consumes two arithmetic instruction slots.
    3. Only one use of this instruction is allowed per shader.
    4. Destination writemask must be .rg /.xy.
    5. This instruction cannot be co-issued.
    6. Aside from the restriction that destination write mask be .rg, modifiers on source src0, src1, and instruction modifiers are unconstrained.

Example code:


texture T_Image;                            // <- Main texture

texture T_Background;                       // <- Background texture


technique tech_main

{

    pass P0

    {

        Texture[0] = <T_Image>;

        Texture[2] = <T_Background>;

        PixelShader = asm

        {

            ps.1.4;                         // <- Pixel shader version


            // --- PHASE 1 --- //


            texld r0, t0;                   // <- Load the T_Image texture

            texld r1, t0;                   // <- Load the T_Background texture

            texld r2, t0;                   // <- Load dump texture

            

            bem r2.xy, r1, r0;              // <- Assign a new texCoord offset to Dump texture for red and green color (.xy)


            // --- PHASE 2 --- //

            phase;                          // <- Change from phase 1 to phase 2


            texld r0, r2;                   // <- Load the img texture with texCoord distortion (from dump texture / r2)

        };

    }

}



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

Instruction

Description

Instruction slots

ps.1.0

ps.1.1

ps.1.2

ps.1.3

ps.1.4

Note

asm

bem

Apply a fake bump environment-map transform

2

No

No

No

No

Yes

Used to modify texCoords based on two texture.

Created with the Personal Edition of HelpNDoc: Why Microsoft Word Isn't Cut Out for Documentation: The Benefits of a Help Authoring Tool