0 Replies Latest reply on Dec 20, 2007 1:40 AM by dhirendvs

    Mosaic Effect : Problemof lines in output generated by Pixel Shader

    dhirendvs
      Hello,

      I have tried out the following Pixel shader code to create a Mosaic
      Effect when a texture is applied for a simple rectangle. (Clamp U, V
      addressing and Linear Filtering is being used for the texture) :

      sampler2D s0 : register( s0 );

      float4 mainPS( float2 vTex : TEXCOORD0 ) : COLOR0
      {
      if( vTex.x < 0.1f )
      vTex.x = 0.0f;
      else if( vTex.x < 0.2f )
      vTex.x = 0.1f;
      else if( vTex.x < 0.3f )
      vTex.x = 0.2f;
      else if( vTex.x < 0.4f )
      vTex.x = 0.3f;
      else if( vTex.x < 0.5f )
      vTex.x = 0.4f;
      else if( vTex.x < 0.6f )
      vTex.x = 0.5f;
      else if( vTex.x < 0.7f )
      vTex.x = 0.6f;
      else if( vTex.x < 0.8f )
      vTex.x = 0.7f;
      else if( vTex.x < 0.9f )
      vTex.x = 0.8f;
      else if( vTex.x < 1.0f )
      vTex.x = 0.9f;
      else
      vTex.x = 1.0f;

      if( vTex.y < 0.1f )
      vTex.y = 0.0f;
      else if( vTex.y < 0.2f )
      vTex.y = 0.1f;
      else if( vTex.y < 0.3f )
      vTex.y = 0.2f;
      else if( vTex.y < 0.4f )
      vTex.y = 0.3f;
      else if( vTex.y < 0.5f )
      vTex.y = 0.4f;
      else if( vTex.y < 0.6f )
      vTex.y = 0.5f;
      else if( vTex.y < 0.7f )
      vTex.y = 0.6f;
      else if( vTex.y < 0.8f )
      vTex.y = 0.7f;
      else if( vTex.y < 0.9f )
      vTex.y = 0.8f;
      else if( vTex.y < 1.0f )
      vTex.y = 0.9f;
      else
      vTex.y = 1.0f;

      return tex2D( s0, vTex /*- 2.0f*/ );

      }

      --> The above code could also have been written using :

      sampler2D s0 : register( s0 );

      float4 mainPS( float2 vTex : TEXCOORD0 ) : COLOR0
      {
      return tex2D( s0, saturate( floor ( vTex * 10 ) * 0.1 ) /* - 2.0f
      */ );

      }

      Although the above 2 pixel shaders produce a Mosaic effect, a few
      lines having some random color appear along the edges of some
      rectangles (These lines can be clearly seen when a complex texture is
      applied to the rectangle and "- 2.0f" is uncommented in the last line
      in the pixel shader in order to produce a black frame).

      The rendering is done using an ATI X700 graphics card. I even tried
      disabling mipmaps for the texture and using a texture having
      dimensions = some power of 2.But even that didn't solve the problem.

      Screen Shots of the output and the original texture are available at
      the following link :
      http://picasaweb.google.com/dh...OfLinesInMosaicEffect

      Can anybody please explain to me how to solve this problem of lines in
      the output?

      Regards,
      Dhiren Sarup.