#version 130 #extension GL_ARB_uniform_buffer_object : enable #define ATTRIN in #define ATTROUT out #define VARYIN centroid in #define VARYOUT centroid out #define float2 vec2 #define float3 vec3 #define float4 vec4 #define uint2 uvec2 #define uint3 uvec3 #define uint4 uvec4 #define int2 ivec2 #define int3 ivec3 #define int4 ivec4 #define frac fract #define lerp mix #extension GL_ARB_texture_rectangle : enable #define COLOROUT(name) out vec4 name; //Pixel Shader for TEV stages //5 TEV stages, 4 texgens, 0 IND stages float fmod( float x, float y ) { float z = fract( abs( x / y) ) * abs( y ); return (x < 0.0) ? -z : z; } uniform sampler2D samp0; uniform sampler2D samp1; uniform sampler2D samp2; uniform sampler2D samp3; uniform sampler2D samp4; uniform sampler2D samp5; uniform sampler2D samp6; uniform sampler2D samp7; layout(std140) uniform PSBlock { float4 color[4] ; float4 k[4] ; float4 alphaRef[1] ; float4 texdim[8] ; float4 czbias[2] ; float4 cindscale[2] ; float4 cindmtx[6] ; float4 cfog[3] ; float4 cPLights[40] ; float4 cPmtrl[4] ; }; COLOROUT(ocol0) #define depth gl_FragDepth VARYIN float4 colors_02; VARYIN float4 colors_12; VARYIN float3 uv0_2; VARYIN float3 uv1_2; VARYIN float3 uv2_2; VARYIN float3 uv3_2; VARYIN float4 clipPos_2; void main() { int4 ic0 = int4(color[1] * 255.0), ic1 = int4(color[2] * 255.0), ic2 = int4(color[3] * 255.0), iprev = int4(color[0] * 255.0); int4 irastemp = int4(0, 0, 0, 0), itextemp = int4(0, 0, 0, 0), ikonsttemp = int4(0, 0, 0, 0); int3 comp16 = int3(1, 256, 0), comp24 = int3(1, 256, 256*256); int alphabump=0; int3 tevcoord=int3(0, 0, 0); int2 wrappedcoord=int2(0,0); float2 tempcoord=float2(0.0,0.0); int4 icc0=int4(0, 0, 0, 0), icc1=int4(0, 0, 0, 0); int4 icc2=int4(0, 0, 0, 0), icprev=int4(0, 0, 0, 0); int4 icrastemp = int4(0, 0, 0, 0), ickonsttemp = int4(0, 0, 0, 0); float4 rawpos = gl_FragCoord; float4 colors_0 = colors_02; float4 colors_1 = colors_12; float3 uv0 = uv0_2; float3 uv1 = uv1_2; float3 uv2 = uv2_2; float3 uv3 = uv3_2; float4 clipPos = clipPos_2; clipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w); uv0.xy = uv0.xy * texdim[0].zw; uv1.xy = uv1.xy * texdim[1].zw; uv2.xy = uv2.xy * texdim[2].zw; uv3.xy = uv3.xy * texdim[3].zw; // TEV stage 0 tevcoord.xy = int2(uv1.xy*256.0); itextemp = int4(255.0f * texture(samp1,(float2(tevcoord.xy)/256.0).xy * texdim[1].xy)).rgba; ikonsttemp = int4(int3(k[0].aaa * 255.0f), int(k[0].a * 255.0f)); // color combine ic2.rgb = clamp( (int3(0,0,0)&255) + ((dot((itextemp.aaa.rgb&255), comp16) > dot((ikonsttemp.rgb.rgb&255), comp16)) ? (int3(255,255,255)&255): int3(0,0,0)), int3(0,0,0), int3(255,255,255)); // alpha combine iprev.a = clamp(((int4(0,0,0,0).a&255) * (255 - (int4(0,0,0,0).a&255)) + (int4(0,0,0,0).a&255) * (int4(0,0,0,0).a&255)) / 255, 0, 255); // TEV done // TEV stage 1 tevcoord.xy = int2(uv0.xy*256.0); itextemp = int4(255.0f * texture(samp0,(float2(tevcoord.xy)/256.0).xy * texdim[0].xy)).rgba; // color combine iprev.rgb = clamp(((int3(0,0,0)&255) * (int3(255,255,255) - (ic2.rgb&255)) + (itextemp.rgb&255) * (ic2.rgb&255)) / 255, int3(0,0,0), int3(255,255,255)); // alpha combine iprev.a = clamp(((int4(0,0,0,0).a&255) * (255 - (int4(0,0,0,0).a&255)) + (int4(0,0,0,0).a&255) * (int4(0,0,0,0).a&255)) / 255, 0, 255); // TEV done // TEV stage 2 tevcoord.xy = int2(uv2.xy*256.0); itextemp = int4(255.0f * texture(samp2,(float2(tevcoord.xy)/256.0).xy * texdim[2].xy)).rgba; // color combine iprev.rgb = clamp(iprev.rgb + ((itextemp.rgb&255) * (int3(255,255,255) - (ic2.rgb&255)) + (int3(0,0,0)&255) * (ic2.rgb&255)) / 255, int3(0,0,0), int3(255,255,255)); // alpha combine iprev.a = clamp(((int4(0,0,0,0).a&255) * (255 - (int4(0,0,0,0).a&255)) + (int4(0,0,0,0).a&255) * (int4(0,0,0,0).a&255)) / 255, 0, 255); // TEV done // TEV stage 3 irastemp = int4(colors_0 * 255.0f).rgba; tevcoord.xy = int2(uv3.xy*256.0); itextemp = int4(255.0f * texture(samp3,(float2(tevcoord.xy)/256.0).xy * texdim[3].xy)).rgba; ikonsttemp = int4(159,159,159, int(k[0].a * 255.0f)); // color combine ic1.rgb = clamp(ic0.rgb + ((itextemp.rgb&255) * (int3(255,255,255) - (ikonsttemp.rgb&255)) + (irastemp.rgb&255) * (ikonsttemp.rgb&255)) / 255- 128, int3(0,0,0), int3(255,255,255)); // alpha combine iprev.a = ((int4(0,0,0,0).a&255) * (255 - (int4(0,0,0,0).a&255)) + (int4(0,0,0,0).a&255) * (int4(0,0,0,0).a&255)) / 255; // TEV done // TEV stage 4 irastemp = int4(colors_1 * 255.0f).rgba; itextemp = int4(255, 255, 255, 255); ikonsttemp = int4(127,127,127, int(k[0].a * 255.0f)); // color combine iprev.rgb = clamp(iprev.rgb + ((ic1.rgb&255) * (int3(255,255,255) - (ikonsttemp.rgb&255)) + (irastemp.rgb&255) * (ikonsttemp.rgb&255)) / 255- 128, int3(0,0,0), int3(255,255,255)); // alpha combine iprev.a = irastemp.a + ((int4(0,0,0,0).a&255) * (255 - (int4(0,0,0,0).a&255)) + (int4(0,0,0,0).a&255) * (int4(0,0,0,0).a&255)) / 255; // TEV done iprev = iprev & 255; float zCoord = czbias[1].x + (clipPos.z / clipPos.w) * czbias[1].y; depth = zCoord; float ze = cfog[1].x / (cfog[1].y - (zCoord / cfog[1].w)); float fog = clamp(ze - cfog[1].z, 0.0, 1.0); iprev.rgb = (iprev.rgb*(int(256.0-fog))) / 256; ocol0 = float4(iprev) / 255.0f; }