Jump to content
  • Advertisement
Sign in to follow this  
webjeff

cube map problem

This topic is 4331 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 got a shader that works fine in fx composer, I can import my model and see the cube map on the model perfect. in my demo, I only seem to see the positiveY mip map of the cube map mapped onto the entire mesh, im using a shader for this, the same one that works fine in fx composer. Any ideas what could be wrong, I tried using D3DXCreateTextureFromFileEx & D3DXCreateCubeTextureFromFileEx. Both with similar results. I can't seem to figure out how in fx composer they're loading the texture. Has anyone experienced this before? or has a clue. I am also maybe thinking it has to do with the UV's that are on the model all being between 0-1. maybe thats why im getting the positiveY mip map, but then how does fx compser work? That doesnt seem right. Thanks for any help anyone can provide in advance. Jeff.

Share this post


Link to post
Share on other sites
Advertisement
did u set texturestage that about texture coord for cube-mapping?
like this,
IDirect3DDevice9::SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );

Share this post


Link to post
Share on other sites
I tried doing the setTextureStageState:
SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );

But it crashes. Any idea why that would crash it? Also, anything else I need to do for cube maps to work? I am creating a cubemap with D3DXCreateCubeTextureFromFileEx.

Top Image is from FX Composer.
Bottom Image is from my app.

You can see something is wrong, but I'm not sure what.

http://www.guerrillagames.net/jersey.jpg


Thanks
Jeff.

Share this post


Link to post
Share on other sites
Does the file you are using to to load the cube map texture from actually contain a cube map?

Try opening the file in the SDKs DirectX Texture Tool. Then from the menu select View->Cube Map Face, and select the face you wish to view.

Do all the faces show OK?

If the cube map face options are grayed out, then the file does not contain a cube map.

Also when you say the program crashes ... how or where does the program crash?

What does the debug output say?

EDIT: have you also checked that your card supports cube mapping?
From the DirectX Caps Viewer:
Texture Caps -> D3DPTEXTURECAPS_CUBEMAP = yes.

Another Edit:
Double check that you are calling SetTexture on the effect and setting all other parameters in your effect file required by your shader including the matrices.

Also I think:
SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR );

is only good when using the fixed function pipe line, but not needed when doing reflection mapping via a shader.

Any chance we could see your code where you set up the effect parameters, your rendering code and your .fx file?

HTH

[Edited by - Cambo_frog on July 12, 2006 11:00:55 AM]

Share this post


Link to post
Share on other sites
Thanks Cambo

I checked and the file does actually contain a cube map and they look ok, plus fx composer works fine with the file so I think the file is ok, same with the shader.

Here is the shader code:
www.guerrillagames.net/crome.txt (I renamed it cause it was blocking .fx files)

Here is a snippet of where I setup the shader:

///////////// SETTING UP ONCE /////////////////
D3DXHANDLE hTechnique = m_Effect->GetTechniqueByName( "BumpReflect0" );
m_Effect->SetTechnique( hTechnique );

D3DXCreateCubeTextureFromFileEx(m_RenderingDevice,"evironment.dds",0,0,0,D3DFMT_A8B8G8R8,D3DPOOL_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&m_EnvTexture);
D3DXCreateTextureFromFile(m_RenderingDevice,"bumpnormal.dds",&m_NormalTexture);



D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
D3DDECL_END()
};
m_RenderingDevice->CreateVertexDeclaration( decl, &m_VertexDecl);


///////////// PASSING PER FRAME /////////////////
D3DXHANDLE handle = NULL;

D3DXMATRIX VWPMatrix(m_Renderer->m_matWorld*m_Renderer->m_matView*m_Renderer->m_matProj);

D3DXMATRIX worldMatrix(&(m_Renderer->m_matWorld).m[0][0]);
D3DXMATRIX wvpMatrix(& (m_Renderer->m_matWorld*m_Renderer->m_matView*m_Renderer->m_matProj).m[0][0]);
D3DXMATRIX worldViewMatrix(& (m_Renderer->m_matWorld*m_Renderer->m_matView).m[0][0]);

D3DXMATRIX worldViewMatrixI;
D3DXMatrixTranspose(&worldViewMatrixI,&D3DXMATRIX(&(m_Renderer->m_matWorld*m_Renderer->m_matView).m[0][0]));

D3DXMATRIX viewInverseMatrix;
D3DXMatrixTranspose(&viewInverseMatrix,&D3DXMATRIX(&(m_Renderer->m_matView).m[0][0]));

D3DXMATRIX viewMatrix(&(m_Renderer->m_matView).m[0][0]);

handle = m_Effect->GetParameterByName(NULL, "worldMatrix");
m_Effect->SetMatrix(handle, &worldMatrix );
handle = m_Effect->GetParameterByName(NULL, "wvpMatrix");
m_Effect->SetMatrix(handle, &wvpMatrix );
handle = m_Effect->GetParameterByName(NULL, "worldViewMatrix");
m_Effect->SetMatrix(handle, &worldViewMatrix );
handle = m_Effect->GetParameterByName(NULL, "worldViewMatrixI");
m_Effect->SetMatrix(handle, &worldViewMatrixI );
handle = m_Effect->GetParameterByName(NULL, "viewInverseMatrix");
m_Effect->SetMatrix(handle, &viewInverseMatrix );
handle = m_Effect->GetParameterByName(NULL, "viewMatrix");
m_Effect->SetMatrix(handle, &viewMatrix );

handle = m_Effect->GetParameterByName(NULL, "cubeMap");
m_Effect->SetTexture("cubeMap",m_EnvTexture);

handle = m_Effect->GetParameterByName(NULL, "normalMap");
m_Effect->SetTexture("normalMap",m_NormalTexture);



m_RenderingDevice->SetVertexDeclaration(m_VertexDecl);




I checked and I am passing Verts/normals/uv/tangents/binormals and in that order in my Vertex Buffer. Next step for me is to make it so I can see those show up to verify those are correct. But before doing that, do you or anyone else see anything wrong with the code for setting up this effect?

Thanks
Jeff

Share this post


Link to post
Share on other sites
OK webjeff,
A few comments here, some related to your problem, some related to your code in general:


D3DXMATRIX worldMatrix(&(m_Renderer->m_matWorld).m[0][0]);





You seem to be creating worldMatrix via the D3DXMATRIX constuctor which takes a pointer to FLOAT (D3DXMATRIX( CONST FLOAT * ); )

or D3DXMATRIX( CONST D3DXFLOAT16 * );

I don't know what m_Renderer->m_matWorld is, but seeing you are using the "m" member, I guess m_Renderer->m_matworld is a D3DMATRIX, in which case you could use the D3DXMATRIX( CONST D3DMATRIX& ) constructor like this:

D3DXMATRIX worldMatrix( m_Renderer->m_matWorld );

There is lots of other stuff like that in your code, I need more info really :)

If you like, I could create a program using the SDK sample framework which renders a mesh using reflection mapping within a skybox.

The same environment map ( cube map texture) would be used for the skybox and the refection mapping on the mesh.

It would use shaders with the absolute minimum of code (plus comments) to show how it can be done.

The mesh vertices would contain position and normal data only initially, and the cube map texture coordinates would be calculated in the shader code.

Best to start really simple, get the basic reflection mapping going inititialy, then add your normal mapping etc.

Let me know if you would like the code and I will get to work on it. It is going to be easier this way than going through all your code and .fx file.

HTH

[Edited by - Cambo_frog on July 12, 2006 4:57:48 PM]

Share this post


Link to post
Share on other sites
cambo:

The matrix constructor you are showing is correct, I could have just passed it in, instead of address of the first value. However, I am not just working with a PC platform. I am also writing a renderer for a console. Which has a different Matrix variable which I can pass it in the same way... its just for consistancy so I can see similar code :) I can optimize/clean up later.

As for creating a basic reflection one, that would be great. I'd love to see that. I am still learning shaders, but I am getting it very fast.

The .fx file is one taken from a sample in fx composer. Thats the reason they also have a normal map in there.

You also said that for this you only need verts and normals. So Is the tangent and binormal calculated in the shader. I wonder why this one requires it to be sent in.

If you want to help me out, that would be great! I'm sure others would benefit too here, especially if they're learning shaders/effects.

Jeff.
PS
Tonight(hopefully) im going to try and get lines showing normals/tangents/binormals. So I can see if the problem lies with those calculations.

Share this post


Link to post
Share on other sites
OK,

I have it rendering the normals/tangents/binormals and they appear correct, as they form an axis per vertex.

So now I am thinking it might have to do how I am loading the cubemap, even though I am loading it through D3DXCreateCubeTextureFromFileEx.

Does anyone have any ideas on how I can make sure its loading the file properly, meaning the cube is setup? Also, the file itself is fine, I have verified that the cube map exists through DX Texture Util and it looks perfect in FX Composer. I think its how I'm loading it and using it that is wrong somewhere.

Let me know if anyone can think of anything that it might be. I'm sorda at a stand still tryin to figure this out.

Thanks again!
Jeff.

Share this post


Link to post
Share on other sites
Guys:

After much much more research.. (I can post new pictures if neccesary). I have figured out my cube map is showing the entire map with only 180degrees and not correctly showing only half the cube map, and half when it rotates the other 180degrees.

I basically have a square (two triangles) the normals/tangents/binormals look correct as I am comparing them with what they have in fx composer.. as far as directions go.

In FX Composer, from when you see the square rotate 180degrees you see half the cube map (like your suppose to) and when it rotates the other side you see the other side of the cube map, for a full rotation around the map.

But in my app, the entire map is shown on each 180degree rotation. Can someone point me in the right direction as to what controls that?? does that have to do with my world matrix or does it have to do with tangents/normals/binormals?

Any help would be greatly appreciated as I'm just shooting in the dark trying to see what may cause that effect.

Thanks again!
Jeff.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!