//congo_tetra

:int foundShader 0

:if ($GLSL) {
	:set foundShader 1
	:CERR "GLSL WAS SENSED"
	:GLSLshader
	:vshader "varying vec4 color;"
	:vshader "varying vec2 texture_coordinate;"
	:vshader "varying vec2 texture_coordinateB;"
	:vshader "void main() {"
	:vshader "  texture_coordinate = vec2(gl_MultiTexCoord0);"
	:vshader "  texture_coordinateB = vec2(gl_MultiTexCoord1);"
	:vshader "  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
	:vshader "  color = vec4(gl_Color.r,gl_Color.g,gl_Color.b,1);"
	:vshader "}"

	:fshader "varying vec4 color;"
	:fshader "varying vec2 texture_coordinate;"
	:fshader "varying vec2 texture_coordinateB;"
	:fshader "uniform sampler2D tex1,tex2,tex3;"
	:fshader "void main() {"
	:fshader "  gl_FragColor = color*texture2D(tex1, texture_coordinate) + texture2D(tex2, texture_coordinateB)*texture2D(tex3, texture_coordinate);"
	:fshader "}"

	:addStage {
		:chans 4
		:tex body.sgi
		:combine MODULATE
		:uvIndex 0
		:useAlpha
	}
	:set diffuseMultiply .9

	:addStage {
		:chans 3
		:tex global/arrays/enviro3.sgi
		:combine ADD
		:uvIndex 1
	}

	:addStage {
	:chans 4
		:tex {
			:buffer -name spec -chans 4 -file spec.sgi
			:setAlpha spec 0
		}
		:combine ADD
		:uvIndex 1
		:useAlpha
	}

	:normalsToTexture 1

	:dontUpdate uv
}

:if ($canDoMultAdd) {
	:if ($maxTexUnits >= 3) {
		:set foundShader 1	
		:addStage {
			:chans 3
			:tex global/arrays/enviro3.sgi
			:arg1 TEXTURE
			:combine SELECTARG1
			:uvIndex 1
		}
		
		:addStage {
			:chans 3
			:tex spec.sgi
			:arg1 CURRENT
			:arg2 TEXTURE
			:combine MODULATE
			:uvIndex 0
		}
		
		:addStage {
			:chans 4
			:tex body.sgi
			:arg1 DIFFUSE
			:arg2 TEXTURE
			:combine MULTIPLYADD
			:uvIndex 0
			:useAlpha
		}
		
		:normalsToTexture 1
		:set diffuseMultiply 1
	}
	:elseif ($maxTexUnits >= 2) {
		:set foundShader 1
		:addStage {
			:chans 4
			:tex body.sgi
			:arg1 DIFFUSE
			:arg2 TEXTURE
			:combine MODULATE2X
			:uvIndex 0
			:useAlpha
		}
		:addStage {
			:chans 3
			:tex spec.sgi
			:arg1 SPECULAR
			:arg2 TEXTURE
			:combine MULTIPLYADD
			:uvIndex 0
		}
		:set diffuseMultiply .5
		:specularColorReflection global/arrays/enviroFloat.image		
		:dontUpdate uv
	}
}

:if ($foundShader == 0) {
	:addStage {
		:chans 4
		:tex {
			:buffer -name body -chans 4 -file body.sgi
			:buffer -name spec -file spec.sgi
			:buffer -name alpha -chans 1 -file body.alpha
			:mult body .5 .5 .5 1
			:add body spec .4 .4 .4 0
			:replaceAlpha body alpha
		}
		:arg1 DIFFUSE
		:arg2 TEXTURE
		:combine MODULATE2X
		:uvIndex 0
		:useAlpha
	}
	:set diffuseMultiply .75
}

:dontUpdate uv
:doAlphaMultWhenOpaque 0
:doAlphaMultWhenTransparent 1
