3D DX8 - Texel to pixel mapping

Recommended Posts

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.

Share on other sites

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.

Create an account

Register a new account

• 23
• 10
• 19
• 15
• 14
• Similar Content

• Hi guys!
This is a independent game being produced by me and my brother. We’ve been working on it for about 6 months and we’ve already done a good part of the game. We hope to finalize and make it available on Steam by the end of this year.
We are using Blender 3D and Gimp software for production.

About the Game: Dongo Adventure will be a 3D platform style game, where the main character (Dongo) is a mouse that ventures through various scenarios (sewers, culverts, streets, electric grid, etc.) and faces several enemies along the way (cockroaches, mosquitoes, spiders, toxic gases, electrical wires, etc.). He carries a basket / backpack with cheeses that he uses to throw and defend himself from enemies, as well as being able to push objects that helps him to overcome obstacles. The ultimate goal will be a surprise!
The game follows the style of classic platform games, bringing many surprises and challenges.

Now we are developing new scenarios and enemies. We hope to publish news soon...
Game page on Steam: http://store.steampowered.com/app/811450/Dongo_Adventure/ - (Teaser UPDATED)
Dongo Adventure (Indie Game Project) – First Gameplay Teaser + Making Of: https://www.youtube.com/watch?v=X2nmxtkE0xk
Dongo Adventure (Indie Game Project) – First Gameplay Teaser (UPDATED) + Making Of: https://vimeo.com/250501345

Thanks for following the project!

• By Mailbox
Hello,
I'm in the midst of developing a simple 3d physics engine, but have been stuck on a problem for quite a while now. I would really appreciate it if someone could have a look at it, because I'm at a loss.
The issue I'm having concerns the collision response code, which seems to fail spectacularly in some cases, generating wrong impulse magnitudes. Specifically, something with the angular part of it is wrong, since it works as expected when only dealing with the linear part.
I'm still not sure if I calculate the inertia tensor in world coordinates the right way, so that could be one possible culprit (though I've tried a few different ways). Impulses seem to be applied correctly to the bodies, so I think the error lies in the calculation of the impulse magnitude denominator.
I've checked it many times with the way the Bullet physics engine does it, with the formulas available at Wikipedia, and some other sources, to no avail.
The bodies simply keep bouncing off eachother (even though there is supposed to be no restitution) or spinning wildly on collisions.
Here is the code that deals with the collision response:
Vector3 originA = contactOrigin - bodyA.Position; Vector3 originB = contactOrigin - bodyB.Position; Vector3 velocityA = bodyA.Velocity + Vector3::Cross(bodyA.AngularVelocity, originA); Vector3 velocityB = bodyB.Velocity + Vector3::Cross(bodyB.AngularVelocity, originB); Vector3 velocity = velocityA - velocityB; Matrix3x3 inverseWorldInertiaTensorA = Matrix3x3::Scale(bodyA.InverseInertia) * Matrix3x3::Rotate(bodyA.Orientation); Matrix3x3 inverseWorldInertiaTensorB = Matrix3x3::Scale(bodyB.InverseInertia) * Matrix3x3::Rotate(bodyB.Orientation); float normalVelocity = Vector3::Dot(velocity, contactNormal); if (normalVelocity > 0.f) { float impulseDenominator = bodyA.InverseMass + bodyB.InverseMass + Vector3::Dot(Vector3::Cross(inverseWorldInertiaTensorA * Vector3::Cross(originA, contactNormal), originA), contactNormal) + Vector3::Dot(Vector3::Cross(inverseWorldInertiaTensorB * Vector3::Cross(originB, contactNormal), originB), contactNormal); float j = -normalVelocity / impulseDenominator; bodyA.Velocity += j * bodyA.InverseMass * contactNormal; bodyB.Velocity -= j * bodyB.InverseMass * contactNormal; bodyA.AngularVelocity += j * (inverseWorldInertiaTensorA * Vector3::Cross(originA, contactNormal)); bodyB.AngularVelocity -= j * (inverseWorldInertiaTensorB * Vector3::Cross(originB, contactNormal)); } Thanks in advance!

• Hi again,  After some looking around I have decided to base my game directly on Direct X rather than using an existing game engine.  Because of the nature of the stuff I'm doing it just didn't seem to fit very well and I kept running into road blocks.  At this point I have a big blob of code for doing fractal world generation and some collision code,  and I'm trying to put it into some form that resembles a game engine.  Since I've never used one before It's a bit alien to me ..... so can someone direct me to a book, website, article, whatever... that covers this?  I'm mainly looking for stuff that covers C++ library design. I'm not adverse to using 3rd party tools for stuff I can used them for.
• By mmmax3d
Hi everyone,
I would need some assistance from anyone who has a similar experience
or a nice idea!
I have created a skybox (as cube) and now I need to add a floor/ground.
The skybox is created from cubemap and initially it was infinite.
Now it is finite with a specific size. The floor is a quad in the middle
of the skybox, like a horizon.
I have two problems:
When moving the skybox upwards or downwards, I need to
sample from points even above the horizon while sampling
from the botton at the same time.  I am trying to create a seamless blending of the texture
at the points of the horizon, when the quad is connected
to the skybox. However, I get skew effects. Does anybody has done sth similar?
Is there any good practice?
Thanks everyone!