c# - Is there a state that needs to be reset in between shaders -


i starting out shaders using xna , ran behavoir didn't understand immediately.

i created simple scene textured box , ground sit on, composed of single textured quad using repeating texture (so texture coordinates 0,0 10,10 make repeat 10 times). both of these used basiceffect class.

i followed tutorial create first shader , used cube - nothing more shader returns color of texture @ coordinate coordinate, giving me same textured cube had before.

however strange happened - ground solid color 2 blurry edges , 1 instance of proper texture in corner. texture no longer repeating. changed order in drew cube , ground no effect, commenting out cube solved things.

then looked in shader code, copied tutorial, , saw specified clamp addressu , addressv. changing wrap fixed everything, still leaves me question - why texture wrapping logic of 1 shader affecting basic shader? normal behavoir, there kind of state saving need do, or indicate might have bug in code?

groundeffect.view = camera1.view; // basiceffect groundeffect.projection = projection; groundeffect.world = matrix.createtranslation(0, -1.5f, 0); groundeffect.textureenabled = true; groundeffect.texture = groundtexture; graphicsdevice.indices = groundindexbuffer; graphicsdevice.setvertexbuffer(groundvertexbuffer); foreach (effectpass pass in groundeffect.currenttechnique.passes) {     pass.apply();     graphicsdevice.drawindexedprimitives(primitivetype.trianglelist, 0, 0, groundvertexbuffer.vertexcount, 0, groundindexbuffer.indexcount / 3);  }   shadereffect.parameters["view"].setvalue(camera1.view); shadereffect.parameters["projection"].setvalue(projection); shadereffect.parameters["world"].setvalue(modelposition); shadereffect.parameters["modeltexture"].setvalue(boxtexture); graphicsdevice.indices = model.indexbuffer; graphicsdevice.setvertexbuffer(model.vertexbuffer); foreach (effectpass pass in shadereffect.currenttechnique.passes) {     pass.apply();     graphicsdevice.drawindexedprimitives(primitivetype.trianglelist, 0, 0, model.vertexbuffer.vertexcount, 0, model.indexbuffer.indexcount / 3);     } 

the render state controlled 4 state objects:

graphicsdevice.blendstate graphicsdevice.depthstencilstate graphicsdevice.rasterizerstate graphicsdevice.samplerstates[] // 1 each sampler 

their introduction in xna 4 explained in this blog post.

all state changes go through these variables or can set in .fx file.

iirc, xna's built-in effect objects don't set state using either method - although spritebatch does.

i can't sure setting state in case, code you've provided. guess spritebatch culprit (see blog post) - comes lot. maybe it's in shadereffect.

in case, it's reasonable set states want before rendering. here's typical states 3d rendering:

graphicsdevice.blendstate = blendstate.opaque; graphicsdevice.depthstencilstate = depthstencilstate.default; graphicsdevice.rasterizerstate = rasterizerstate.cullcounterclockwise; graphicsdevice.samplerstates[0] = samplerstate.linearwrap; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -