PDA

View Full Version : Arrays in Shaders


jj80
02-21-2007, 10:33 PM
Hello all,

this is a 0.01 beginner question, but I've been spending way too much time on this already, so I thought I'd better ask (also asked on myMentalRay and mrShaders mailing list, will inform everyone if I find out what went wrong) ...

Basically, my goal is to pass four arrays, 3 integer arrays and one string array from maya to a mental ray geometry shader. So far, I've just been trying one single integer array. It's more or less a copy out of the "Programming Mental Ray" book, so I thought it should work without any major issues. However, if I render (in Maya 8.5), it tells me that all my array values are 0 and then crashes when it starts rendering the scene. Could it be a compiler issue? Does it work fine for anyone else ?

Here's the output I get:


PHEN 0.4 info : FB i_list 1
PHEN 0.4 info : FB n_list 3
PHEN 0.4 info : FB 0
PHEN 0.4 info : FB 0
PHEN 0.4 info : FB 0
PHEN 0.4 info : FrameBufferDev initialised


I assigned all the values in Maya with setAttr shader.list[0] 1 etc btw...

-- MI declaration: --

declare shader geometry "jj_bufferWriterDev" (
array integer "list"
)
version 1
apply geometry
end declare


-- Shader Source: --



#include <stdio.h>
#include <math.h>
#include <shader.h>
#include <geoshader.h>

typedef struct jj_bufferWriterDev_t{
int i_list;
int n_list;
miInteger list[1];
};

DLLEXPORT int jj_bufferWriterDev_version(void) {return(1);}

DLLEXPORT miBoolean jj_bufferWriterDev(miTag *result, miState *state, struct jj_bufferWriterDev_t *param)
{
int *list = mi_eval_integer(param->list);
int i_list = *mi_eval_integer(&param->i_list);
int n_list = *mi_eval_integer(&param->n_list);
int i;

mi_info("FrameBufferDev initialised");
mi_info("FB i_list %d",i_list);
mi_info("FB n_list %d",n_list);
for (i=0; i < n_list; i++) {
mi_info("FB %d",list[i_list + i]);
}


return(miTRUE);
}

jj80
02-22-2007, 02:42 AM
seems like it had to do with the .mi declaration. The c code is ok...


declare shader geometry "jj_bufferWriterDev" (
array struct "list" { integer "value"}
)
version 1
apply geometry
end declare


instead of


declare shader geometry "jj_bufferWriterDev" (
array integer "list"
)
version 1
apply geometry
end declare


and then in maya set the attribute with


setAttr jj_bufferWriterDev1.list[0].value 0
setAttr jj_bufferWriterDev1.list[1].value 1

CGTalk Moderation
02-22-2007, 02:42 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.