Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Custom Shaders and Batch Rendering (Maya)

  1. #1
    Join Date
    Nov 2012
    Posts
    18

    Default Custom Shaders and Batch Rendering (Maya)

    Hey Y'all

    The solution to this problem was actually very simple: Follow This Guide

    http://download.autodesk.com/global/...ber=d30e675459

    I hadn't included my libraries in mentalray's PATH variable and the mayabatch.exe couldn't find it, which is why only batch rendering did not work.
    Attached Images Attached Images
    Last edited by mynameisjohn; July 26th, 2013 at 16:58.

  2. #2
    Join Date
    Dec 2005
    Location
    Wherever The Computer Says
    Posts
    2,853

    Default

    Are there any errors output when you try to render? Maybe an error finding the library for the shader or the .mi?
    "Don't argue with an idiot, they will drag you down to their level and beat you over the head with experience."

  3. #3
    Join Date
    Nov 2012
    Posts
    18

    Default

    During the Batch render itself I've noticed nothing out of the ordinary. However, I just noticed that when loading the .mi file I get this error:

    Warning: (Mayatomr.Nodes) : Node "lightless_Ramp" has no ID, assigning a temporary ID. Scene should be saved as .ma (ASCII)

    For the record I tried saving my scene as a Maya ASCII file, to no avail. It is worth noting that I get this error on every shader in that .mi file, which happens to be the mayaShaderExample.mi file included in the devkit. This file comes with three shaders (phong, lambert, and light_point) by default, and those yield the same error.

    Do you think this error could be causing the problem and, if so, is it fixable?

    - John

  4. #4
    Join Date
    Dec 2005
    Location
    Wherever The Computer Says
    Posts
    2,853

    Default

    That error might be trouble later, which Maya are you using? Maya 2014 attempts to assign it's own ID to the shader or you can request one from Autodesk. You don't want them to overlap because when you open a file it might think it's a different shader and display the wrong UI etc.

    Otherwise Batch and Render View should call the same thing for rendering.
    "Don't argue with an idiot, they will drag you down to their level and beat you over the head with experience."

  5. #5
    Join Date
    Nov 2012
    Posts
    18

    Default

    Nope, I've still got 13. I'm considering doing a fresh install.

    I'm basing my .mi file declaration off of what's given in the other .mi files (like base.mi), and I'm basing my shader code off of the .cpp files included in the devkit. Again, I'm able to save nice renders if I do a single image but not during batch renders.

    I appreciate your helping me, but I don't want to waste your time.

    My shader declaration is as follows:

    declare shader
    color "lightless_Ramp" (
    color "Warm", #: default 1.0, 1.0, 0.0
    color "Cool", #: default 0.0, 0.0, 1.0
    scalar "ramp", #: default -.1
    scalar "Lx", #: default 1
    scalar "Ly", #: default 1
    scalar "Lz", #: default 1
    array light "lights"
    )
    version 3
    apply material
    end declare

    I suppose it's curious that I don't have anything regarding light linking, the maya_illum_lambert declaration does and I still encounter the same error.

    Just out of curiosity, is there a resource where I can download a user created custom shader, just so I can confirm the error is on my part? Shaders like mib_illum_lambert work just fine for batch rendering, but that is a Maya default and comes with no code other than it's .mi file.

  6. #6
    Join Date
    Dec 2005
    Location
    Wherever The Computer Says
    Posts
    2,853

    Default

    The best resource for that would probably be Andy Kopra's book on writing mental ray shaders. http://www.amazon.com/Writing-mental.../dp/3211489649

    There's a companion website www.writingshaders.com but I can't get to it.
    "Don't argue with an idiot, they will drag you down to their level and beat you over the head with experience."

  7. #7
    Join Date
    Nov 2012
    Posts
    18

    Default

    Nor can I. Sad, as I had been hoping to use this shader to make a short film. I can render each frame one by one, but that seems highly unrealistic. Perhaps I'll learn how to write a MEL script to do that, or end up using Maya's built in ramp shader. I will sorely miss the customizations, though.

    Do you think it matters that I'm using the Student version of Maya?

  8. #8
    Join Date
    Nov 2012
    Posts
    18

    Default

    As a last ditch effort, if anyone feels like trying my code out and seeing what's wrong here it is. I basically took the provided .cpp files and fiddled around till I got what I wanted.

    Code:
    #include <stdio.h>
    #include <stdlib.h>		/* for abs */
    #include <float.h>		/* for FLT_MAX */
    #include <math.h>
    #include <string.h>
    #include <assert.h>
    #include "shader.h"
    
    
    struct lightless_Ramp {
    	miColor     Warm;
    	miColor     Cool;
    	miScalar    ramp;
    	miScalar    Lx, Ly, Lz;
    	miTag       light[1];   /* list of lights */
    };
    
    
    extern "C" DLLEXPORT int lightless_Ramp_version(void) {return(3);}
    
    
    /*
    This is the function that exports the dll responsible for calculating the resulting color. 
    It takes in a pointer to our final color *result, a pointer to the current state of the
    render *state, and a pointer to our shader struct *paras. 
    */
    
    extern "C" DLLEXPORT miBoolean lightless_Ramp(
    	miColor *result, miState *state, struct lightless_Ramp *paras)
    {
    	miColor	warm, cool;	/* variables we will use to store color */
    	miTag		*light;		/* tag of light instance */
    	miScalar     ramp;		/* our lightless_Ramp coefficients */
    	miScalar	dot_nl;		/* dot prod of normal and light direction*/
    	miScalar     Lx, Ly, Lz;          /* user-inputted light vector (3-D)*/
    	miVector    lightVector;       /* the same vector in proper format
    	miScalar     mag;                  /* magnitude, for normalization*/
    
    	/* check for illegal calls */
    	if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE ) {
    		return(miFALSE);
    	}
    
    	/* Evaluate our parameters, in order */
    	warm  =  *mi_eval_color(&paras->Warm);
    	cool  =  *mi_eval_color(&paras->Cool);
    	ramp  =  *mi_eval_scalar(&paras->ramp);
    	light =   mi_eval_tag(paras->light);
    	Lx    =  *mi_eval_scalar(&paras->Lx);
    	Ly    =  *mi_eval_scalar(&paras->Ly);
    	Lz    =  *mi_eval_scalar(&paras->Lz);
    
    	mag = Lx*Lx + Ly*Ly * Lz*Lz;
    	mag = sqrt(mag);
    
    	lightVector.x = Lx/mag;
    	lightVector.y = Ly/mag;
    	lightVector.z = Lz/mag;
    
    	dot_nl = state->normal.x * lightVector.x + state->normal.y * lightVector.y + state->normal.z * lightVector.z;
    
    	if (dot_nl>=ramp)
    	{
    		result->r=warm.r;
    		result->g=warm.g;
    		result->b=warm.b;
    	}
    	else
    	{
    		result->r=cool.r;
    		result->g=cool.g;
    		result->b=cool.b;
    	}
    	result->a=1.0;
    
    	/* Now that the color has been calculated and stored in result, 
    	we can return true. */
    	return (miTRUE);
    }

  9. #9
    Join Date
    Oct 2009
    Posts
    75

    Default

    I put an ID number into the mi declaration file. It needs one specified. I made up my own one by altering alot of the digits in an existing one.

  10. #10
    Join Date
    Nov 2012
    Posts
    18

    Default

    After looking at the provided .mi files I could not find an example with the field ID. One thing I notice is that when I render a .ma file, Maya saves a temporary .mb file. I suppose that could be an issue, so would you mind providing an example of this declaration?

    Sorry to be such a scrub, by the way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •