# Spotlight + Low vertice Mesh + Fixed function

This topic is 4241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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 on other sites
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 on other sites
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 on other sites
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 on other sites
Now I'm having a really weird problem, look the image

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 on other sites
never mind, the faces that were towards the inside of the room were the backfaces, a rotation of those two walls solved the problem

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631790
• Total Posts
3002365
×