Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pixel Shader for TEV stages
- //3 TEV stages, 2 texgens, 2 IND stages
- int idot(int3 x, int3 y)
- {
- int3 tmp = x * y;
- return tmp.x + tmp.y + tmp.z;
- }
- int idot(int4 x, int4 y)
- {
- int4 tmp = x * y;
- return tmp.x + tmp.y + tmp.z + tmp.w;
- }
- int iround(float x) { return int (round(x)); }
- int2 iround(float2 x) { return int2(round(x)); }
- int3 iround(float3 x) { return int3(round(x)); }
- int4 iround(float4 x) { return int4(round(x)); }
- SamplerState samp[8] : register(s0);
- Texture2DArray Tex[8] : register(t0);
- cbuffer PSBlock : register(b0) {
- int4 color[4];
- int4 k[4];
- int4 alphaRef;
- float4 texdim[8];
- int4 czbias[2];
- int4 cindscale[2];
- int4 cindmtx[6];
- int4 cfogcolor;
- int4 cfogi;
- float4 cfogf[2];
- float4 czslope;
- float2 cefbscale;
- uint bpmem_genmode;
- uint bpmem_alphaTest;
- uint bpmem_fogParam3;
- uint bpmem_fogRangeBase;
- uint bpmem_dstalpha;
- uint bpmem_ztex_op;
- bool bpmem_late_ztest;
- bool bpmem_rgba6_format;
- bool bpmem_dither;
- bool bpmem_bounding_box;
- uint4 bpmem_pack1[16];
- uint4 bpmem_pack2[8];
- int4 konstLookup[32];
- };
- #define bpmem_combiners(i) (bpmem_pack1[(i)].xy)
- #define bpmem_tevind(i) (bpmem_pack1[(i)].z)
- #define bpmem_iref(i) (bpmem_pack1[(i)].w)
- #define bpmem_tevorder(i) (bpmem_pack2[(i)].x)
- #define bpmem_tevksel(i) (bpmem_pack2[(i)].y)
- struct VS_OUTPUT {
- float4 pos : POSITION;
- float4 colors_0 : COLOR0;
- float4 colors_1 : COLOR1;
- float3 tex0 : TEXCOORD0;
- float3 tex1 : TEXCOORD1;
- float4 clipPos : TEXCOORD2;
- float clipDist0 : SV_ClipDistance0;
- float clipDist1 : SV_ClipDistance1;
- };
- void main(
- out uint4 ocol0 : SV_Target,
- in float4 rawpos : SV_Position,
- in float4 colors_0 : COLOR0,
- in float4 colors_1 : COLOR1
- ,
- in float3 tex0 : TEXCOORD0,
- in float3 tex1 : TEXCOORD1,
- in float4 clipPos : TEXCOORD2,
- in float clipDist0 : SV_ClipDistance0
- ,
- in float clipDist1 : SV_ClipDistance1
- ) {
- int4 c0 = color[1], c1 = color[2], c2 = color[3], prev = color[0];
- int4 rastemp = int4(0, 0, 0, 0), textemp = int4(0, 0, 0, 0), konsttemp = 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), tempcoord=int2(0,0);
- int4 tevin_a=int4(0,0,0,0),tevin_b=int4(0,0,0,0),tevin_c=int4(0,0,0,0),tevin_d=int4(0,0,0,0);
- float4 col0 = colors_0;
- float4 col1 = colors_1;
- int2 fixpoint_uv0 = int2((tex0.z == 0.0 ? tex0.xy : tex0.xy / tex0.z) * texdim[0].zw);
- int2 fixpoint_uv1 = int2((tex1.z == 0.0 ? tex1.xy : tex1.xy / tex1.z) * texdim[1].zw);
- tempcoord = fixpoint_uv1 >> cindscale[0].zw;
- int3 iindtex1 = iround(255.0 * Tex[2].Sample(samp[2], float3(float2(tempcoord).xy * texdim[2].xy, 0.0))).abg;
- // TEV stage 0
- // indirect op
- int2 indtevtrans0 = int2(0, 0);
- wrappedcoord.x = fixpoint_uv0.x;
- wrappedcoord.y = fixpoint_uv0.y;
- tevcoord.xy = wrappedcoord + indtevtrans0;
- tevcoord.xy = (tevcoord.xy << 8) >> 8;
- rastemp = iround(col0 * 255.0).rgba;
- textemp = int4(255, 255, 255, 255);
- tevin_a = int4(rastemp.rgb, 0)&int4(255, 255, 255, 255);
- tevin_b = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
- tevin_c = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
- tevin_d = int4(int3(0,0,0), rastemp.a);
- // color combine
- c2.rgb = clamp((((tevin_d.rgb)) + (((((tevin_a.rgb<<8) + (tevin_b.rgb-tevin_a.rgb)*(tevin_c.rgb+(tevin_c.rgb>>7)))) + 128)>>8)), int3(0,0,0), int3(255,255,255));
- // alpha combine
- prev.a = clamp((((tevin_d.a)) + (((((tevin_a.a<<8) + (tevin_b.a-tevin_a.a)*(tevin_c.a+(tevin_c.a>>7)))))>>8)), 0, 255);
- // TEV stage 1
- // indirect op
- int3 iindtevcrd1 = iindtex1 & 255;
- int2 indtevtrans1 = int2(idot(cindmtx[0].xyz, iindtevcrd1), idot(cindmtx[1].xyz, iindtevcrd1)) >> 3;
- if (cindmtx[0].w >= 0) indtevtrans1 >>= cindmtx[0].w;
- else indtevtrans1 <<= (-cindmtx[0].w);
- wrappedcoord.x = fixpoint_uv1.x;
- wrappedcoord.y = 0;
- tevcoord.xy += wrappedcoord + indtevtrans1;
- tevcoord.xy = (tevcoord.xy << 8) >> 8;
- textemp = iround(255.0 * Tex[0].Sample(samp[0], float3(float2(tevcoord.xy).xy * texdim[0].xy, 0.0))).rgba;
- tevin_a = int4(c2.rgb, 0)&int4(255, 255, 255, 255);
- tevin_b = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
- tevin_c = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
- tevin_d = int4(textemp.rgb, textemp.a);
- // color combine
- prev.rgb = clamp((((tevin_d.rgb)) + (((((tevin_a.rgb<<8) + (tevin_b.rgb-tevin_a.rgb)*(tevin_c.rgb+(tevin_c.rgb>>7)))) + 128)>>8)), int3(0,0,0), int3(255,255,255));
- // alpha combine
- prev.a = clamp((((tevin_d.a)) + (((((tevin_a.a<<8) + (tevin_b.a-tevin_a.a)*(tevin_c.a+(tevin_c.a>>7)))))>>8)), 0, 255);
- // TEV stage 2
- // indirect op
- int2 indtevtrans2 = int2(0, 0);
- wrappedcoord.x = fixpoint_uv0.x;
- wrappedcoord.y = fixpoint_uv0.y;
- tevcoord.xy = wrappedcoord + indtevtrans2;
- tevcoord.xy = (tevcoord.xy << 8) >> 8;
- textemp = int4(255, 255, 255, 255);
- tevin_a = int4(c0.rgb, prev.a)&int4(255, 255, 255, 255);
- tevin_b = int4(c2.rgb, 0)&int4(255, 255, 255, 255);
- tevin_c = int4(prev.rgb, 0)&int4(255, 255, 255, 255);
- tevin_d = int4(int3(0,0,0), 0);
- // color combine
- prev.rgb = clamp( tevin_d.rgb + ((idot(tevin_a.rgb, comp16) > idot(tevin_b.rgb, comp16)) ? tevin_c.rgb : int3(0,0,0)), int3(0,0,0), int3(255,255,255));
- // alpha combine
- prev.a = clamp((((tevin_d.a)) + (((((tevin_a.a<<8) + (tevin_b.a-tevin_a.a)*(tevin_c.a+(tevin_c.a>>7)))))>>8)), 0, 255);
- prev = prev & 255;
- if(!( (prev.a > alphaRef.r) && (true))) {
- ocol0 = float4(0.0, 0.0, 0.0, 0.0);
- ocol1 = float4(0.0, 0.0, 0.0, 0.0);
- discard;
- }
- int zCoord = int((1.0 - rawpos.z) * 16777216.0);
- zCoord = clamp(zCoord, 0, 0xFFFFFF);
- ocol0 = uint4(prev);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement