[Back]
[Forward]
cellnoiseDSO.c
/* $RCSfile$ $Revision$ $Date$
*
* Copyright (c) 2000 Thomas E. Burge. All rights reserved.
*
* Affine (R) is a registered trademark of Thomas E. Burge
*
* THIS SOFTWARE IS DISTRIBUTED "AS-IS" WITHOUT WARRANTY OF ANY KIND
* AND WITHOUT ANY GUARANTEE OF MERCHANTABILITY OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* In no event shall Thomas E. Burge be liable for any indirect or
* consequential damages or loss of data resulting from use or performance
* of this software.
*
* Permission is granted to include compiled versions of this code in
* noncommercially sold software provided the following copyrights and
* notices appear in all software and any related documentation:
*
* The Affine (R) Libraries and Tools are
* Copyright (c) 1995-2000 Thomas E. Burge.
* All rights reserved.
* Affine (R) is a registered trademark of Thomas E. Burge.
*
* Also refer to any additional requirements presently set by Pixar
* in regards to the RenderMan (R) Interface Procedures and Protocol.
*
* Those wishing to distribute this software commercially and those wishing
* to redistribute the source code must get written permission from the
* author, Thomas E. Burge.
*
* Basically for now, I would like folks to get the source code directly
* from me rather than to have a bunch of different versions circulating
* about.
*
*
* Affine Toolkit
*
* FILE: cellnoise.c
*
* DESCRIPTION: Example shadeop DSO for PRMan 3.8.
*
* Contains:
*
* History:
*
* References:
* [PIXA98] Pixar, rnotes-3.8.html#shadedsos, Version 3.8,
* Richmond, CA, 1998.
* [NUMREC] Numerical Recipes in C, Second Edition, page 284.
* [EBER98] David S. Ebert, F. Kenton Musgrave, Darwyn Peachey,
* Ken Perlin and Steven Worley; Texturing & Modeling,
* Second Edition, page 215.
*
*
* The RenderMan (R) Interface Procedures and Protocol are:
* Copyright 1988, 1989, Pixar
* All Rights Reserved
*
* Renderman (R) is a registered trademark of Pixar
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifndef BMRT
#include <shadeop.h>
#else
typedef struct _SHADEOP_SPEC {
char *declaration; /* if zero length string, end of table signaled. */
char *initfunctionname; /* optional */
char *cleanupfunctionname;/* optional */
} SHADEOP_SPEC;
#endif
typedef struct _point {
float x;
float y;
float z;
} point;
#define xcomp(/* point* */ p) ((p)->x)
#define ycomp(/* point* */ p) ((p)->y)
#define zcomp(/* point* */ p) ((p)->z)
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
extern int P[2*2048];
extern float R[2048];
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
/*same as SHADEOP_TABLE(cellnoiseDSO) = */
SHADEOP_SPEC cellnoiseDSO_shadeops[] =
{
/* In PRMan 3.8c and 3.8d the order in the following list determines
* which function gets matched as the output type is not
* checked by prman. So if f_cellnoiseDSO_v function is mentioned
* first the shader interpreter will match it to SL calls
* that should match to v_cellnoiseDSO_v. The reverse
* is also true.
* Until this bug is fixed this DSO has to be broken up into
* different shared objects with slightly different names.
* For now I'll just compile and test the functions I need at the
* time.
*/
#if 1
{ "color v_cellnoiseDSO_f(float)", "", "", },
{ "color v_cellnoiseDSO_2f(float, float)", "", "", },
{ "color v_cellnoiseDSO_v(point)", "", "", },
{ "color v_cellnoiseDSO_vf(point, float)", "", "", },
{ "point v_cellnoiseDSO_f(float)", "", "", },
{ "point v_cellnoiseDSO_2f(float, float)", "", "", },
{ "point v_cellnoiseDSO_v(point)", "", "", },
{ "point v_cellnoiseDSO_vf(point, float)", "", "", },
#endif
{ "float f_cellnoiseDSO_f(float)", "", "", },
{ "float f_cellnoiseDSO_2f(float, float)", "", "", },
{ "float f_cellnoiseDSO_v(point)", "", "", },
{ "float f_cellnoiseDSO_vf(point, float)", "", "", },
{ "", "", "", }
};
int f_cellnoiseDSO_f( void *initdata, int argc, void *argv[] )
{
float *result = (float*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("f_cellnoiseDSO_f\n");
#endif
f = (*(float*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
*result = R[i];
return 0;
}
int f_cellnoiseDSO_2f( void *initdata, int argc, void *argv[] )
{
float *result = (float*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("f_cellnoiseDSO_2f\n");
#endif
f = (*(float*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
f = (*(float*)argv[2]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
*result = R[i];
return 0;
}
int f_cellnoiseDSO_v( void *initdata, int argc, void *argv[] )
{
float *result = (float*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("f_cellnoiseDSO_v\n");
#endif
f = xcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
f = ycomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
f = zcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
*result = R[i];
return 0;
}
int f_cellnoiseDSO_vf( void *initdata, int argc, void *argv[] )
{
float *result = (float*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("f_cellnoiseDSO_vf\n");
#endif
f = xcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
f = ycomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
f = zcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
f = (*(float*)argv[2]);
if (f<0.0)
f-=1;
i = P[P[i] + ((unsigned int)(f))&0x7ff];
*result = R[i];
return 0;
}
int v_cellnoiseDSO_f( void *initdata, int argc, void *argv[] )
{
point *result = (point*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("v_cellnoiseDSO_f\n");
#endif
f = (*(float*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
result->x = R[i];
i = P[P[i] + i];
result->y = R[i];
i = P[P[i] + i];
result->z = R[i];
return 0;
}
int v_cellnoiseDSO_2f( void *initdata, int argc, void *argv[] )
{
point *result = (point*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("v_cellnoiseDSO_2f\n");
#endif
f = (*(float*)argv[1]);
if (f<0.0)
f-=1;
i = P[((unsigned int)(f))&0x7ff];
f = (*(float*)argv[2]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->x = R[i];
i = P[i];
result->y = R[i];
i = P[i];
result->z = R[i];
return 0;
}
int v_cellnoiseDSO_v( void *initdata, int argc, void *argv[] )
{
point *result = (point*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("v_cellnoiseDSO_v\n");
#endif
f = xcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[(unsigned int)(f)&0x7ff];
result->x = R[i];
f = ycomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->y = R[i];
f = zcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->z = R[i];
return 0;
}
int v_cellnoiseDSO_vf( void *initdata, int argc, void *argv[] )
{
point *result = (point*)argv[0];
float f;
unsigned int i;
/* Check to make certain prman is using the correct function. */
#ifdef DEBUG
printf("v_cellnoiseDSO_vf\n");
#endif
f = (*(float*)argv[2]);
if (f<0.0)
f-=1;
i = P[(unsigned int)(f)&0x7ff];
f = xcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->x = R[i];
f = ycomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->y = R[i];
f = zcomp((point*)argv[1]);
if (f<0.0)
f-=1;
i = P[P[i] + (unsigned int)(f)&0x7ff];
result->z = R[i];
return 0;
}
[Affine Toolkit]
[RIB Utilities]
[Bitmap Utilities]
[Handy Little Utilities]
[Libraries]
[Using the Libraries]