string description = "ZX-Spectrum shader"; //------------------------------------ float4x4 worldViewProj : WorldViewProjection; float4 materialDiffuse : Diffuse; texture textureDiffuse : Diffuse; float2 screenSize; float4 colorseparator = {0.2,0.55,0.85,1.0}; float4 colorvalue = {0,0.87,1.0,0}; //------------------------------------ struct vertexInput { float3 position : POSITION; float4 texCoordDiffuse : TEXCOORD0; }; struct vertexOutput { float4 vPosition : POSITION0; float4 texCoordDiffuse : TEXCOORD0; float3 coord : TEXCOORD1; }; //------------------------------------ vertexOutput VS_Transform(vertexInput IN) { vertexOutput OUT; OUT.vPosition = mul( float4(IN.position.xyz , 1.0) , worldViewProj); OUT.coord=IN.position.xyz; OUT.texCoordDiffuse = IN.texCoordDiffuse; return OUT; } //------------------------------------ sampler TextureSampler = sampler_state { texture = ; AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP; MIPFILTER = NONE; MINFILTER = POINT; MAGFILTER = POINT; }; float4 Spectrumize(float4 tc, float3 coords) { float4 c = {0,0,0,0}; float4 p = mul( float4(coords , 1.0) , worldViewProj); p.x=(p.x/p.w-1)/2*(screenSize[0]-1); p.y=(p.y/p.w-1)/2*(screenSize[1]-1); bool bright; int numpresent=0; if (tc.r>colorseparator[0]) numpresent++; if (tc.g>colorseparator[0]) numpresent++; if (tc.b>colorseparator[0]) numpresent++; if (tc.r+tc.g+tc.b>colorseparator[2]*numpresent) { bright=true; } for (int i=0;i<3;i++) { if (tc[i]colorseparator[1]) { if (!bright) { c[i]=colorvalue[1]; } else { c[i]=colorvalue[2]; } } else { if (((int)p.x+(int)p.y)%2==0) { c[i]=colorvalue[0]; } else { if (!bright) { c[i]=colorvalue[1]; } else { c[i]=colorvalue[2]; } } } } if (tc[3]>colorseparator[1]) { c[3]=colorvalue[2]; } else { if (((int)p.x+(int)p.y)%2==0) { c[3]=colorvalue[0]; } else { c[3]=colorvalue[2]; } } return c; } //----------------------------------- float4 PS_PixelateTextured(vertexOutput IN): COLOR { float4 tc = tex2D( TextureSampler, IN.texCoordDiffuse ) * materialDiffuse; return Spectrumize(tc,IN.coord); } //----------------------------------- float4 PS_Pixelate( vertexOutput IN): COLOR { float4 tc = materialDiffuse; return Spectrumize(tc,IN.coord); } //----------------------------------- technique pixelated { pass p0 { VertexShader = compile vs_1_1 VS_Transform(); PixelShader = compile ps_2_0 PS_Pixelate(); } } technique textured { pass p0 { VertexShader = compile vs_1_1 VS_Transform(); PixelShader = compile ps_2_0 PS_PixelateTextured(); } }