Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What vertex shader code should be used for a pixel shader used for simple 2D SpriteBatch drawing in XNA?
  2. Invalid effect file. Unable to find vertex shader in pass "P0"
  3.        
  4. void SpriteVertexShader(inout float4 color    : COLOR0,
  5.                         inout float2 texCoord : TEXCOORD0,
  6.                         inout float4 position : SV_Position)
  7. {
  8.     position = mul(position, MatrixTransform);
  9. }
  10.        
  11. Matrix projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1);
  12. Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
  13. Matrix transformation = halfPixelOffset * projection;
  14.        
  15. float2 Viewport; //Set to viewport size from application code
  16.  
  17. void SpriteVertexShader(inout float4 color    : COLOR0,
  18.                        inout float2 texCoord : TEXCOORD0,
  19.                        inout float4 position : POSITION0)
  20. {
  21.    // Half pixel offset for correct texel centering.
  22.    position.xy -= 0.5;
  23.    // Viewport adjustment.
  24.    position.xy = position.xy / Viewport;
  25.    position.xy *= float2(2, -2);
  26.    position.xy -= float2(1, -1);
  27. }