Thursday, March 31, 2011

Writing mental ray shaders: Color Gain

Goal
A simple shader that takes a base color and multiplies by another color.

Methodology
1. create a color parameter called base
2. create a color parameter called gain
3. create a shader called "color_gain"
4. create a function where result = base * gain

Mi File
declare shader
 color "color_gain" (
  color "base" default 1 1 1,
  color "gain" default 1 1 1
 )
 version 1
 apply material
end declare

C File

#include "shader.h"

DLLEXPORT

struct color_gain {
 miColor base;
 miColor gain;
 };

DLLEXPORT

miBoolean color_gain (miColor *result, miState *state, struct color_gain *params) {
 miColor *base = mi_eval_color(&params->base);
 miColor *gain = mi_eval_color(&params->gain);
 result->r = base->r * gain->r;
 result->g = base->g * gain->g;
 result->b = base->b * gain->b;
 return miTRUE;
 }

0 comments:

Post a Comment