Community
Arnold General Rendering Forum
abbrechen
Suchergebnisse werden angezeigt für 
Anzeigen  nur  | Stattdessen suchen nach 
Meintest du: 

API how to set and retrieve shader's data in an arnold shader ?

5 ANTWORTEN 5
GELÖST
Antworten
Nachricht 1 von 6
eddykem1
630 Aufrufe, 5 Antworten

API how to set and retrieve shader's data in an arnold shader ?

I'am trying to define shader's data in the node_initialize and node_update functions of the shader. but it doesn't compile because of the retrieving function:

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

Is there another way to store and retrieve shader's data properties ?

 

 

 

 

//#pragma once

#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");      // does not work
    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;
}


 

 

 

 

Tags (1)
5 ANTWORTEN 5
Nachricht 2 von 6
maxtarpini
als Antwort auf: eddykem1

what's the error btw ?

 

Nachricht 3 von 6
eddykem1
als Antwort auf: maxtarpini

I have this message:

 

Error C4996 'AiNodeGetInt': has been declared deprecated X3VU C:\Users\eddyk\OneDrive\Documents\Visual Studio 2022\Eddy3ree_01\X3VU\X3VU.cpp 44

Nachricht 4 von 6
maxtarpini
als Antwort auf: eddykem1

That's because you use the 'const char*' version of AiNodeGetInt.. you have to use the AtString..

AiNodeGetInt(node, AtString("TileU"));

 

Nachricht 5 von 6
eddykem1
als Antwort auf: maxtarpini

oh thanks! it works!

Nachricht 6 von 6
maxtarpini
als Antwort auf: eddykem1

Accept solution then .. I'm eager to have more reputation than Lee Griggs ! :Gesicht,_das_etwas_Leckeres_isst::sich_vor_Lachen_auf_dem_Boden_winden::vulkanischer_Gruß:

Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.

In Foren veröffentlichen  

Autodesk Design & Make Report