Cant get Multiple BasicEffects to work

Been stuck on this challange for a while.
Im trying to change effect or texture on a Quad(2 tiangles) at runtime.
My Quad class containg the VertexPositionNormalTexture information to draw the quad.
This works as intended, and texture/light/ambient are all ok.
The Quad also containg information about what Texture or effect should be used

I’ve tried a couple of different ways to solve this. Is there a perticular order to do this.

Psudo code:
BE1 = BasicEffect // Stone texture
BE2 = BasicEffect // Wood texture
TestEff = BasicEffect // This will be Equal to BE1 or BE2 at runtime

For each Quad
If Quad.Region = 1 then
TestEff = BE1
TestEff = BE2
End IF

Dim VPNT(5) As VertexPositionNormalTexture (Gets information from quad and creates both triangles)

                For Each Eff As EffectPass In TestEff.CurrentTechnique.Passes
                    TestEff.World = Camera.World
                    TestEff.View = Camera.View
                    TestEff.Projection = Camera.Projection
                GraphicsDevice.DrawUserPrimitives(Of VertexPositionNormalTexture)(PrimitiveType.TriangleList, VPNT, 0, 2)


When I try this, its only using the last Effect used, on all faces. Also tried to set TestEff.Texture = another texture, same result.
I guess one or both approches should be possible, but need some other command/code here as well.

The last Project I did in MG had all Components in different class instances, With their own Draw metode. That worked as it was intended.

Some guidence would be very helpful :slight_smile:


For a technique with multiple passes, you should do the draw call very time after applying a pass. So for your code the draw call should be inside the for loop. That’s not really important here because BasicEffect techniques are all single-pass.

I don’t see anything else wrong with your code that would cause the error you’re describing. Did you verify that the texture of both effects is set up correctly?

Yes both textures and effects works correctly.
When I use one BE and changes the texture, it draws all Quads/triangles with the last texture used.
Same with two BE, it draws all Quads/triangles with the last used BE.

So if no one spots what I have missed, my next option is Shaders?
I was hoping to start that journy later.


Hmmm. It Works now
I dont know why :slight_smile:
Only added a couple of Debug.print lines to be sure I tested for the right values

Might have been the VS update last night, that needed a restart, or a hickup in my computer

Anyway, thanks for trying to solve it

1 Like