/////////////////////////////////////////////////////////////////////////////// // // ## ###### // ###### ### // ## ############### Shark 3D Engine (www.shark3d.com) // ########## # # # // ######## Copyright (c) 1996-2006 Spinor GmbH. // ######### # # # All rights reserved. // ## ########## // ## // /////////////////////////////////////////////////////////////////////////////// struct PS_INPUT { float2 mainTexCoord: TEXCOORD0; float2 offsScale: TEXCOORD1; }; /////////////////////////////////////////////////////////////////////////////// sampler tex0: register(s0); /////////////////////////////////////////////////////////////////////////////// // Pixelshader // Profile: 2x0 float4 main(PS_INPUT input): COLOR0 { float2 mainTexCoord = input.mainTexCoord; float2 offsScale = input.offsScale; // Use filtering for additional smoothing effect. // The source-texture should be a filter-texture. // The size (width resp. height) of the destination-texture // should be 2 or 4 smaller than the size of the source-texture. // // Pixel in target-texture: X // // Source-sampling positions: S // *---* // Pixel in source-texture: | | // *---* // downscaling by 2 or more // no downscaling // *---*---*---*---* // *---*---*---* | | | | | // | S | | S | *---S---*---S---* // *---*---*---* | | | | | // | | X | | *---*---X---*---* // *---*---*---* | | | | | // | S | | S | *---S---*---S---* // *---*---*---* | | | | | // *---*---*---*---* // // Note: Since this filter cannot sample more than a 4x4 neighbourhood, // downscaling factor of 4 cannot be exceeded without skipping pixels. // With downsampling of 1 or less filtering can't be used for smoothing // because it results in an undesirable filter pattern. // Thus a scaling factor of 2 or 4 is recommanded. const float2 offsPix0 = float2(-1.0f,-1.0f); const float2 offsPix1 = float2( 1.0f,-1.0f); const float2 offsPix2 = float2(-1.0f, 1.0f); const float2 offsPix3 = float2( 1.0f, 1.0f); // neighbour texture coordinates: float2 neigh0 = offsScale * offsPix0 + mainTexCoord.xy; float2 neigh1 = offsScale * offsPix1 + mainTexCoord.xy; float2 neigh2 = offsScale * offsPix2 + mainTexCoord.xy; float2 neigh3 = offsScale * offsPix3 + mainTexCoord.xy; float4 avg = (tex2D(tex0, neigh0) + tex2D(tex0, neigh1) + tex2D(tex0, neigh2) + tex2D(tex0, neigh3)) * 0.25; return clamp(avg - 0.8, 0.0, 1.0) * 5.0; // STD } ///////////////////////////////////////////////////////////////////////////////