Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/shaders/shader-rep.sml
ViewVC logotype

View of /trunk/sml3d/src/shaders/shader-rep.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1236 - (download) (annotate)
Thu Sep 22 19:30:01 2011 UTC (7 years, 2 months ago) by samquinan
File size: 5317 byte(s)
fixed naming issues
structure ShaderRep =
  struct
  	
  	type mat4f = Matrix4f.mat4
  	type mat3f = Matrix3f.mat3
  	
  	datatype ty_rep
  	= T_FLOAT
  	| T_VEC2
  	| T_VEC3
  	| T_VEC4
  	| T_RGB
  	| T_RGBA
  	| T_MAT3
  	| T_MAT4
  	| T_BOOL
  	| T_INT
  	| T_TFORM2D
  	| T_TFORM3D
  	
  	datatype value
  	= NULL
  	| VEC4 of Vec4f.vec4
    | VEC3 of Vec3f.vec3
  	| VEC2 of Vec2f.vec2
    | RGB of Color.color3f
    | RGBA of Color.color4f
    | MAT3 of Matrix3f.mat3
    | MAT4 of Matrix4f.mat4
    | FLOAT of Float.float
    | BOOL of bool
    | INT of int
	
	fun typeOfValue v = 
		(case v of
			VEC4 _ => T_VEC4
		  | VEC3 _ => T_VEC3
		  | VEC2 _ => T_VEC2
		  | RGB _ => T_RGB
		  | RGBA _ => T_RGBA
		  | MAT3 _ => T_MAT3
		  | MAT4 _ => T_MAT4
		  | FLOAT _ => T_FLOAT
		  | BOOL _ => T_BOOL
		  | INT _ => T_INT
		  | _ => raise Fail ("value has no corresponding type")
		(*end case*))

	datatype var_ty
  	= UNIFORM
  	| ATTRIBUTE
  	| VARYING
  	| FRAG_VAR
  	| OUTPUT 
    
    type texture = 	{	id: word,
						name: string,
						dtype: ty_rep,
						var_type: var_ty
					}
						
    datatype sampler
    = TEX2D of texture
	| TEX3D of texture
	
	datatype cnxn = UNIF of {	id: word,
							name: string,
							dtype: ty_rep, 
							binding: bound_exp ref,
							location: shader_ty ref
						}
			  | ATTR of {	id: word,
							name: string,
							attr_kind: attr_ty,
							dtype: ty_rep, 
							binding: bound_exp ref,
							location: shader_ty ref
						}
			  | OUT of {	id: word,
							name: string,
							dtype: ty_rep, 
							binding: bound_exp ref,
							location: shader_ty ref
						}
				
	and attr_ty = T_CONST | T_INTERP
	
	and shader_ty = VERT | FRAG | BOTH
	
	and bound_exp = UNDEFINED
				  | EXPRESSION of exp list
	
	and exp = VAR of {  id: word,
						name: string,
						data_type: ty_rep,
						var_type: var_ty ref
					}
			 | SAMPLER of sampler
			 | CONST of value
			 | TFORM of transform
			 | PRIM of primitive
			 | IF of (exp * exp * exp) (* If then else *)
	
	and primitive (*! user should not be messing with shader rep level, so additional typechecking not necessary *
					* -- but may be a good idea during optimization though *)
	= NORM of exp							(* normalize *)
    | LEN of exp							(* length *)
    | ISO_SCALE	of (exp * exp)				(* isotropic vector scale *)
    | DOT of (exp * exp)					(* dot product *)
    | CROSS	of (exp * exp)					(* Cross product *)
    | EXTRACT_N of (exp * int)  			(* extracts the nth component of a color or position vector *)
    | NEG of exp							(* negation *)
    | ADD of (exp * exp)					(* scalar addition *)
    | SUB of (exp * exp)					(* scalar subtraction *)
    | MUL of (exp * exp)					(* scalar multiplication *)
    | DIV of (exp * exp)					(* scalar division *)
    | SQRT of exp							(* square root *)
    | ABS of exp		    				(* absolute value *)
    | POW of (exp * exp)					(* power *)
    | COS of exp							(* cosine *)
    | SIN of exp							(* sine *)
    | FRACT of exp							(* fractional component *)
    | MAX of (exp * exp)     				(* max *)
    | MIN of (exp * exp)    				(* min *)
    | MIX of (exp * exp * exp)    			(* lerp *)
    | STEP of (exp * exp)					(* returns 0.0 for each component in v1 < corresponding componnt in v0 *)
    | CLAMP of (exp * exp * exp) 			(* clamp -  [val, min, max] *)
    | GEN_VEC2 of (exp * exp)				(* create a vec2 from 2 floats *)
    | GEN_VEC3 of (exp * exp * exp) 		(* create a vec3 from 3 floats *)
    | GEN_VEC4 of (exp * exp * exp * exp)	(* create a vec4 from 4 floats *)
    | GEN_RGB of (exp * exp * exp)          (* create a rgb color vec from 3 floats *)
    | GEN_RGBA of (exp * exp * exp * exp)   (* create a rgba color vec from 4 floats *)
    | APPLY_TFORM of (exp * exp)		  	(* applies a transform to a point or vector *)
    | TFORM_NORM of (exp * exp)				(* applies a transform to a normal *)
    | SAMPLE_2D	of (exp * exp)				(* gets indexed value from sampler2D*)
    | SAMPLE_3D	of (exp * exp)				(* gets indexed value from sampler2D*)
    | AND of (exp * exp) 					(* boolean and *)
    | OR of (exp * exp)						(* boolean or *)
    | GT of (exp * exp)						(* greater than *)
    | LT of (exp * exp)						(* less than *)
    | EQUALS of (exp * exp)					(* equality *)
    | NOT of exp							(* negation *)
    
	and tform3D_rep
  	= T3_TRANSPOSE of tform3D_rep
  	| T3_INVERSE of tform3D_rep
  	| T3_IDENTITY
  	| T3_CUSTOM of exp 							(* mat4f *)
  	| T3_TRANSLATE of exp 						(* vec3f *)
  	| T3_ROTATE_X of exp 						(* float [radian value]*)
  	| T3_ROTATE_Y of exp 						(* float [radian value]*)
  	| T3_ROTATE_Z of exp 						(* float [radian value]*)
  	| T3_USCALE of exp 							(* float *)
  	| T3_SCALE of exp 							(* vec3f *)
  	| T3_CONCAT of (tform3D_rep * tform3D_rep)
  	
  	and tform2D_rep
  	= T2_TRANSPOSE of tform2D_rep
  	| T2_INVERSE of tform2D_rep
  	| T2_IDENTITY
  	| T2_CUSTOM of exp 							(* mat3f *)
  	| T2_TRANSLATE of exp 						(* vec2f *)
  	| T2_ROTATE_X of exp 						(* float [radian value]*)
  	| T2_ROTATE_Y of exp 						(* float [radian value]*)
  	| T2_USCALE of exp 							(* float *)
  	| T2_SCALE of exp 							(* vec2f *)
  	| T2_CONCAT of (tform2D_rep * tform2D_rep)
  	
  	and transform
  	= TFORM_2D of tform2D_rep
  	| TFORM_3D of tform3D_rep
  	
  	datatype shader = SHDR of exp
    
  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0