Index: plugins/GSdx/GSDeviceDX.h =================================================================== --- plugins/GSdx/GSDeviceDX.h (revision 2697) +++ plugins/GSdx/GSDeviceDX.h (working copy) @@ -93,6 +93,7 @@ GSVector4 MinMax; GSVector4 MinF_TA; GSVector4i MskFix; + GSVector4 ChannelMask; struct PSConstantBuffer() { @@ -102,6 +103,7 @@ MinMax = GSVector4::zero(); MinF_TA = GSVector4::zero(); MskFix = GSVector4i::zero(); + ChannelMask = GSVector4(1,1,1,1); } __forceinline bool Update(const PSConstantBuffer* cb) @@ -170,12 +172,13 @@ uint32 aout:1; uint32 rt:1; uint32 ltf:1; + uint32 colclipmode:2; }; uint32 key; }; - operator uint32() {return key & 0x3fffff;} + operator uint32() {return key & 0xffffff;} PSSelector() : key(0) {} }; @@ -234,6 +237,7 @@ uint32 wg:1; uint32 wb:1; uint32 wa:1; + uint32 negative:1; }; struct @@ -246,7 +250,7 @@ uint32 key; }; - operator uint32() {return key & 0x1fff;} + operator uint32() {return key & 0x3fff;} OMBlendSelector() : key(0) {} Index: plugins/GSdx/GSRendererDX.h =================================================================== --- plugins/GSdx/GSRendererDX.h (revision 2697) +++ plugins/GSdx/GSRendererDX.h (working copy) @@ -226,6 +226,11 @@ GSDeviceDX::PSSamplerSelector ps_ssel; GSDeviceDX::PSConstantBuffer ps_cb; + if (env.COLCLAMP.CLAMP == 0) { + ps_sel.colclipmode = 1; + ps_cb.ChannelMask = GSVector4((float)om_bsel.wr, (float)om_bsel.wg, (float)om_bsel.wb, (float)om_bsel.wa); + } + ps_sel.clr1 = om_bsel.IsCLR1(); ps_sel.fba = context->FBA.FBA; ps_sel.aout = context->FRAME.PSM == PSM_PSMCT16 || context->FRAME.PSM == PSM_PSMCT16S || (context->FRAME.FBMSK & 0xff000000) == 0x7f000000 ? 1 : 0; @@ -325,6 +330,17 @@ if(context->TEST.DoFirstPass()) { dev.DrawPrimitive(); + + if (env.COLCLAMP.CLAMP == 0) + { + om_bsel.negative = 1; + dev.SetupOM(om_dssel, om_bsel, afix); + + ps_sel.colclipmode = 2; + dev.SetupPS(ps_sel, &ps_cb, ps_ssel); + + dev.DrawPrimitive(); + } } if(context->TEST.DoSecondPass()) Index: plugins/GSdx/GSTextureFX9.cpp =================================================================== --- plugins/GSdx/GSTextureFX9.cpp (revision 2697) +++ plugins/GSdx/GSTextureFX9.cpp (working copy) @@ -144,7 +144,7 @@ if(i == m_ps.end()) { - string str[12]; + string str[13]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -158,6 +158,7 @@ str[9] = format("%d", sel.clr1); str[10] = format("%d", sel.rt); str[11] = format("%d", sel.ltf); + str[12] = format("%d", sel.colclipmode); D3DXMACRO macro[] = { @@ -173,6 +174,7 @@ {"PS_CLR1", str[9].c_str()}, {"PS_RT", str[10].c_str()}, {"PS_LTF", str[11].c_str()}, + {"PS_COLCLIPMODE", str[12].c_str()}, {NULL, NULL}, }; @@ -290,6 +292,16 @@ bs->SrcBlendAlpha = D3DBLEND_ONE; bs->DestBlendAlpha = D3DBLEND_ZERO; + // Not very good but I don't wanna write another 81 row table + if (bsel.negative && bs->DestBlend != D3DBLEND_ZERO) { + if (bs->BlendOp == D3DBLENDOP_ADD) + bs->BlendOp = D3DBLENDOP_REVSUBTRACT; + else if (bs->BlendOp == D3DBLENDOP_REVSUBTRACT) + bs->BlendOp = D3DBLENDOP_ADD; + else + ; // god knows, best just not to mess with it for now + } + if(blendMapD3D9[i].bogus == 1) { ASSERT(0); Index: plugins/GSdx/res/tfx.fx =================================================================== --- plugins/GSdx/res/tfx.fx (revision 2697) +++ plugins/GSdx/res/tfx.fx (working copy) @@ -33,6 +33,7 @@ #define PS_FBA 0 #define PS_AOUT 0 #define PS_LTF 1 +#define PS_COLCLIPMODE 0 #endif struct VS_INPUT @@ -87,6 +88,7 @@ float2 MinF; float2 TA; uint4 MskFix; + float4 ChannelMask; }; float4 sample_c(float2 uv) @@ -121,6 +123,7 @@ #define PS_CLR1 0 #define PS_RT 0 #define PS_LTF 0 +#define PS_COLCLIPMODE 0 #endif struct VS_INPUT @@ -155,7 +158,7 @@ #define VertexOffset vs_params[1] #define TextureScale vs_params[2].xy -float4 ps_params[5]; +float4 ps_params[6]; #define FogColor ps_params[0].bgr #define AREF ps_params[0].a @@ -164,6 +167,7 @@ #define MinMax ps_params[3] #define MinF ps_params[4].xy #define TA ps_params[4].zw +#define ChannelMask ps_params[5] float4 sample_c(float2 uv) { @@ -647,6 +651,15 @@ if(c.a < 0.5) c.a += 0.5; } + if (PS_COLCLIPMODE == 2) + { + c = 256/255 - c; + } + if (PS_COLCLIPMODE > 0) + { + clip(128/255 - c * ChannelMask); + } + output.c0 = c; return output; @@ -712,6 +725,15 @@ c.a *= 2; + if (PS_COLCLIPMODE == 2) + { + c = 256./255. - c; + } + if (PS_COLCLIPMODE > 0) + { + clip(128./255. - c * ChannelMask); + } + return c; }