Advertisement
PPLToast

Untitled

Sep 7th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. //Pixel Shader for TEV stages
  2. //3 TEV stages, 2 texgens, 2 IND stages
  3. int idot(int3 x, int3 y)
  4. {
  5. int3 tmp = x * y;
  6. return tmp.x + tmp.y + tmp.z;
  7. }
  8. int idot(int4 x, int4 y)
  9. {
  10. int4 tmp = x * y;
  11. return tmp.x + tmp.y + tmp.z + tmp.w;
  12. }
  13.  
  14. int iround(float x) { return int (round(x)); }
  15. int2 iround(float2 x) { return int2(round(x)); }
  16. int3 iround(float3 x) { return int3(round(x)); }
  17. int4 iround(float4 x) { return int4(round(x)); }
  18.  
  19. SamplerState samp[8] : register(s0);
  20.  
  21. Texture2DArray Tex[8] : register(t0);
  22.  
  23. cbuffer PSBlock : register(b0) {
  24. int4 color[4];
  25. int4 k[4];
  26. int4 alphaRef;
  27. float4 texdim[8];
  28. int4 czbias[2];
  29. int4 cindscale[2];
  30. int4 cindmtx[6];
  31. int4 cfogcolor;
  32. int4 cfogi;
  33. float4 cfogf[2];
  34. float4 czslope;
  35. float2 cefbscale;
  36. uint bpmem_genmode;
  37. uint bpmem_alphaTest;
  38. uint bpmem_fogParam3;
  39. uint bpmem_fogRangeBase;
  40. uint bpmem_dstalpha;
  41. uint bpmem_ztex_op;
  42. bool bpmem_late_ztest;
  43. bool bpmem_rgba6_format;
  44. bool bpmem_dither;
  45. bool bpmem_bounding_box;
  46. uint4 bpmem_pack1[16];
  47. uint4 bpmem_pack2[8];
  48. int4 konstLookup[32];
  49. };
  50.  
  51. #define bpmem_combiners(i) (bpmem_pack1[(i)].xy)
  52. #define bpmem_tevind(i) (bpmem_pack1[(i)].z)
  53. #define bpmem_iref(i) (bpmem_pack1[(i)].w)
  54. #define bpmem_tevorder(i) (bpmem_pack2[(i)].x)
  55. #define bpmem_tevksel(i) (bpmem_pack2[(i)].y)
  56.  
  57. struct VS_OUTPUT {
  58. float4 pos : POSITION;
  59. float4 colors_0 : COLOR0;
  60. float4 colors_1 : COLOR1;
  61. float3 tex0 : TEXCOORD0;
  62. float3 tex1 : TEXCOORD1;
  63. float4 clipPos : TEXCOORD2;
  64. float clipDist0 : SV_ClipDistance0;
  65. float clipDist1 : SV_ClipDistance1;
  66. };
  67. void main(
  68. out uint4 ocol0 : SV_Target,
  69. in float4 rawpos : SV_Position,
  70. in float4 colors_0 : COLOR0,
  71. in float4 colors_1 : COLOR1
  72. ,
  73. in float3 tex0 : TEXCOORD0,
  74. in float3 tex1 : TEXCOORD1,
  75. in float4 clipPos : TEXCOORD2,
  76. in float clipDist0 : SV_ClipDistance0
  77. ,
  78. in float clipDist1 : SV_ClipDistance1
  79. ) {
  80. int4 c0 = color[1], c1 = color[2], c2 = color[3], prev = color[0];
  81. int4 rastemp = int4(0, 0, 0, 0), textemp = int4(0, 0, 0, 0), konsttemp = int4(0, 0, 0, 0);
  82. int3 comp16 = int3(1, 256, 0), comp24 = int3(1, 256, 256*256);
  83. int alphabump=0;
  84. int3 tevcoord=int3(0, 0, 0);
  85. int2 wrappedcoord=int2(0,0), tempcoord=int2(0,0);
  86. 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);
  87.  
  88. float4 col0 = colors_0;
  89. float4 col1 = colors_1;
  90. int2 fixpoint_uv0 = int2((tex0.z == 0.0 ? tex0.xy : tex0.xy / tex0.z) * texdim[0].zw);
  91. int2 fixpoint_uv1 = int2((tex1.z == 0.0 ? tex1.xy : tex1.xy / tex1.z) * texdim[1].zw);
  92. tempcoord = fixpoint_uv1 >> cindscale[0].zw;
  93. int3 iindtex1 = iround(255.0 * Tex[2].Sample(samp[2], float3(float2(tempcoord).xy * texdim[2].xy, 0.0))).abg;
  94.  
  95. // TEV stage 0
  96. // indirect op
  97. int2 indtevtrans0 = int2(0, 0);
  98. wrappedcoord.x = fixpoint_uv0.x;
  99. wrappedcoord.y = fixpoint_uv0.y;
  100. tevcoord.xy = wrappedcoord + indtevtrans0;
  101. tevcoord.xy = (tevcoord.xy << 8) >> 8;
  102. rastemp = iround(col0 * 255.0).rgba;
  103. textemp = int4(255, 255, 255, 255);
  104. tevin_a = int4(rastemp.rgb, 0)&int4(255, 255, 255, 255);
  105. tevin_b = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
  106. tevin_c = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
  107. tevin_d = int4(int3(0,0,0), rastemp.a);
  108. // color combine
  109. 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));
  110. // alpha combine
  111. 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);
  112.  
  113. // TEV stage 1
  114. // indirect op
  115. int3 iindtevcrd1 = iindtex1 & 255;
  116. int2 indtevtrans1 = int2(idot(cindmtx[0].xyz, iindtevcrd1), idot(cindmtx[1].xyz, iindtevcrd1)) >> 3;
  117. if (cindmtx[0].w >= 0) indtevtrans1 >>= cindmtx[0].w;
  118. else indtevtrans1 <<= (-cindmtx[0].w);
  119. wrappedcoord.x = fixpoint_uv1.x;
  120. wrappedcoord.y = 0;
  121. tevcoord.xy += wrappedcoord + indtevtrans1;
  122. tevcoord.xy = (tevcoord.xy << 8) >> 8;
  123. textemp = iround(255.0 * Tex[0].Sample(samp[0], float3(float2(tevcoord.xy).xy * texdim[0].xy, 0.0))).rgba;
  124. tevin_a = int4(c2.rgb, 0)&int4(255, 255, 255, 255);
  125. tevin_b = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
  126. tevin_c = int4(int3(0,0,0), 0)&int4(255, 255, 255, 255);
  127. tevin_d = int4(textemp.rgb, textemp.a);
  128. // color combine
  129. 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));
  130. // alpha combine
  131. 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);
  132.  
  133. // TEV stage 2
  134. // indirect op
  135. int2 indtevtrans2 = int2(0, 0);
  136. wrappedcoord.x = fixpoint_uv0.x;
  137. wrappedcoord.y = fixpoint_uv0.y;
  138. tevcoord.xy = wrappedcoord + indtevtrans2;
  139. tevcoord.xy = (tevcoord.xy << 8) >> 8;
  140. textemp = int4(255, 255, 255, 255);
  141. tevin_a = int4(c0.rgb, prev.a)&int4(255, 255, 255, 255);
  142. tevin_b = int4(c2.rgb, 0)&int4(255, 255, 255, 255);
  143. tevin_c = int4(prev.rgb, 0)&int4(255, 255, 255, 255);
  144. tevin_d = int4(int3(0,0,0), 0);
  145. // color combine
  146. 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));
  147. // alpha combine
  148. 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);
  149. prev = prev & 255;
  150. if(!( (prev.a > alphaRef.r) && (true))) {
  151. ocol0 = float4(0.0, 0.0, 0.0, 0.0);
  152. ocol1 = float4(0.0, 0.0, 0.0, 0.0);
  153. discard;
  154. }
  155. int zCoord = int((1.0 - rawpos.z) * 16777216.0);
  156. zCoord = clamp(zCoord, 0, 0xFFFFFF);
  157. ocol0 = uint4(prev);
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement