//Pixel Shader for TEV stages //2 TEV stages, 2 texgens, XXX IND stages sampler samp0 : register(s0), samp1 : register(s1), samp2 : register(s2), samp3 : register(s3), samp4 : register(s4), samp5 : register(s5), samp6 : register(s6), samp7 : register(s7); Texture2D Tex0 : register(t0), Tex1 : register(t1), Tex2 : register(t2), Tex3 : register(t3), Tex4 : register(t4), Tex5 : register(t5), Tex6 : register(t6), Tex7 : register(t7); uniform float4 color[4] : register(c0); uniform float4 k[4] : register(c4); uniform float4 alphaRef[1] : register(c8); uniform float4 texdim[8] : register(c9); uniform float4 czbias[2] : register(c17); uniform float4 cindscale[2] : register(c19); uniform float4 cindmtx[6] : register(c21); uniform float4 cfog[3] : register(c27); typedef struct { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; } Light; typedef struct { Light lights[8]; } s_cLights; uniform s_cLights cLights : register(c30); typedef struct { float4 C0, C1, C2, C3; } s_cmtrl; uniform s_cmtrl cmtrl : register(c70); void main( out float4 ocol0 : SV_Target0, out float depth : SV_Depth, in float4 rawpos : SV_Position, in float4 colors_0 : COLOR0, in float4 colors_1 : COLOR1, in float3 uv0 : TEXCOORD0, in float3 uv1 : TEXCOORD1, in float4 clipPos : TEXCOORD2, in float4 Normal : TEXCOORD3 ) { float4 c0 = color[1], c1 = color[2], c2 = color[3], prev = float4(0.0f, 0.0f, 0.0f, 0.0f), textemp = float4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = float4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = float4(0.0f, 0.0f, 0.0f, 0.0f); float3 comp16 = float3(1.0f, 255.0f, 0.0f), comp24 = float3(1.0f, 255.0f, 255.0f*255.0f); float4 alphabump=float4(0.0f,0.0f,0.0f,0.0f); float3 tevcoord=float3(0.0f, 0.0f, 0.0f); float2 wrappedcoord=float2(0.0f,0.0f), tempcoord=float2(0.0f,0.0f); float4 cc0=float4(0.0f,0.0f,0.0f,0.0f), cc1=float4(0.0f,0.0f,0.0f,0.0f); float4 cc2=float4(0.0f,0.0f,0.0f,0.0f), cprev=float4(0.0f,0.0f,0.0f,0.0f); float4 crastemp=float4(0.0f,0.0f,0.0f,0.0f),ckonsttemp=float4(0.0f,0.0f,0.0f,0.0f); float3 _norm0 = normalize(Normal.xyz); float3 pos = float3(clipPos.x,clipPos.y,Normal.w); float4 mat, lacc; float3 ldir, h; float dist, dist2, attn; { mat = colors_0; lacc = float4(1.0f, 1.0f, 1.0f, 1.0f); lacc.w = 1.0f; colors_0 = mat * saturate(lacc); } { mat = cmtrl.C3; lacc = cmtrl.C1; lacc.w = cmtrl.C1.w; ldir = cLights.lights[0].pos.xyz - pos.xyz; dist2 = dot(ldir, ldir); dist = sqrt(dist2); ldir = ldir / dist; attn = max(0.0f, dot(ldir, cLights.lights[0].dir.xyz)); attn = max(0.0f, dot(cLights.lights[0].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot(cLights.lights[0].distatt.xyz, float3(1.0f,dist,dist2)); lacc.xyzw += attn * max(0.0f,dot(ldir, _norm0)) * cLights.lights[0].col.xyzw; ldir = cLights.lights[1].pos.xyz - pos.xyz; dist2 = dot(ldir, ldir); dist = sqrt(dist2); ldir = ldir / dist; attn = max(0.0f, dot(ldir, cLights.lights[1].dir.xyz)); attn = max(0.0f, dot(cLights.lights[1].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot(cLights.lights[1].distatt.xyz, float3(1.0f,dist,dist2)); lacc.xyzw += attn * max(0.0f,dot(ldir, _norm0)) * cLights.lights[1].col.xyzw; colors_1 = mat * saturate(lacc); } clipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w); uv0.xy = uv0.xy * texdim[0].zw; uv1.xy = uv1.xy * texdim[1].zw; // TEV stage 0 rastemp = colors_0.rgba; crastemp = frac(rastemp * (255.0f/256.0f)) * (256.0f/255.0f); tevcoord.xy = uv0.xy; textemp=Tex0.Sample(samp0,tevcoord.xy * texdim[0].xy).rgba; // color combine prev.rgb = saturate((textemp.rgb)*(crastemp.rgb)); // alpha combine prev.a = saturate(textemp.a*crastemp.a); // TEV done // TEV stage 1 tevcoord.xy = uv1.xy; textemp=Tex1.Sample(samp1,tevcoord.xy * texdim[1].xy).rgba; konsttemp = float4(0.25f,0.25f,0.25f, ERROR9); ckonsttemp = frac(konsttemp * (255.0f/256.0f)) * (256.0f/255.0f); cprev = prev; // color combine prev.rgb = saturate((prev.rgb)+float3(0.0f, 0.0f, 0.0f)); // alpha combine prev.a = saturate(textemp.a+cprev.a*(1.0f-ckonsttemp.a)); // TEV done if(!( (true) && (abs( prev.a - alphaRef[0].g ) >= (0.5f/255.0f)))) { ocol0 = 0; depth = 1.f; discard; } 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 x_adjust = (2.0f * (clipPos.x / cfog[2].y)) - 1.0f - cfog[2].x; x_adjust = sqrt(x_adjust * x_adjust + cfog[2].z * cfog[2].z) / cfog[2].z; ze *= x_adjust; float fog = saturate(ze - cfog[1].z); prev.rgb = lerp(prev.rgb,cfog[0].rgb,fog); ocol0 = prev; }