2017-05-29 7 views
0

MonogameでPixelShaderを実装しようとしています。MonoGame 2D PixelShaderが機能しない

シェーダ(今のところ)は、テクスチャを取り、それを操作しないで戻す必要があります。

sampler MyTex : register(s0); 

float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0 
{ 
    float4 Color = tex2D(MyTex, coords); 
    return Color; 
} 

technique tech 
{ 
    pass Pass1 
    { 
     PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction(); 
    } 
} 

私Monogame実装次のようになります。LoadContentで

spriteBatch = new SpriteBatch(GraphicsDevice); 
texture = Content.Load<Texture2D>("surge"); 
GraphicsDevice.Textures[0] = texture; 
effect = Content.Load<Effect>("sha"); 

とドロー法で:

GraphicsDevice.Clear(Color.Aquamarine); 

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,null, null, null, effect, null); 
spriteBatch.Draw(texture, new Vector2(150, 150), Color.White); 
spriteBatch.End(); 

しかし、それは何も表示されません。 BlendStateをOpaqueに変更すると、テクスチャがあるはずの黒い矩形が表示されます。私はまた、他のSortmodeとBlendStatesを成功せずに変更しようとしました。私は問題を見つけることができないようです。 問題を解決するのに役立つすべての回答、または私がこれを理由に自己憎しみを減らしていることは非常に高く評価されています。

EDIT:リソースバインディング(登録)がシェイダーモデルのバージョン全体で変更された問題はありますか。 誰か助けてください!

答えて

0

こんにちはステファンiはグレースケール効果のために、このコードを試してみました

texture Texture; 
sampler TextureSampler = sampler_state 
{ 
    Texture = <Texture>; 
}; 

//このデータは、スプライトバッチ頂点シェーダから来

struct VertexShaderOutput 
{ 
    float4 Position : TEXCOORD0; 
    float4 Color : COLOR0; 
    float2 TextureCordinate : TEXCOORD0; 
}; 

//私たちのピクセルシェーダ

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 
{ 
    float4 color = tex2D(TextureSampler, input.TextureCordinate); 

    float value = 0.299*color.r + 0.587*color.g + 0.114*color.b; 
    color.r = value; 
    color.g = value; 
    color.b = value; 
    color.a = 1.0f; 

    return color; 
} 

//シェーダをコンパイル

technique Technique1 
{ 
    pass Pass1 
    { 
    PixelShader = compile ps_2_0 PixelShaderFunction(); 
    } 
} 

か、あなたの答えのために、このlinkthis

+0

感謝を試みるかもしれませんが、そのshaderfileと私もコンパイルすることはできません。 MSBuild \ MonoGame \ v3.0 \ MonoGame.Content.Builder.targets(90,5):エラーMSB3073:[..]コード1で終了しました – Steffen

関連する問題