/* $Id: //sw/devtools/SDK/9.5/SDK/MEDIA/HLSL/bicubic.fx#1 $ Bicubic texture filtering This effect demonstrates bicubic texture filtering, a higher quality filtering method that uses a 4x4 footprint rather than the usual 2x2. This works best with an FP texture, but it's no strictly required for good results. There are three versions included, with increasing levels of optimization: Passes Comment Bicubic 141 Full precision, all math Bicubic2 78 Uses texture lookup, half precision Bicubic3 52 Calculates texcoord in vertex shader Bilinear 1 Hardware References: http://www.engineering.uiowa.edu/~gec/248_s00_students/blake_carlson/hw2/ http://www.path.unimelb.edu.au/~dersch/interpolator/interpolator.html */ float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "object"; string ScriptOrder = "standard"; string ScriptOutput = "color"; string Script = "Technique=Technique?Bicubic:Bicubic2:Bicubic3:Bilinear;"; > = 0.8; float4x4 worldViewProj : WorldViewProjection; // you need to change these if you load a different texture: const float2 imageSize = { 32.0, 32.0 }; const float2 texelSize = { 1.0 / 32.0, 1.0 / 32.0 }; texture imageTexture < string ResourceName = "lowres.png"; >; texture weightTex < string ResourceType = "2D"; string format = "A16B16G16R16F"; // should use a fp texture for this string function = "genWeightTex"; float2 Dimensions = { 256.0f, 1.0f}; >; sampler imageSampler = sampler_state { texture = ; MagFilter = Point; MinFilter = Point; MipFilter = None; }; sampler imageSamplerBilinear = sampler_state { texture = ; MagFilter = Linear; MinFilter = Linear; MipFilter = None; }; sampler weightSampler = sampler_state { texture = ; MagFilter = Linear; MinFilter = Linear; MipFilter = None; AddressU = Clamp; AddressV = Clamp; }; // vertex shader struct a2v { float4 pos : POSITION; float4 texcoord : TEXCOORD0; }; struct v2f { float4 pos : POSITION; float4 texcoord : TEXCOORD0; }; v2f bicubicVS(a2v IN) { v2f OUT; OUT.pos = mul(IN.pos, worldViewProj); OUT.texcoord = IN.texcoord; return OUT; } // compute 4 weights using the cubic polynomial: // w = (A+2.0)*x^3 - (A+3.0)*x^2 + 1.0 for 0 { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_1_1 bicubicVS(); PixelShader = compile ps_2_0 bicubicPS(); } } technique Bicubic2 < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_1_1 bicubicVS(); PixelShader = compile ps_2_0 bicubic2PS(); } } technique Bicubic3 < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_1_1 bicubic2VS(); PixelShader = compile ps_2_0 bicubic3PS(); } } technique Bilinear < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_1_1 bicubicVS(); PixelShader = compile ps_2_0 bilinearPS(); } }