/******************************************************************************
 * Copyright 1986-2002 by mental images GmbH & Co.KG, Fasanenstr. 81, D-10623
 * Berlin, Germany. All rights reserved.
 ******************************************************************************
 * Author:	thomas
 * Created:	18.6.94
 * Module:	shader
 * Purpose:	Softimage shader user parameter data structures
 *
 * Exports: 
 *
 * History: 
 *
 * Description:
 * The SOFT module need these to properly write the data for the shaders.
 * It formally belongs to the shader pseudo-module, and is included by
 * shader/src/softshade.c. When changing parameter structs, remember to
 * also change the declaration version in softimage.mi *and* the shader
 * version (shader_name_version())!
 *****************************************************************************/

#ifndef MI_SOFTSHADE_H
#define MI_SOFTSHADE_H

void  mi_soft_install(void);
char *mi_soft_shader_version(void);

struct soft_material {
	miInteger	mode;		/* 0=flat, 1=lambt, 2=phong, 3=blinn */
	miColor		ambient;	/* ambient color */
	miColor		diffuse;	/* diffuse color */
	miColor		specular;	/* specular color */
	miColor		ambience;	/* ambience factor */
	miScalar	shiny;		/* specular decay (phong exponent) */
	miScalar	transp;		/* transparency */
	miScalar	reflect;	/* reflectivity */
	miScalar	ior;		/* index of refraction */
	miBoolean	sblur;		/* true if static blur is enabled */
	miScalar	sblurdecay;	/* if enabled, falloff strength */
	miBoolean	notrace;	/* if true, no refl rays, just envmap*/

	int		i_light;	/* index of first light */
	int		n_light;	/* number of lights */
	miTag		light[1];	/* list of lights */

	int		i_difflight;	/* index of first diffuse light */
	int		n_difflight;	/* number of diffuse lights */
	miTag		difflight[1];	/* list of diffuse lights */

	int		i_texture;	/* index of first texture */
	int		n_texture;	/* number of textures */
	struct Tex {
	    miTag	map;		/* texture file */
	    miInteger	space;		/* texture vertex space (projection) */
	    miInteger	mask;		/* blend: 0=without, 1=alpha, 2=inten*/
	    miInteger	comp;		/* map component: 1=alpha, 2=intens */
	    miInteger	method;		/* 0=XY, 1=YZ, 2=XZ, 3=UV, 4=cyl/sph */
	    miScalar	blend;		/* overall blending */
	    miScalar	ambient;	/* ambient weight */
	    miScalar	diffuse;	/* diffuse weight */
	    miScalar	specular;	/* specular weight */
	    miScalar	transp;		/* transparency weight */
	    miScalar	reflect;	/* reflectivity weight */
	    miScalar	bump;		/* bump mapping weight */
	    miScalar	u_unit;		/* epsilon distance in texture space */
	    miScalar	v_unit;		/*    coords, for bump gradient calc */
	    miScalar	u_wrap;		/* replace u_unit in case u + u_unit */
	    miScalar	v_wrap;		/* is outside of [0, 1) */
	    miBoolean	blackwhite;	/* if color is white or black -> t=0 */
	}		texture[1];	/* textures, must be last in struct */
};


struct soft_color {
	miTag		texture;	/* texture shader (pic file) */
	miInteger	repu, repv;	/* repetition factor, >= 1 */
	miBoolean	altu, altv;	/* flip map on odd repetitions */
	miBoolean	swap;		/* swap U and V coordinates */
	miScalar	minu, maxu;	/* horizontal cropping boundaries */
	miScalar	minv, maxv;	/* vertical cropping boundaries */
	miMatrix	transform;	/* transformation matrix */
	miBoolean	u_torus;	/* set if map is cyl or spherical */
	miBoolean	v_torus;	/* same thing for V, for patches only*/
	miInteger	method;		/* 0..5==XY,YZ,XZ,UV,cyl/sph,UV-wrap */
};


struct soft_color_3d {
	miInteger	seq;		/* not used */
	miInteger	type;		/* TT_MARBLE, TT_WOOD, or TT_CLOUD */
	miScalar	spacing;	/* spacing (density) */
	miScalar	angle;		/* rotation */
	miScalar	strength;	/* amount of noise */
	miScalar	power;		/* deformation strength */
	miInteger	iteration;	/* polynomial order */
	miScalar	weight1;	/* weights of middle colors 1,2,3 */
	miScalar	weight2;
	miScalar	weight3;
	miColor		color0;		/* 5-color color spread */
	miColor		color1;
	miColor		color2;
	miColor		color3;
	miColor		color4;
	miMatrix	transform;	/* texture xlate, scale and rotation */
};


struct soft_light {
	miInteger	mode;		/* 0=infinite, 1=point, 2=spot */
	miColor		color;		/* color of light source */
	miScalar	intensity;	/* multiplier for color parameter */
	miBoolean	shadow;		/* light casts shadows */
	miScalar	factor;		/* makes opaque objects transparent */
					/* --- next two point and spot only: */
	miBoolean	atten;		/* distance attenuation */
	miScalar	start, stop;	/* if atten, distance range */
					/* --- next one spot only: */
	miScalar	spread;		/* outer fuzzy cone */
					/* --- next two spot only: */
	miBoolean	bGlbUseColor;	/* use energy or color? */
	miScalar	glb_intensity;	/* multiplier for energy */
};


struct soft_infinite {
	miColor		color;		/* color of light source */
	miVector	null;		/* spot light has dir vector here */
	miBoolean	shadow;		/* light casts shadows */
	miScalar	factor;		/* makes opaque objects transparent */
};


struct soft_point {
	miColor		color;		/* color of light source */
	miVector	null;		/* spot light has dir vector here */
	miBoolean	shadow;		/* light casts shadows */
	miScalar	factor;		/* makes opaque objects transparent */
	miBoolean	atten;		/* distance attenuation */
	miScalar	start, stop;	/* if atten, distance range */
};


struct soft_spot {
	miColor		color;		/* color of light source */
	miVector	direction;	/* spot direction */
	miBoolean	shadow;		/* light casts shadows */
	miScalar	factor;		/* makes opaque objects transparent */
	miBoolean	atten;		/* distance attenuation */
	miScalar	start, stop;	/* if atten, distance range */
	miScalar	cone;		/* inner solid cone */
	miScalar	spread;		/* outer fuzzy cone */
};


struct soft_displace {
	int		i_texture;	/* index of first texture */
	int		n_texture;	/* number of textures */
	struct DisTex {
	    miTag	map;		/* texture file */
	    miInteger	space;		/* texture vertex space (projection) */
	    miInteger	comp;		/* map component: 1=alpha, 2=intens */
	    miScalar	displace;	/* weight of texture */

	}		texture[1];	/* list of textures */
};


struct soft_staticblur {
	miScalar	width;		/* blur distance, fraction of normal */
};


struct soft_env_sphere {
	miScalar	rotate;		/* global rotation around world Y */
	int		i_texture;	/* index of first texture */
	int		n_texture;	/* number of textures */
	struct EnvTex {
	    miTag	map;		/* texture file */
	    miInteger	mask;		/* blend: 0=without, 1=alpha, 2=inten*/
	    miScalar	blend;		/* overall blending */
	}		texture[1];	/* list of textures */
};


struct soft_fog {
	miScalar	start, stop;
	miScalar	rate;
	miColor		transmit;
	miBoolean	lightrays;	/* applies to light rays too */
};


struct soft_layered_fog {
	miScalar	start, stop;	/* start/stop of fog along the ray */
	miScalar	base;		/* lowest y-value of layer */
	miScalar	thickness;	/* thickness of layer */
	miScalar	density;	/* density of the fog */
	miColor		fogcolor;	/* color of the fog */
	miBoolean	lightrays;	/* applies to light rays too */
};


struct lens_depth_of_field {
	miScalar	plane;		/* distance to focused plane */
	miScalar	radius;		/* size of the lens */
};


struct soft_dof {
	miScalar	plane;		/* distance to focused plane */
	miScalar	radius;		/* size of the lens */
};


/*
 * parameter structure of depth of field shader
 */

struct dof {
	miScalar	nearplane;		/* near focus plane */
	miScalar	farplane;		/* far focus plane */
	miScalar	radius;		/* radius of the lens */
	int		max;		/* max. filter radius in pixels */
	miScalar	infinity;	/* plane of infinite depth pixels */
};


/*
 * shader prototypes
 */

DLLIMPORT miBoolean soft_material(
	miColor			*result,
	miState			*state,
	struct soft_material	*paras);
DLLIMPORT miBoolean soft_material_photon(
        miColor                 *energy,
        miState                 *state,
        struct soft_material    *paras);
DLLIMPORT miBoolean soft_material_forwards(
        miColor                 *energy,
        miState                 *state,
        struct soft_material    *paras);
DLLIMPORT miBoolean soft_shadow(
	miColor			*result,
	miState			*state,
	struct soft_material	*paras);
DLLIMPORT miBoolean soft_color(
	miColor			*result,
	miState			*state,
	struct soft_color	*paras);
DLLIMPORT miBoolean soft_color_3d(
	miColor			*result,
	miState			*state,
	struct soft_color_3d	*paras);
DLLIMPORT miBoolean soft_color_3d_init(
	miState			*state,
	struct soft_color_3d	*paras,
	miBoolean		*inst_req);
DLLIMPORT miBoolean soft_color_3d_exit(
	miState			*state,
	struct soft_color_3d	*paras);
DLLIMPORT miBoolean soft_vertex_color(
	miColor			*result,
	miState			*state,
        void			*paras);
DLLIMPORT miBoolean soft_vertex_color_alpha(
	miColor			*result,
	miState			*state,
        void			*paras);
DLLIMPORT miBoolean soft_vertex_color_alpha2(
	miColor			*result,
	miState			*state,
        int			*paras);
DLLIMPORT miBoolean soft_vertex_color_alpha3(
	miColor			*result,
	miState			*state,
	int			*paras);
DLLIMPORT miBoolean soft_light(
	miColor			*result,
	miState			*state,
	struct soft_light	*paras);
DLLIMPORT miBoolean soft_infinite(
	miColor			*result,
	miState			*state,
	struct soft_infinite	*paras);
DLLIMPORT miBoolean soft_point(
	miColor			*result,
	miState			*state,
	struct soft_point	*paras);
DLLIMPORT miBoolean soft_spot(
	miColor			*result,
	miState			*state,
	struct soft_spot	*paras);
DLLIMPORT miBoolean soft_displace(
	miScalar		*result,
	miState			*state,
	struct soft_displace	*paras);
DLLIMPORT miBoolean soft_staticblur(
	miScalar		*result,
	miState			*state,
	struct soft_staticblur	*paras);
DLLIMPORT miBoolean soft_env_sphere(
	miColor			*result,
	miState			*state,
	struct soft_env_sphere	*paras);
DLLIMPORT miBoolean soft_fog(
	miColor			*result,
	miState			*state,
	struct soft_fog		*paras);
DLLIMPORT miBoolean soft_dof(
	miColor			*result,
	miState			*state,
	struct soft_dof		*paras);
DLLIMPORT miBoolean soft_layered_fog(
        miColor                 *result,
        miState                 *state,
        struct soft_layered_fog *paras);
DLLIMPORT miBoolean lens_depth_of_field(
        miColor			*result,
        miState			*state,
        struct soft_dof		*);
DLLIMPORT miBoolean out_depth_of_field(
	void			*result,
	miState			*state,
        struct dof *);
DLLIMPORT miBoolean out_raisedcosine(
        miOutstate              *state,
        void                    *paras);
DLLIMPORT miBoolean out_underlay(
        miOutstate              *state,
        char                    **name);
DLLIMPORT miBoolean out_overlay(
        miOutstate              *state,
        char                    **name);


/*
 * SOFTIMAGE material shader versions
 */

DLLIMPORT int soft_material_version		(void);
DLLIMPORT int soft_material_photon_version	(void);
DLLIMPORT int soft_material_forwards_version	(void);
DLLIMPORT int soft_shadow_version		(void);
DLLIMPORT int soft_color_version		(void);
DLLIMPORT int soft_color_3d_version		(void);
DLLIMPORT int soft_vertex_color_version		(void);
DLLIMPORT int soft_vertex_color_alpha_version	(void);
DLLIMPORT int soft_vertex_color_alpha2_version	(void);
DLLIMPORT int soft_vertex_color_alpha3_version	(void);
DLLIMPORT int soft_light_version		(void);
DLLIMPORT int soft_infinite_version		(void);
DLLIMPORT int soft_point_version		(void);
DLLIMPORT int soft_spot_version			(void);
DLLIMPORT int soft_displace_version		(void);
DLLIMPORT int soft_staticblur_version		(void);
DLLIMPORT int soft_env_sphere_version		(void);
DLLIMPORT int soft_fog_version			(void);
DLLIMPORT int soft_dof_version			(void);
DLLIMPORT int soft_layered_fog_version		(void);
DLLIMPORT int lens_depth_of_field_version	(void);
DLLIMPORT int out_depth_of_field_version	(void);
DLLIMPORT int out_raisedcosine_version		(void);
DLLIMPORT int out_underlay_version		(void);
DLLIMPORT int out_overlay_version		(void);


/*
 * SOFTIMAGE material shader components
 */

DLLIMPORT miBoolean mi_mtl_is_casting_shadow (
              miState *, struct soft_material *);
DLLIMPORT void	mi_mtl_refraction_index  (
              miState *, struct soft_material *, miScalar *, miScalar *);
DLLIMPORT void mi_mtl_textures (
              miState *, struct soft_material *,
	      struct soft_material *, miVector *, miScalar *);
DLLIMPORT miBoolean mi_mtl_compute_shadow(
              miColor *, struct soft_material *);
DLLIMPORT void mi_mtl_static_blur (
              miState *, struct soft_material *);
DLLIMPORT void mi_mtl_illumination (
              miColor *, miState *, struct soft_material *,
	      struct soft_material *,
	      double, double);
DLLIMPORT void mi_mtl_reflection(
              miColor *, miState *, struct soft_material *);
DLLIMPORT void mi_mtl_refraction(
              miColor *, miState *,
	      struct soft_material *, double, double);


/*
 * SOFTIMAGE 2D color texture shader components
 */

DLLIMPORT miBoolean mi_remap_parameter (
              miVector *, miVector *, miState *,
	      struct soft_color *);

#endif

