How to return a struct from my shader?

Output, Volumen, Light, etc..

How to return a struct from my shader?

Postby waltherg on Tue Jul 07, 2009 20:26 pm

Hi again gmrf

I'd like to be able to write a shader which returns a struct rather than just a single colour - along the lines of misss_fast_skin_x / mia_material_x etc.

My aim here is to then write a phenomenon for my shader which passes these various outputs into max_mrStoreElements, where I can save them with mrLabelledElement render elements in 3dsmax.

Is this possible? Is it a case of using a different signature to :

DLLEXPORT miBoolean SlideTest(miColor *result, miState *state, slideTestParas *paras)
{ ... }

Any pointers or examples would be fantastic :D

Many thanks from Slide.

Rob
waltherg
User
 
Posts: 12
Joined: Tue Jun 17, 2008 16:45 pm

Re: How to return a struct from my shader?

Postby haggi on Tue Jul 07, 2009 22:05 pm

Returning a struct is quite easy.

First you will have to write your mi - interface file in a way it returns a struct.
For example you can have a look in the mayabase shaders oder if you use max, in the standard shaders include files:

Code: Select all
declare shader
   struct {
      scalar    "density",
      vector   "direction"
   }
   "myBeautyfulShader" (
      scalar  "steps",
      boolean "doitOrNot"
   )
   version 1
   apply material
    }
end declare


Then you build your data struct exactly like the params struct:

Code: Select all

typedef struct{
      miScalar steps;
      miBoolean doitOrNot;
} shaderParas;

typedef struct{
   miScalar    density;
   miVector   direction;
} returnStruct;

DLLEXPORT miBoolean myBeautyfulShader(returnStruct*result, miState *state, shaderParas*paras)
{
   result->density = 1.0;
   result->direction.x = 123.4;
   result->direction.y = 567.8;
   
  return miTRUE;
}

haggi
Admin
 
Posts: 752
Joined: Wed Jan 10, 2007 0:56 am

Re: How to return a struct from my shader?

Postby waltherg on Wed Jul 08, 2009 11:24 am

Thank you Haggi, that's very helpful - I was hoping it would be that simple.

I will give it a go and post back with my results...
waltherg
User
 
Posts: 12
Joined: Tue Jun 17, 2008 16:45 pm

Re: How to return a struct from my shader?

Postby waltherg on Wed Jul 08, 2009 15:22 pm

Fantastic - that worked perfectly!

I now have a build of Pavel's p_HairTK which saves all it's various outputs to mrLabelledElement render elements in max. That will find it's way into the next official drop of SlideShaders.

Thanks again :D
waltherg
User
 
Posts: 12
Joined: Tue Jun 17, 2008 16:45 pm

Re: How to return a struct from my shader?

Postby jb_alvarado on Thu Jul 09, 2009 11:33 am

Hi waltherg,
that's really cool! I think I need more time, then I can make a Softimage addon from your nice shaders :).
User avatar
jb_alvarado
Moderator
 
Posts: 2022
Joined: Sun Nov 12, 2006 20:16 pm
Location: Dornbirn

Re: How to return a struct from my shader?

Postby banned on Thu Jul 09, 2009 12:03 pm

hi wahltherg,

you are great, i can´t wait of the new SlideShaders.

cheers
hot chip
banned
 

Re: How to return a struct from my shader?

Postby waltherg on Fri Jul 10, 2009 12:19 pm

Thank you guys! I'm glad this is useful for everyone.

Most of the hard work has been done by Pavel though - we just add some 'klebstoff' :)

By the way : if you have any suggestions to make SlideShaders better, please tell us - contact@slidelondon.com will get through to me.
waltherg
User
 
Posts: 12
Joined: Tue Jun 17, 2008 16:45 pm

Return to Shader general

Who is online

Users browsing this forum: No registered users and 1 guest

cron