BUG?? Problem with shaders: crappy Binormal and Tangent

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

BUG?? Problem with shaders: crappy Binormal and Tangent

Post by genesys »

Hi!

I've got a problem and i think it may be a bug in irrlicht!


I'm writing HLSL shaders and now i use the BINORMAL and TANGENT Input semantics from the vertex streams for one of my shaders...

the vertex streams i used before (NORMAL, POSITION, COLOR and TEXCOORD) work fine... but BINORMAL and TANGENT don't!

Irrlicht gives them completly messy to the shaders! I don't think it's a problem of my mesh - because in RenderMonkey it's working fine!


Has anyone an idea how to fix that?
thx!
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

hmmmmm.... i think that irrlichts stream mapping doesn't even pass the binormal and tangent streams to the shaders - could that be true??
Guest

Post by Guest »

if you use S3DVertexTangents there shouldn't be any problem.
Maybe the tangent and binormal are passed as fake texcoords take a look at the source.
gozargozarian

Post by gozargozarian »

I had this same problem. Converting the mesh to one with computed vertex normals, such as the process used in the per pixel lighting demo, will help to fix 90% of it. It still seems like they are not the exact numbers they should be, but maybe it's just me.
gozargozarian

Post by gozargozarian »

I found something strange trying to figure out how irrlicht uses the pixel shader information. In the file CD3D9Driver.cpp inside of the function "void CD3D9Driver::setVertexShader(E_VERTEX_TYPE newType)" there are two lines in the "case EVT_TANGENTS:" statement. The exact wording is:

D3DFVF_TEXCOORDSIZE2(0) | // real texture coord
D3DFVF_TEXCOORDSIZE3(1) | // misuse texture coord 2 for tangent
D3DFVF_TEXCOORDSIZE3(2) // misuse texture coord 3 for binormal

Now I'm not exactly sure what Irrlicht is doing at this point in the code since this is the advanced stuff we use the engine to avoid, but the comments for it disturb me. Can anyone explain if this might be a problem or if it is something that should be fixed?
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

It's standard practice. The easiest way to get per-vertex varying parameters to a shader is stuff them in the texture coords, since there are usually more texture coords available than are actually needed for textures
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

yes thank you!
i found the Tangents in TEXCOORD1 . . . but in TEXCOORD2 there are the tangents as well and not the binormals!
gozargozarian

Post by gozargozarian »

Found this too looking through some code. In CMeshManipulator.cpp I found in the function "void CMeshManipulator::recalculateNormals(IMeshBuffer* buffer) const" this comment:

case video::EVT_TANGENTS:
{
// TODO: recalculate tangent and binormal
}

I guess my question that I have is, does Irrlicht actual do any real computation for the binormals and tangents? Because some of the functions seem to be missing the important stuff.
gozargozarian

Post by gozargozarian »

And besides the above, I have found out that binormals and tangents are indeed computed, but strangely they are stored in TEXCOORD2 and TEXCOORD3. These are what you would use instead of the standardized BINORMAL and TANGENT. Why are they not stored in the standard BINORMAL and TANGENT slots for HLSL? If we ever needed more that 2 textures this would become a problem wouldn't it?
Guest

Post by Guest »

using more than 2 textures wouldn't cause problems - but using more than 2 texture coordinates stored in the mesh!

It's really bothering me!
dorvo
Posts: 2
Joined: Thu Dec 09, 2004 7:56 pm

Post by dorvo »

So why not change it to work the way it's supposed to? You are given the source code, after all.
gozargozarian

Post by gozargozarian »

I've searched through the source code, but I can't find the exact place where the code is placing these in TEXCOORD2 and TEXCOORD3 instead of BINORMAL and TANGENT settings. I would assume that it is in the driver files, but nothing comes up with a search through the files. Does anyone know where the code is at? If I knew where the error was I would fix it myself, get it working, and post the fixed code.
Post Reply