Microsoft DirectX 8.0 (C++)

Sample Effect File

The following effect file is used for the Water Sample.

The file starts by declaring two matrices, three textures, and a vertex shader that will be used for this effect.

matrix mID;     // Identity transform
matrix mENV;    // Environment map transform

texture tFLR;   // Floor texture
texture tCAU;   // Caustic texture
texture tENV;   // Cubic environment map

vertexshader vs =  decl { fvf xyz | normal | diffuse | tex1; };

The first technique renders the water scene using both the floor texture and caustic texture. Both the water and the floor reflect light. This technique uses a single pass and four texture stage states.

technique T0
{
    vertexshader = <vs>;

    pass P0
    {        
        Lighting       = True;
        SpecularEnable = True;

        // Stage0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        AlphaOp[0]   = SelectArg2;
        AlphaArg2[0] = Current;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tFLR>;
        TextureTransform[0] = <mID>;
        TextureTransformFlags[0] = Count2;


        // Stage1
        ColorOp[1]   = Add;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;
        AlphaOp[1]   = SelectArg2;
        AlphaArg2[1] = Current;

        MinFilter[1] = Linear;
        MagFilter[1] = Linear;
        MipFilter[1] = Point;

        Texture[1] = <tCAU>;
        TextureTransform[1] = <mID>;
        TextureTransformFlags[1] = Count2;


        // Stage2
        ColorOp[2]   = BlendCurrentAlpha;
        ColorArg1[2] = Texture;
        ColorArg2[2] = Current;
        AlphaOp[2]   = Disable;

        MinFilter[2] = Linear;
        MagFilter[2] = Linear;
        MipFilter[2] = Point;

        Texture[2] = <tENV>;
        TextureTransform[2] = <mENV>;
        TextureTransformFlags[2] = Count3;
        TexCoordIndex[2] = CameraSpaceReflectionVector;


        // Stage3
        ColorOp[3] = Disable;
        AlphaOp[3] = Disable;
    }
}

The second technique renders the water scene using both the floor texture and caustic texture. Both the floor and water reflect light. This technique uses two passes to render the scene.

technique T1
{
    vertexshader = <vs>;

    pass P0
    {
        // Stage0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        AlphaOp[0]   = Disable;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tFLR>;
        TextureTransform[0] = <mID>;
        TextureTransformFlags[0] = Count2;


        // Stage1
        ColorOp[1]   = Add;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;
        AlphaOp[1]   = Disable;

        MinFilter[1] = Linear;
        MagFilter[1] = Linear;
        MipFilter[1] = Point;

        Texture[1] = <tCAU>;
        TextureTransform[1] = <mID>;
        TextureTransformFlags[1] = Count2;


        // Stage2
        ColorOp[2] = Disable;
        AlphaOp[2] = Disable;
    }


    pass P1
    {
        SrcBlend  = One;
        DestBlend = InvSrcAlpha;

        Lighting         = True;
        SpecularEnable   = True;
        AlphaBlendEnable = True;


        // Stage0
        ColorOp[0]   = BlendDiffuseAlpha;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;
        AlphaOp[0]   = SelectArg2;
        AlphaArg2[0] = Diffuse;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tENV>;
        TextureTransform[0] = <mENV>;
        TextureTransformFlags[0] = Count3;
        TexCoordIndex[0] = CameraSpaceReflectionVector;


        // Stage1
        ColorOp[1] = Disable;
        AlphaOp[1] = Disable;
    }
}

The third technique renders the water scene using both the floor texture and caustic texture. The water surface reflects light. This effect uses three passes to render the scene.

technique T2
{
    vertexshader = <vs>;

    pass P0
    {
        // Stage0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        AlphaOp[0]   = Disable;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tFLR>;
        TextureTransform[0] = <mID>;
        TextureTransformFlags[0] = Count2;

        // Stage1
        ColorOp[1] = Disable;
        AlphaOp[1] = Disable;
    }


    pass P1
    {
        SrcBlend  = One;
        DestBlend = One;

        Lighting         = False;
        SpecularEnable   = True;
        AlphaBlendEnable = True;


        // Stage0
        ColorOp[0]   = Add;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Current;
        AlphaOp[0]   = Disable;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tCAU>;
        TextureTransform[0] = <mID>;
        TextureTransformFlags[0] = Count2;


        // Stage1
        ColorOp[1] = Disable;
        AlphaOp[1] = Disable;
    }


    pass P2
    {
        SrcBlend  = One;
        DestBlend = InvSrcAlpha;

        Lighting         = True;
        SpecularEnable   = True;
        AlphaBlendEnable = True;


        // Stage0
        ColorOp[0]   = BlendDiffuseAlpha;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;
        AlphaOp[0]   = SelectArg2;
        AlphaArg2[0] = Diffuse;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0] = <tENV>;
        TextureTransform[0] = <mENV>;
        TextureTransformFlags[0] = Count3;
        TexCoordIndex[0] = CameraSpaceReflectionVector;


        // Stage1
        ColorOp[1] = Disable;
        AlphaOp[1] = Disable;
    }
}

The fourth technique renders the water scene using both the floor texture and caustic texture. This effect uses a single pass to render the scene.

technique T3
{
    vertexshader = <vs>;

    pass P0
    {
        Lighting       = True;
        SpecularEnable = True;


        // Stage0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        AlphaOp[0]   = Disable;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0]   = <tFLR>;


        // Stage1
        ColorOp[1]   = Add;
        ColorArg1[1] = Texture;
        ColorArg2[1] = Current;
        AlphaOp[1]   = Disable;

        MinFilter[1] = Linear;
        MagFilter[1] = Linear;
        MipFilter[1] = Point;

        Texture[1]   = <tCAU>;


        // Stage2
        ColorOp[2]   = Disable;
        AlphaOp[2]   = Disable;
    }
}

The fifth technique renders the water scene using both the floor and caustic textures. There is no reflection in this technique. This effect uses two passes to render the scene.

technique T4
{
    vertexshader = <vs>;

    pass P0
    {
        // Stage 0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;

        AlphaOp[0]   = SelectArg1;
        AlphaArg1[0] = Texture;
        AlphaArg2[0] = Diffuse;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0]   = <tFLR>;


        // Stage 1
        ColorOp[1]   = Disable;
        AlphaOp[1]   = Disable;
    }


    pass P1
    {
        SrcBlend  = One;
        DestBlend = One;

        Lighting         = True;
        SpecularEnable   = True;
        AlphaBlendEnable = True;


        // Stage 0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Current;

        AlphaOp[0]   = SelectArg1;
        AlphaArg1[0] = Texture;
        AlphaArg2[0] = Current;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Point;

        Texture[0]   = <tCAU>;


        // Stage 1
        ColorOp[1]   = Disable;
        AlphaOp[1]   = Disable;
    }
}

The sixth and final technique renders the water scene with just the floor texture. There is no reflection in this technique. This effect uses a single pass to render the scene.

technique T5
{
    vertexshader = <vs>;

    pass P0
    {
        Lighting       = True;
        SpecularEnable = True;


        // Stage 0
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Current;

        AlphaOp[0]   = SelectArg1;
        AlphaArg1[0] = Texture;
        AlphaArg2[0] = Current;

        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = None;

        Texture[0]   = <tFLR>;

        // Stage 1
        ColorOp[1]   = Disable;
        AlphaOp[1]   = Disable;
    }
}