TextureEffect: Server basics

From The Foundry MODO SDK wiki
Jump to: navigation, search

A TextureEffect is a plug-in server that defines a texture output or gradient input. These can be extended to provide access to any attributes in any packets in the sample vector.

Overview

Effects are used when texturing. A texture evaluates to a percentage or color, and that is applied as an effect, like diffuse color or luminous amount. Some effects can also be used as gradient inputs. Each effect is implemented by a TextureEffect server, providing a way of interpreting one aspect of shading as a simple value. The value can be scalar or RGB, and it can be read from the sample vector and/or written to the sample vector.

Headers

Tags

  • LXsTFX_CATEGORY -- the category of the effect. NOTE: needs SDK defines

Sample Methods

The plug-in server class derives from CLxImpl_TextureEffect, and exports the ILxTextureEffect interface.

TextureEffect::Type()

The Type() method returns the base type, scalar or color, plus bits indicating whether the effect can be read, written, or used as a gradient input.

        unsigned int
tfx_Type ()                          LXx_OVERRIDE
{
        return LXi_TFX_SCALAR | LXf_TFX_READ | LXf_TFX_WRITE;
}
TextureEffect::TypeName()

The TypeName() method returns the type of the value, in this case a percent.

        const char *
tfx_TypeName ()                      LXx_OVERRIDE
{
        return LXs_TYPE_PERCENT;
}
TextureEffect::Get()

The Get() method reads packets from the sample vector, and outputs a value. Color values write to three sequential locations.

        LxResult
tfx_Get (
        ILxUnknownID          sv,
        float                *val,
        void                 *item)  LXx_OVERRIDE
{
        LXpSampleParms       *sParm = (LXpSampleParms *) packet_svc.FastPacket (sv, sParm_offset);

        val[0] = sParm->rough;
        return LXe_OK;
}
TextureEffect::Set()

The Set() method does the reverse. For writable effects it takes an input value and deposits that into the sample vector.

        LxResult
tfx_Set (
        ILxUnknownID          sv,
        const float          *val,
        void                 *item)  LXx_OVERRIDE
{
        LXpSampleParms       *sParm = (LXpSampleParms *) packet_svc.FastPacket (sv, sParm_offset);

        sParm->rough = val[0];
        return LXe_OK;
}