:int foundShader 0

:if ($GLSL) {

	:set foundShader 1
	:CERR "GLSL WAS SENSED"
	: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) + texture2D(tex2, texture_coordinateB)*texture2D(tex3, texture_coordinate) + specColor*texture2D(tex4, texture_coordinate);"
	:fshader "}"

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

	: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
	}

	:addStage {
		:chans 4
		:tex {
			:buffer -name neon -chans 4 -file neon.sgi
			:setAlpha neon 0
		}
		:combine MODULATE
		:uvIndex 0
	}
	
	:specularColorReflectionChan global/arrays/neonFalloffBlue.chan
	:reflectionTexScale 2

	:normalsToTexture 1

	:dontUpdate uv
}

:if ($canDoMultAdd) {
	:if ($maxTexUnits >= 5) {
		:if ($canDoTemp) {
			:set foundShader 1
			
			:normalsToTexture 1
			:addStage {
				:chans 3
				:tex global/arrays/enviro3.sgi
				:arg1 TEXTURE
				:combine SELECTARG1
				:uvIndex 1
			}
			:addStage {
				:chans 3
				:tex spec.sgi
				:arg2 CURRENT
				:arg1 TEXTURE
				:combine MODULATE
				:uvIndex 0
			}
			:specularColorReflectionChan global/arrays/neonFalloffBlue.chan
			:reflectionTexScale 3
 
 			:addStage {
				:chans 4
				:tex {
					:buffer -name neon -chans 4 -file neon.sgi
					:buffer -name alpha -chans 1 -file body.alpha
					:replaceAlpha neon alpha
				}
				:arg2 SPECULAR
				:arg1 TEXTURE
				:combine MULTIPLYADD
				:useAlpha
				:uvIndex 0
			}

			:addStage {
				:chans 3
				:tex body.sgi
				:arg2 DIFFUSE
				:arg1 TEXTURE
				:combine MODULATE2X
				:resultArg TEMP
				:uvIndex 0
			}
			:set diffuseMultiply .5
			
			:addStage {
				:arg1 CURRENT
				:arg2 TEMP
				:combine ADD
			}
		}
	}
	
	:if ($foundShader == 0) {
		:if ($maxTexUnits >= 2) {
			:set foundShader 1
 			:addStage {
				:chans 4
				:tex body.sgi
				:tex {
					:buffer -name body -chans 4 -file body.sgi
					:buffer -name spec -file spec.sgi
					:add body spec .3 .3 .3 0
				}
				:arg1 DIFFUSE
				:arg2 TEXTURE
				:combine MODULATE2X
				:uvIndex 0
			}
 			:addStage {
				:chans 4
				:tex {
					:buffer -name neon -chans 4 -file neon.sgi
					:buffer -name alpha -chans 1 -file body.alpha
					:replaceAlpha neon alpha
				}
				:arg1 TEXTURE
				:arg2 SPECULAR
				:combine MULTIPLYADD
				:useAlpha
				:uvIndex 0
			}
			:set diffuseMultiply .48
			:specularColorReflectionChan global/arrays/neonFalloffBlue.chan
			:reflectionTexScale 3
		}
	}
}


: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
				:add body spec .3 .3 .3 0
				:add body neon .9 .9 .9 0
			}
			:arg1 DIFFUSE
			:arg2 TEXTURE
			:combine MODULATE2X
			:uvIndex 0
			:useAlpha
		}
		:set diffuseMultiply .45
	}
	:else {
		:addStage {
			:chans 4
			:tex {
				:buffer -name body -chans 4 -file body.sgi
				:buffer -name spec -file spec.sgi
				:add body spec .3 .3 .3 0
			}
			:arg1 DIFFUSE
			:arg2 TEXTURE
			:combine MODULATE2X
			:set diffuseMultiply .45
			:uvIndex 0
			:useAlpha
		}

		:addStage {
			:chans 3
			:tex neon.sgi
			:arg1 CURRENT
			:arg2 TEXTURE
			:combine ADD
			:uvIndex 0
		}
	}
}

:dontUpdate uv

:lighting 0

:doAlphaMultWhenOpaque 0
:doAlphaMultWhenTransparent 1
