C语言 Arnold API如何在Arnold着色器中设置和检索着色器的数据?

suzh9iv8  于 2023-08-03  发布在  其他
关注(0)|答案(1)|浏览(84)

我尝试在着色器的node_initializenode_update函数中定义着色器的数据,但由于检索函数的原因,它无法编译:

intValue = AiGetNodeInt(node,"parameter");       // error

字符串
是否有其他方法来存储和检索着色器的数据属性?我在node_update函数上遇到了问题。这不管用

#include "X3VU.h"

AI_SHADER_NODE_EXPORT_METHODS(X3VUMethods);

namespace {

    enum X3VUParams { p_wiMatrix, p_baseColor,  p_textureColor, p_textureMask, p_renderOption, p_tileU, p_tileV, p_seed, p_randomness };

    const char* optionList[] = {"Normal","Position","TextureUV","TextureUVW","TextureUVW2",NULL};

};

node_parameters
{
    AiParameterMtx("wiMatrix", AI_M4_IDENTITY);
    AiParameterRGB("BaseColor", 0.7f, 0.7f, 0.7f);
    AiParameterRGB("TextureColor", 0.7f, 0.7f, 0.7f);
    AiParameterFlt("TextureMask", 1.0f);
    AiParameterEnum("RenderOption", 3, optionList);
    AiParameterInt("TileU", 10);
    AiParameterInt("TileV", 10);
    AiParameterInt("Seed", 1);
    AiParameterFlt("Randomness", 1.0f);

}

struct X3VUtile {

    int nU;                     // number of tiles in U
    int nV;                     // number of tiles in V
    int * randList;             // nU*nV random list
    int seed;                   // random seed [0,inf]
    float randomness;           // randomness in range [0,1]

};

node_initialize{
    X3VUtile* tile = (X3VUtile*)AiMalloc(sizeof(X3VUtile));
    AiNodeSetLocalData(node, tile);
}

node_update{
    X3VUtile *tile = (X3VUtile*)AiNodeGetLocalData(node);
    tile->nU = AiNodeGetInt(node, "TileU");
    printf("node update: tileU: %d, tileV: %d \n", tile->nU, tile->nV);

}

node_finish{
    AiFree(AiNodeGetLocalData(node));
}

shader_evaluate
{
    AtMatrix *wimatrix = AiShaderEvalParamMtx(p_wiMatrix);          // world inverse matrix
    AtVector wpoint = sg->P;                                        // world point
    wpoint = AiM4PointByMatrixMult( *wimatrix, wpoint);             // world point by inverse matrix
    AtVector wnormal = sg->N;                                       // world normal
    wnormal = AiM4VectorByMatrixMult( *wimatrix, wnormal);          // world normal by inverse matrix
    wnormal = AiV3Normalize( wnormal );                             // normalize world normal

    int renderOption = AiShaderEvalParamEnum( p_renderOption );

    switch (renderOption) {

        default:
            sg->out.RGB() = AiShaderEvalParamRGB(p_baseColor);
            break;
         case 0:
            sg->out.RGB() = { fabs(wnormal.x), fabs(wnormal.y), fabs(wnormal.z) };
            break;

         case 1:
            X3vector_toFloorMod( &wpoint, &wpoint);
            sg->out.RGB() = { fabs(wpoint.x), fabs(wpoint.y), fabs(wpoint.z) };
            break;

         case 2:
            sg->out.RGB() = AiShaderEvalParamRGB(p_textureColor);
            break;

         case 3:
            break;

        case 4:
            break;

    }// end switch
    
}

node_loader
{
    if (i > 0)
        return false;
    node->methods = X3VUMethods;
    node->output_type = AI_TYPE_RGB;
    node->name = "X3VU";
    node->node_type = AI_NODE_SHADER;
    strcpy_s(node->version, AI_VERSION);
    return true;
}

plicqrtu

plicqrtu1#

有人给了我答案:你必须使用AtString作为char* 参数。

intValue = AiNodeGetInt(node, AtString("parameter"));

字符串

相关问题