Drawing a non rectangular part of Texture2d

If you wish to do this when using SpriteBatch you will need to write a pixel shader.
Which is probably the easiest way anyways.

You will need to send in a Ray to the shader. That is a position which is the player or maybe some distance behind him e.g. (float2 playerPosition;) and a direction he is looking at e.g. (float2 playerLookAtDirection;).
You will need to send in a float for range of vision in radians or degrees e.g. (float rangeInDegrees;)

In the pixel shader you will need to use the following general calculation.
(the variable names will be long and verbose for clarity).

float4 resultingPixelColor = tex2D(TextureSampler, input.TexureCoordinate); // *input.Color;
float2 playerToScreenPixelNormal = normalize(position.xy - playerPosition.xy);
float theta = dot(normalize(playerLookAtDirection) , playerToScreenPixelNormal );
float pixelDegreesToLineOfSight = theta * 90.0f;

// clips out anything not within the specified range to the line of site.
clip(pixelDegreesToLineOfSight - rangeInDegrees);

return resultingPixelColor; 
}

You will need to use the pipeline tool to make a New Effect.
http://www.monogame.net/documentation/?page=adding_content
Open it and you will see a standard barebones pixelshader.

Here is a small game1 and working shader that should help to see how to do it on both ends the game1 and the shader. The example below is just about copy pasteable and runable with a spritefont added in.

1 Like