c# - SharpDX Pixel shaders need different parameters for different SpriteBatches vs DrawQuad. Fixable? -


i'm new building graphics engines , kinda stumped on particular issue.

i have issue getting pixel shaders work using same set of parameters both. causing me have create 2 different techniques each method. if try use same parameters both, 1 of them return nothing.

my goal use 1 set of parameters shader, eliminating sprite specific version of each technique use.

here have do:

hlsl pixel shader

texture2d texture : register(t0); samplerstate texturesampler : register(s0); texture2d texturealpha;  cbuffer projectionmatrix : register(b0) {     row_major float4x4 matrixtransform : packoffset(c0); };  void vs(     inout float4 color    : color0,     inout float2 texcoord : texcoord0,     inout float4 position : sv_position) {     position = mul(position, matrixtransform); }  //method required using drawquad float4 ps(     float2 tex : texcoord0     ) : sv_target {     float3 tcolor = texture.sample(texturesampler, tex).rgb * texturealpha.sample(texturesampler, tex).a;     float alpha = texturealpha.sample(texturesampler, tex).a * texture.sample(texturesampler, tex);      return float4(tcolor, alpha); }  //method required using in spritebatches float4 pssprite(     float4 color    : color0,     float2 tex : texcoord0     ) : sv_target {     return ps(tex); }  technique masksprite {     pass     {         profile = 9.3;         //sprite's require vs set well.         vertexshader = compile vs_4_0_level_9_1 vs();         pixelshader = compile ps_4_0_level_9_1 pssprite();     } }  technique mask {     pass     {         profile = 9.3;         pixelshader = compile ps_4_0_level_9_1 ps();     } } 

loadcontent() code

protected override void loadcontent() {     //...        //render target mask     var backdesc = graphicsdevice.backbuffer.description;     rendertargetmask = todisposecontent(rendertarget2d.new(graphicsdevice, backdesc.width, backdesc.height, 1, backdesc.format));      //sprite batch initialization     spritebatch = todisposecontent(new spritebatch(graphicsdevice));      //load in fx , textures      ballstexture = content.load<texture2d>("balls");     alphamaptexture= content.load<texture2d>("alphamap");     maskeffect = content.load<effect>("mask");      //... } 

spritebatch code

protected override void draw(gametime gametime) {     //...     maskeffect.currenttechnique = bloomeffect.techniques["masksprite"];     maskeffect.parameters["destination"].setresource(alphamaptexture); //texture2d      spritebatch.begin(                     spritesortmode.deferred,                      graphicsdevice.blendstates.nonpremultiplied,                      null, null, null, maskeffect);      spritebatch.draw(                     ballstexture, //texture2d                     new vector2(10, 10),                     new rectangle(0, 0, ballsdesttexture.width, ballsdesttexture.height),                     color.white,                     0.0f,                     new vector2(0, 0),                     vector2.one,                     spriteeffects.none,                     0f);      spritebatch.end();     //... } 

draw quad code

protected override void draw(gametime gametime) {     //draw stuff rendertargetmask      //...     maskeffect.currenttechnique = maskeffect.techniques["mask"];     maskeffect.parameters["texture"].setresource(rendertargetmask);     maskeffect.parameters["texturealpha"].setresource(ballsdesttexture);     maskeffect.parameters["texturesampler"]             .setresource(graphicsdevice.samplerstates.pointclamp);     var pquad = new primitivequad(graphicsdevice);     pquad.draw(maskeffect.currenttechnique.passes[0]);     //... } 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -