1
\$\begingroup\$

Sure there's something I'm missing about wrap/repeat textures in D3D 9. I've tried setting the sampler in the shader, i.e. :

sampler DiffuseSampler = 
sampler_state
{    
    Texture = <DiffuseMap>;

    MipFilter = NONE;
    MinFilter = POINT;
    MagFilter = POINT;

    AddressU = WRAP;    // Repeat on X
    AddressV = WRAP;    // Repeat on Y.
};

, and I've also tried doing it in code before I render the object:

device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

I thought there might be something screwy with my texture coordinates too, so I hard coded them to be 0.0, 0.0 on the left and 2.0, 2.0 bottom right. I expected x 2 repeat but got a similar result to the screenshot, with the texture top left and then what looks like clamp across the rest of the image.

What mistake have I made here? (Note that the screenshot isn't the 0.0, 0.0 -> 2.0, 2.0 experiment I did, it's the general case I get as I'm panning my image around).

Here's a screenshot of the resulting image (it's just a checker texture)

\$\endgroup\$
5
  • \$\begingroup\$ You are setting a sampler for the vertex shader in the second piece of code is this what you want? \$\endgroup\$ Feb 18, 2014 at 17:26
  • \$\begingroup\$ In the vertex shader? No, the only place the sampler is used is in the pixel shader. I think I see what you're getting at here... that's for vertex texture fetch isn't it. Hmmmm... \$\endgroup\$
    – Robinson
    Feb 18, 2014 at 17:31
  • \$\begingroup\$ D3DVERTEXTEXTURESAMPLER0 is indicating you are setting it to the first sampler slot of the vertex shader state. \$\endgroup\$ Feb 18, 2014 at 17:32
  • \$\begingroup\$ OK, not sure whether to delete this question as unbelievably stupid or ask you to add that as the answer so I can give it a cookie. It now works as I changed it to 0. I need to pay attention to what I copy and paste from the internet :p. Thanks János \$\endgroup\$
    – Robinson
    Feb 18, 2014 at 17:35
  • \$\begingroup\$ No problem I think this question can stay on the site, I am gonna answer it. :) \$\endgroup\$ Feb 18, 2014 at 17:38

1 Answer 1

1
\$\begingroup\$

The problem here is that you are setting a sampler for the vertex shader stage (D3DVERTEXTEXTURESAMPLER0 means the first slot) but you want to use it in your pixel shader. You should change it to null.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .