@Toemsel wrote:
For some reasons applying pixel shader does not work as excepted.
Shader.fx (Grayscale effect)
sampler TextureSampler : register(s0); float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0 { float4 c = 0; c = tex2D(TextureSampler, texCoord); c.a = clamp(c.a - 0.05, 0, 1); c.r = c.r * c.a; c.g = c.g * c.a; c.b = c.b * c.a; return c; } technique Technique1 { pass Pass1 { PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction(); } }
Draw call
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); Shader.CurrentTechnique.Passes[0].Apply(); spriteBatch.Draw(...); spriteBatch.End();
This shader with this draw call, will result in no output. (Transparent or not visible) However, many other .fx also did result in a disappearing texture. Even following code returns nothing:
float4 c = 0; c = tex2D(TextureSampler, texCoord); return c;
Am I missing something? Also, using spriteBatch.Begin(SpriteSortMode.Immediate...); kinda grinds my gear. If I interpret the doc correct, after every .draw(); the GPU will receive the texture and instantly draw it. Isn't that very unperformant? Can I use pixel/vertex shader and still draw in batches?
Thanks in advance
Edit:
return float4(1, 0, 0, 0);
works like a charm. (Each pixel same color)
Posts: 6
Participants: 2