Skip to content

Instantly share code, notes, and snippets.

@jackmott
Created December 22, 2017 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmott/47c0856be2bfaab970bc3780ddb27ee3 to your computer and use it in GitHub Desktop.
Save jackmott/47c0856be2bfaab970bc3780ddb27ee3 to your computer and use it in GitHub Desktop.
monogame problem
public static void Draw(GameTime gameTime)
{
var effect = DDGame.contentManager.Load<Effect>("road");
effect.Parameters["TerrainTexture"].SetValue(MainState.level.tex);
effect.Parameters["MaskTexture"].SetValue(MainState.maskTex);
DDGame.batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, effect);
DDGame.batch.Draw(MainState.roadTex, new Rectangle(0, 0, Settings.WINDOW_WIDTH, Settings.WINDOW_HEIGHT), Color.White);
DDGame.batch.End();
}
//*** and the shader for road //
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
Texture2D RoadTexture;
sampler2D RoadTextureSampler = sampler_state
{
Texture = <RoadTexture>;
};
Texture2D TerrainTexture;
sampler2D TerrainTextureSampler = sampler_state
{
Texture = <TerrainTexture>;
};
Texture2D MaskTexture;
sampler2D MaskTextureSampler = sampler_state
{
Texture = <MaskTexture>;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
float4 MainPS(VertexShaderOutput input) : COLOR
{
float4 maskColor = tex2D(MaskTextureSampler,input.TextureCoordinates);
if (maskColor.r == 1.0) {
return tex2D(RoadTextureSampler, input.TextureCoordinates);
}
else {
return tex2D(TerrainTextureSampler, input.TextureCoordinates);
}
}
technique SpriteDrawing
{
pass P0
{
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment