#*****************************************************************************
# Copyright 1986-2002 by mental images GmbH & Co.KG, Fasanenstr. 81, D-10623
# Berlin, Germany. All rights reserved.
#*****************************************************************************
# Author:       Per Henrik Christensen
# Created:      22.07.97
# Module:       baseshader
# Purpose:      .mi declarations for Softimage phenomena and base shaders
#
# Exports:
#       mi_soft_material        material phenomenon
#       mi_soft_color		2D color texture phenomenon
#
#	mi_soft_bumpmap         base shader for bump mapping
#	mi_soft_textures	base shader for texture maps
#	mi_soft_static_blur	base shader for modifying transparency w/ blur
#	mi_soft_refraction_index  base shader to compute indices of refraction
#	mi_soft_illumination    base shader for direct illumination
#	mi_soft_globillum       base shader for global illumination + caustics
#	mi_soft_reflection	base shader for reflection
#	mi_soft_refraction	base shader for refraction
#	mi_soft_shadow		base shader for shadow
#	mi_soft_shadowselect	base shader for selecting shadow or illum
#
#	mi_soft_remap_coords	base shader that remaps texture coordinates
#	mi_soft_lookup_color_texture  base shader that looks up a texture
#
# History: 
#	22.07.97 per: initial version
#
# Description:
#
#****************************************************************************/

min version "2.0.17.48"
max version "3.0.99"


#
# base shaders
#

declare shader
    vector "mi_soft_bumpmap" (
	array struct    "textures" {	# array of textures for bump maps
	    color texture   "map",
	    integer         "space",
	    integer         "mask",
	    integer         "comp",
	    integer         "method",
	    scalar          "blend",
	    scalar          "ambient",
	    scalar          "diffuse",
	    scalar          "specular",
	    scalar          "transp",
	    scalar          "reflect",
	    scalar          "bump",
	    scalar          "u_unit",
	    scalar          "v_unit",
	    scalar          "u_wrap",
	    scalar          "v_wrap",
	    boolean         "blackwhite"
	}
    )
    version 1
end declare


declare shader
    struct {
	color           "ambient",
	color           "diffuse",
	color		"specular",
	scalar		"transp",
	scalar		"reflect"
    } "mi_soft_textures" (
	vector          "normal",       # dummy param to enforce eval of bumps
	color    	"ambient",	# ambient reflection coefficients 
	color      	"diffuse",	# diffuse reflection coefficients 
	color           "specular",	# specular reflection coefficients 
	color           "ambience",	# ambience 
	scalar          "transp",	# transparency 
	scalar          "reflect",	# reflectance 	    
	array struct    "textures" { 	# array of textures 
	    color texture   "map",
	    integer         "space",
	    integer         "mask",
	    integer         "comp",
	    integer         "method",
	    scalar          "blend",
	    scalar          "ambient",
	    scalar          "diffuse",
	    scalar          "specular",
	    scalar          "transp",
	    scalar          "reflect",
	    scalar          "bump",
	    scalar          "u_unit",
	    scalar          "v_unit",
	    scalar          "u_wrap",
	    scalar          "v_wrap",
	    boolean         "blackwhite"
	}
    )
    version 1
end declare


declare shader
    scalar "mi_soft_staticblur" (
	scalar          "transp",	# input transparency 
	boolean 	"sblur",	# static blur? 
	scalar		"sblurdecay"	# falloff strength 
    )
    version 1
end declare


declare shader
    struct {
	scalar		"ior_in",	# incident index of refraction
	scalar		"ior_out",	# exitant index of refraction
	shader          "refracvol"	# volume shader for refraction
    } "mi_soft_refraction_index" (
	scalar		"ior"		# index of refraction for material 
    )
    version 1
end declare


declare shader
    color "mi_soft_illumination" (
	integer		"mode",   	# 0=flat, 1=lambt, 2=phong, 3=blinn 
	color		"ambient",      # ambient material color
	color           "diffuse",	# diffuse material color
	color           "specular",	# specular material color
	scalar          "shiny",	# shinyness 
	array light     "lights",       # light sources 
	array light     "difflights" 	# diffuse light sources 
    )
    version 1
end declare


declare shader
    color "mi_soft_globillum" (
	color		"color",	# globillum is added to this color
	color		"diffuse"	# diffuse material color
    )
    version 1
end declare


declare shader
    color "mi_soft_reflection" (
	color		"color",	# reflection is added to this color
	scalar		"reflect",	# reflection coefficient
	boolean         "notrace"       # no trace for this material
    )
    version 1
end declare


declare shader
    color "mi_soft_refraction" (
	color		"color",	# refraction is added to this color
	scalar		"transp",	# refraction coefficient
	boolean         "notrace",      # no trace for this material
	scalar		"ior_in",	# incident index of refraction
	scalar		"ior_out",	# exitant index of refraction
	shader 		"refracvol"	# volume shader for refraction
    )
    version 1
end declare


declare shader
    color "mi_soft_shadow" (
	color		"diffuse",      # diffuse material color
	scalar		"transp",	# transparency
	shader 		"refracvol",	# volume shader
	array light     "lights",       # light sources 
	array light     "difflights" 	# diffuse light sources 
    )
    version 1
end declare


declare shader
    color "mi_soft_shadowselect" (
	color		"materialcolor",# color of material
	shader 		"shadowshader"  # color of shadow
    )	
    version 2
end declare



#
# Softimage material phenomenon
#

declare phenomenon
    color "mi_soft_material" ( 
        integer         "mode",         # 0=flat, 1=lambert, 2=phong, 3=blinn
        color           "ambient",
        color           "diffuse",
        color           "specular",
        color           "ambience",
        scalar          "shiny",
        scalar          "transp",
        scalar          "reflect",
        scalar          "ior",
        boolean         "sblur",
        scalar          "sblurdecay",
        boolean         "notrace",
        array light     "lights",
        array light     "difflights",
        array struct    "texture" {
	    color texture   "map",
	    integer         "space",
	    integer         "mask",
	    integer         "comp",
	    integer         "method",
	    scalar          "blend",
	    scalar          "ambient",
	    scalar          "diffuse",
	    scalar          "specular",
	    scalar          "transp",
	    scalar          "reflect",
	    scalar          "bump",
	    scalar          "u_unit",
	    scalar          "v_unit",
	    scalar          "u_wrap",
	    scalar          "v_wrap",
	    boolean         "blackwhite"
        }
    )
    version 1

    shader "bumpmap"        # output: normal
	"mi_soft_bumpmap" (
	    "textures"	= interface "texture"
	)

    shader "tex"            # output: ambient, diffuse, spec, reflect, refract
	"mi_soft_textures" (
	    "normal"	= "bumpmap",
	    "textures"	= interface "texture",
	    "ambience" 	= interface "ambience",
	    "ambient"	= interface "ambient",
	    "diffuse"	= interface "diffuse",
	    "specular"	= interface "specular",
	    "reflect"	= interface "reflect",
	    "transp"	= interface "transp"
	)

    shader "staticblur"     # output: transp
	"mi_soft_staticblur" (
	    "transp" 	= "tex.transp",
	    "sblur"		= interface "sblur",
	    "sblurdecay"	= interface "sblurdecay"
	)

    shader "refrindex"      # output: ior_in, ior_out, refracvol
	"mi_soft_refraction_index" (
	    "ior"		= interface "ior"
	)

    shader "directillum"    # output: color
	"mi_soft_illumination" (
	    "mode"		= interface "mode",
	    "ambient"	= "tex.ambient",
	    "diffuse"	= "tex.diffuse",
	    "specular"	= "tex.specular",
	    "shiny"		= interface "shiny",
	    "lights" 	= interface "lights",
	    "difflights" 	= interface "difflights",
	)

    shader "globalillum"    # output: color
	"mi_soft_globillum" (
	    "color"		= "directillum",
	    "diffuse"	= "tex.diffuse"
	)

    shader "reflection"     # output: color
	"mi_soft_reflection" (
	    "color"		= "globalillum",
	    "reflect"	= "tex.reflect",
	    "notrace"	= interface "notrace"
	)

    shader "refraction"     # output: color
	"mi_soft_refraction" (
	    "color" 	= "reflection",
	    "transp"	= "staticblur",
	    "notrace"	= interface "notrace",
	    "ior_in"	= "refrindex.ior_in",
	    "ior_out"	= "refrindex.ior_out",
	    "refracvol"	= "refrindex.refracvol"
	)

    shader "shadow"         # output: color
	"mi_soft_shadow" (
	    "diffuse"   = "tex.diffuse",
	    "transp"	= "staticblur",
	    "refracvol"	= "refrindex.refracvol",
	    "lights" 	= interface "lights",
	    "difflights" 	= interface "difflights",
	)
     
    shader "select"        # output: color
	"mi_soft_shadowselect" (
	    "materialcolor"	= "refraction",
	    "shadowshader"	  "shadow"
	) 

    root = "select"

end declare



#
# more base shaders
#

declare shader
    vector "mi_soft_remap_coords" (
	integer         "repu",
	integer         "repv",
	boolean         "altu",
	boolean         "altv",
	boolean         "swap",
	scalar          "minu",
	scalar          "maxu",
	scalar          "minv",
	scalar          "maxv",
	transform       "transform",
	boolean         "u_torus",
	boolean         "v_torus",
	integer         "method"	# 0..5==XY,YZ,XZ,UV,cyl/sph,UV-wrap
    )
    version 1
end declare


declare shader
    color "mi_soft_lookup_color_texture" (
	color texture   "texture",
	vector		"coords"
    )
    version 1
end declare



#
# Softimage 2D color texture phenomenon
#

declare phenomenon
    color "mi_soft_color" (
        color texture   "texture",
        integer         "repu",
        integer         "repv",
        boolean         "altu",
        boolean         "altv",
        boolean         "swap",
        scalar          "minu",
        scalar          "maxu",
        scalar          "minv",
        scalar          "maxv",
        transform       "transform",
        boolean         "u_torus",
        boolean         "v_torus",
        integer         "method"
    )
    version 1

    shader "remap"        	# output: coords
	"mi_soft_remap_coords" (
	    "repu"          = interface "repu",
	    "repv"          = interface "repv",
	    "altu"          = interface "altu",
	    "altv"          = interface "altv",
	    "swap"          = interface "swap",
	    "minu"          = interface "minu",
	    "maxu"          = interface "maxu",
	    "minv"          = interface "minv",
	    "maxv"          = interface "maxv",
	    "transform"     = interface "transform",
	    "u_torus"       = interface "u_torus",
	    "v_torus"       = interface "v_torus",
	    "method"        = interface "method"
	)

    shader "lookup"     	# output: color
	"mi_soft_lookup_color_texture" (
	    "coords"	= "remap",	
	    "texture"	= interface "texture",
	)

    root = "lookup"
end declare



#
# Softimage versions of base shaders (base.mi): added diffuse lights
#

declare shader
	color "mib_illum_lambert" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 2
end declare

declare shader
	color "mib_illum_phong" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		color 		"specular",
		scalar		"exponent",  # phong exponent
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 2
end declare

declare shader
	color "mib_illum_ward" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		color 		"glossy",
		scalar		"shiny_u",   # shinyness in u direction
		scalar		"shiny_v",   # shinyness in v direction
		vector		"u",         # u direction
		vector		"v",         # v direction
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 1
end declare

declare shader
	color "mib_illum_ward_deriv" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		color 		"glossy",
		scalar		"shiny_u",   # shinyness in u direction
		scalar		"shiny_v",   # shinyness in v direction
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 1
	derivative 1 	# requires surface derivatives	
end declare

declare shader
	color "mib_illum_blinn" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		color 		"specular",
		scalar		"roughness", # average microfacet slope
		scalar          "ior",       # rel. ior
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 2
end declare

declare shader
	color "mib_illum_cooktorr" (
		color		"ambience",
		color		"ambient",
		color 		"diffuse",
		color 		"specular",
		scalar		"roughness", # average microfacet slope
		color           "ior",       # rel. ior for three wavelengths
		integer		"mode",      # light selection mode 0..2
		array light	"lights",
		array light	"difflights"
	)
	version 2
end declare
