DX8 - Texel to pixel mapping

Started by
1 comment, last by CrazyCdn 6 years, 3 months ago

Blast from the past: While checking my different renderers I've come upon a problem in a Direct3d8 renderer, which I'm pretty sure worked fine already a while ago.

Basically I'm drawing a 2d quad with pretransformed vertices, but the first triangle's texture coordinates seem off. I'm offsetting the coordinates by -0.5,-0.5 as per spec and there's not much more to it. The same part with D3D11 using shaders works fine (well, duh). Anyhow, I'm still curious, as the DX8 renderer is still my final fallback and it currently is supported quite well.

Anybody see any glaring mistake?

The code in question is this, the texture is a 16x16 pixel sized cut out from a 256x256 texture, these values are used. FWIW I'm running on Windows 10 with some AMD Radeon 5450.

 

iX = 22
iY = 222
Texture rect from the full texture are is (144,0 with 16x16 size)
The drawn box is drawn scaled up to a size of 40x40 pixels
m_DirectTexelMapping.offset is a 2d vector with values -0.5, -0.5

I've set min-, mag- and mip-mapping filter to nearest.


struct CUSTOMVERTEX
{
  D3DXVECTOR3   position; // The position
  float         fRHW;
  D3DCOLOR      color;    // The color
  float         fTU,
                fTV;
  };	  
  
  CUSTOMVERTEX          vertData[4];	  
  
  float   fRHW = 1.0f;	  
  GR::tVector   ptPos( (float)iX, (float)iY, fZ );
  GR::tVector   ptSize( (float)iWidth, (float)iHeight, 0.0f );	  
  
  m_pd3dDevice->SetVertexShader( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 );	  
  
  vertData[0].position.x  = ptPos.x + m_DirectTexelMappingOffset.x;
  vertData[0].position.y  = ptPos.y + m_DirectTexelMappingOffset.y;
  vertData[0].position.z  = (float)ptPos.z;
  vertData[0].fRHW        = fRHW;
  vertData[0].color       = dwColor1;
  vertData[0].fTU         = fTU1;
  vertData[0].fTV         = fTV1;	  
  
  vertData[1].position.x  = ptPos.x + ptSize.x + m_DirectTexelMappingOffset.x;
  vertData[1].position.y  = ptPos.y            + m_DirectTexelMappingOffset.y;
  vertData[1].position.z  = (float)ptPos.z;
  vertData[1].fRHW        = fRHW;
  vertData[1].color       = dwColor2;
  vertData[1].fTU         = fTU2;
  vertData[1].fTV         = fTV2;	  
  
  vertData[2].position.x  = ptPos.x            + m_DirectTexelMappingOffset.x;
  vertData[2].position.y  = ptPos.y + ptSize.y + m_DirectTexelMappingOffset.y;
  vertData[2].position.z  = (float)ptPos.z;
  vertData[2].fRHW        = fRHW;
  vertData[2].color       = dwColor3;
  vertData[2].fTU         = fTU3;
  vertData[2].fTV         = fTV3;	  
  
  vertData[3].position.x  = ptPos.x + ptSize.x + m_DirectTexelMappingOffset.x;
  vertData[3].position.y  = ptPos.y + ptSize.y + m_DirectTexelMappingOffset.y;
  vertData[3].position.z  = (float)ptPos.z;
  vertData[3].fRHW        = fRHW;
  vertData[3].color       = dwColor4;
  vertData[3].fTU         = fTU4;
  vertData[3].fTV         = fTV4;	  
  
  m_pd3dDevice->DrawPrimitiveUP(
                  D3DPT_TRIANGLESTRIP,
                  2,
                  &vertData,
                  sizeof( vertData[0] ) );
	

 

God, I hate this borked message editor, it's so not user friendly. This POS message editor really loves to f*ck up code formatting.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Advertisement

D3D9 was released Jan, 2003... I don't see anything standing out to me in your code snippet mind you.  But honestly you need to drop support for this, it's not worth the time of day to maintain.  If you release anything to the public you will have a maintenance nightmare on your hands.  Mostly in the form of infected out of date OS support calls/complaints.  And if you claim to support their OS they will ridicule your software on public forums and leaving negative reviews.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement