Wednesday, April 13, 2011

Writing mental ray shaders: UV as Colors

Here, we'll start working with UV's. We'll first look at the state variable, tex_list. I will first use tex_list in a shader that translates tex_list into the red and green component of result. In the next section I will combine the quantization function into the uv as colors shader. As I'm no expert in programming, my codes will be a little simpler, but hopefully easier to understand.

state->tex_list is a pointer to an array containing the texture coordinates of the intersection point in all texture spaces. 

1. For every point P on surface, find its texture coordinates x and y
2. Color R at point P = x
3. Color G at point P = y

MI Source: uv_as_colors
declare shader
 color "uv_as_colors" ()
apply material
end declare

C Source: uv_as_colors
#include "shader.h"

miBoolean uv_as_colors(miColor *result, miState *state) {
 result->r = state->tex_list[0].x;
 result->g = state->tex_list[0].y;
 result->b = 0;
 return miTRUE;

UV as colors

Pretty straight forward, Red channel is the U coordinate and Green channel is the V coordinate


Post a Comment