// cardinal_tetra

:int foundShader 0
:if ($GLSL) {
	:set foundShader 1
	:GLSLshader
	:vshader "varying vec4 color;"
	:vshader "varying vec4 specColor;"
	: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 "  specColor = vec4(gl_Normal.r,gl_Normal.g,gl_Normal.b,0);"
	:vshader "}"
  
	:fshader "varying vec4 color;"
	:fshader "varying vec4 specColor;"
	:fshader "varying vec2 texture_coordinate;"
	:fshader "varying vec2 texture_coordinateB;"
	:fshader "uniform sampler2D tex1,tex2,tex3,tex4;"
	:fshader "void main() {"
	:fshader "  gl_FragColor = color*texture2D(tex1, texture_coordinate) + vec4(1,1,1,0)*texture2D(tex2, texture_coordinateB)*texture2D(tex3, texture_coordinate) + specColor*texture2D(tex4, texture_coordinate);"
	:fshader "}"

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

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

	:addStage {
		:chans 4
		:tex spec.sgi {
			:mult .4
		}
		:combine ADD
		:uvIndex 1
	}

	:addStage {
		:chans 4
		:tex neon.sgi
		:combine MODULATE
		:uvIndex 0
	}
	:set diffuseMultiply .7

	:specularColorReflectionChan global/arrays/neonFalloffBlue.chan
	:reflectionTexScale 1.6 2.8
	
	:normalsToTexture 1

	:dontUpdate uv
}

:if ($foundShader == 0) {
	:if ($canDoMultAdd) {
		:if ($maxTexUnits >= 4) {
			//:CERR "hello world"
			:set foundShader 1
			
			:normalsToTexture 1
			:addStage {
				:chans 3
				:tex global/arrays/enviro3.sgi
				:arg1 TEXTURE
				:combine SELECTARG1
				:uvIndex 1
			}
			:reflectionTexScale 1.6 2.8
			
			:addStage {
				:chans 3
				:tex spec.sgi {
					:mult .4
				}
				:arg1 CURRENT
				:arg2 TEXTURE
				:combine MODULATE
				:uvIndex 0
			}
			
			:specularColorReflectionChan global/arrays/neonFalloffBlue.chan

			:addStage {
				:chans 3
				:tex neon.sgi
				:arg1 SPECULAR
				:arg2 TEXTURE
				:combine MULTIPLYADD
				:uvIndex 0
			}
			
			:addStage {
				:chans 4
				:tex body.sgi
				:arg1 DIFFUSE
				:arg2 TEXTURE
				:combine MULTIPLYADD
				:uvIndex 0
				:useAlpha
			}
			:set diffuseMultiply .65
		}
		:elseif ($maxTexUnits == 3) {
			
			:specularColorReflection global/arrays/enviroFloat.image
			/* this does a point-color based reflection pass */
			:addStage {
				:chans 3
				:tex spec.sgi {
					:mult .8
				}
				:arg1 SPECULAR
				:arg2 TEXTURE
				:combine MODULATE
				:uvIndex 0
			}
			
			:set foundShader 1
			:addStage {
				:chans 3
				:tex neon.sgi 1
				:arg1 CURRENT
				:arg2 TEXTURE
				:combine ADD
				:uvIndex 0
			}
			
			:addStage {
				:chans 4
				:tex body.sgi
				:arg1 DIFFUSE
				:arg2 TEXTURE
				:combine MULTIPLYADD
				:uvIndex 0
				:useAlpha
			}
			:set diffuseMultiply .7
			
			:set foundShader 1
		}
	}
	:if ($foundShader == 0) {
		:if ($maxTexUnits == 1) {
			:addStage {
				:chans 4
				:tex {
					:buffer -name body -chans 4 -file body.sgi
					:buffer -name spec -file spec.sgi
					:buffer -name neon -file neon.sgi
					:makeResized neonNew neon body
					:buffer -name alpha -chans 1 -file body.alpha
					:add body spec .3 .3 .3 0
					:add body neonNew .9 .9 .9 0
					:replaceAlpha body alpha
				}
				:arg1 DIFFUSE
				:arg2 TEXTURE
				:combine MODULATE2X
				:uvIndex 0
				:useAlpha
			}
			:set diffuseMultiply .45
		}
		:else {
			:addStage {
				:chans 4
				:tex body.sgi
				:arg1 DIFFUSE
				:arg2 TEXTURE
				:combine MODULATE2X
				:uvIndex 0
				:useAlpha
			}
		
			:addStage {
				:chans 3
				:tex neon.sgi {
					:mult .8
				}
				:arg1 CURRENT
				:arg2 TEXTURE
				:combine ADD
				:uvIndex 0
			}
			:set diffuseMultiply .45
		}
	}
}

:lighting 0
:dontUpdate uv

:doAlphaMultWhenOpaque 0
:doAlphaMultWhenTransparent 1


