Sign in to follow this  
chronon

Spotlight + Low vertice Mesh + Fixed function

Recommended Posts

chronon    122
Hi all, I'm trying to learn Direct3D 9, so I'm building a very simple room with some lights, 3d models and some other stuff. I have a spotlight set to a corner of the room. My room have only 10 faces, the very basic room. When I enable the spotlight the corner is not lit the way I wanted. I believe that happens because my room don't many faces. Is there a way to make the spotlight do it work without adding faces to my room? TIA, chronon

Share this post


Link to post
Share on other sites
Moe    1256
Not really. You have a couple of options:

1) Tesselate the faces of the room. Add a bunch more polygons.
2) Use lightmapping.
3) Use some sort of per-pixel lighting (shaders)
4) Attempt to do per-pixel lighting in the Fixed Function Pipeline. If I remember correctly, it is possible to do dot3 bump mapping or something similar in the fixed function pipeline.

If you are looking for the easiest solution, just add more faces.

Share this post


Link to post
Share on other sites
chronon    122
I see, well...let's add more faces then! Thank you Moe!

EDIT: Is there a way to make directx break my mesh (each Wall of the room) in more faces?

Share this post


Link to post
Share on other sites
Moe    1256
It's probably easier to add more faces using whatever modelling program you are using to make the mesh in the first place. There is something called n-patches, but I haven't seen them used very much, and they might be a bit complicated for what you are doing right now.

Share this post


Link to post
Share on other sites
chronon    122
I'm creating the mesh myself by programming. I tried to use Progressive Mesh, but all it do is to reduce the number of faces, there is an option to increase the number of faces, but it's not working

Quote:
DWORD pAdjacency[3*128]={0};
pWorldMeshTemp->GenerateAdjacency(0.0f, pAdjacency);
V_RETURN( D3DXCleanMesh(D3DXCLEAN_OPTIMIZATION, pWorldMeshTemp, pAdjacency, &m_Mesh, (DWORD*) pAdjacency, NULL) );
V_RETURN( D3DXValidMesh(m_Mesh, pAdjacency, NULL) );
V_RETURN( D3DXGeneratePMesh(m_Mesh, pAdjacency, NULL, NULL, 512, D3DXMESHSIMP_VERTEX, &m_ProgMesh) );

m_ProgMesh->TrimByVertices(512, 1024, NULL, NULL);
m_ProgMesh->SetNumVertices(512);


btw, the mesh I'm talking about is the room!

Share this post


Link to post
Share on other sites
jollyjeffers    1570
You might be able to use D3DXCreatePatchMesh() followed by D3DXTesselateTriPatch() (or similar). Hardware accelerated HOS is reasonably rare now (although might reappear with D3D10 GPU's courtesy of the GS) but the D3DX functions allow you to generate HOS models and then convert them to regular triangular meshes. Getting the results you want might be tricky but it should be possible.

Alternatively, if you simply want higher vertex density you can write your own sub-division algorithm with little difficulty. Just step through each triangle and break it into three:

for( each triangle in mesh_input )
{
mid_point = (tri_vert_0 + tri_vert_1 + tri_vert_2) / 3
mesh_output.add( tri_vert_0, tri_vert_1, mid_point )
mesh_output.add( tri_vert_1, tri_vert_2, mid_point )
mesh_output.add( tri_vert_2, tri_vert_0, mid_point )
}


The above pseudo-code might give you the idea - take the midpoint of each triangle (just average the 3 coordinates) and you can then generate 3 more triangles. Keep applying this to your mesh until you have the density you desire...

Although I'd still go with using a per-pixel PS to do the job - for the most part it'll be the better approach.

hth
Jack

Share this post


Link to post
Share on other sites
chronon    122
Thank you jollyjeffers! Don't want to start with PS yet, I just changed the algorithm that made the walls of the room to get more faces.

Thank you both for the help.

Share this post


Link to post
Share on other sites
chronon    122
Now I'm having a really weird problem, look the image

Free Image Hosting at www.ImageShack.us

I think you noticed that the left wall is not lit at all. This also happen to the adjacent wall in the most left the wall that is not lit.

All walls are build in the same way (objects of CWall class).

What could be wrong here?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this