Jump to content
  • Advertisement
Sign in to follow this  
freka586

Simple (?) texturing/shading problem

This topic is 5046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having some odd problems with using textures and HLSL shading. This is what I am currently doing: effect.SetValue("tex1",texture1); effect.SetValue("tex2",texture2); effect.Begin(0); effect.BeginPass(0); theQuad.Render(); effect.EndPass(); effect.End(); theQuad is a textured quad. Its render method does: device.SetTexture(0, texture); device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, vertices, 0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); device.SetTexture(0, null); Inside the shader I am doing some texture lookups. The problem is that for some reason the SetTexture call overwrites the texture pointer inside the shader. If I lookup stuff in tex2 in the shader values are not those I expect. So, how should this be done properly? I really like to keep theQuad unaffected, as I sometimes render it without using shaders.

Share this post


Link to post
Share on other sites
Advertisement
For vertex texturing (which I assume you are doing) you need to use the D3DVERTEXTEXTURESAMPLER0 sampler stage, replacing 0 with the vertex texture stage (0-4).

Share this post


Link to post
Share on other sites
Alternative, simply DO NOT set the texture in one overload of the quad draw. I had a similar situation. So I just made two overloads of Quad.Draw -- one takes a texture as an input and the other doesn't. If I'm using an effect on the quad then I set the textures explicitly with the FX interface (like you did with effect.SetValue()) -- otherwise, if I'm using the fixed pipeline then I use the other overload which take a texture and then it uses SetTexture. Works well for me and it's fairly simple to implement.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!