# textures and ligths: HELP ME!!!!

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

## Recommended Posts

i'm new, i don't know how to use textures and lights at the same time. I created 3d textured tiles and one directional light but it hits only my loaded meshes, why?

##### Share on other sites
Have you made sure that the vertices you are using for your tiles have normals?

Can you post some code.

ace

##### Share on other sites
Hi there Baf,
How are you doing?
[The problem]
You light only hits the loaded meshes. 2 things might be happening here.

[The possible solutions]
When working with light you have 2 very important components to note.

1) The normals
2) The material associated with the object (Tells direct3d how you want the light to behave when it hits the material associated with the object
Material:
"A property that determines how a surface reflects light. A material has emissive, diffuse, ambient, and specular properties. The emissive property describes the color of light that a material emits. The diffuse, ambient, and specular properties describe the behavior of reflected light. The sharpness of specular highlights is determined by a power setting. "

Make sure you have a material associated and the normals of the tiles are set.

I hope this helps.
Take care.

##### Share on other sites

I tried with normals and light now hits tiles!! thank you

but isn't a good scene on the screen. it looks vary bad
my tiles are square and drawn in trianglestrip, i don't know how to compute normals,
i have 4 vertex: clockwise 0,1,3,2

i created this function but don't works i think..

the function is for vertex 0(input vertex 0,1,2) e 3 (input vertex 1,2,3)
D3DXVECTOR3 tile::normal( customvertex v1, customvertex v2, customvertex v3){
D3DXVECTOR3 v;
v.x=(v2.y-v1.x)*(v3.z-v1.z)*(v1.y-v3.y)*(v1.z-v2.z);
v.y=(v2.z-v1.z)*(v3.x-v1.x)*(v1.z-v3.z)*(v1.x-v2.x);
v.z=(v2.x-v1.x)*(v3.y-v1.y)*(v1.x-v3.x)*(v1.y-v2.y);
return v;
}
and for vertex 1 e 2 i tried
float k=0.5 ;
D3DXVec3Lerp(&v,&v1,&v2,k);
i have no more ideas!!!! my light is directional (1,0,0)

##### Share on other sites
Hi there Baf,
How are you doing?

[The Problem]

[The Solution]
Direct3D comes to the rescue once again.
It supplies us with a cool little equation in the mesh class called Compute Normals.

D3DXComputeNormals:
Computes unit normals for each vertex in a mesh. Provided to support legacy applications. Use D3DXComputeTangentFrameEx for better results.

So what you can do is send your index buffer and vertex buffer to a newly created mesh.

e.g.
ID3DXMesh* mesh;D3DXCreateMesh(numFaces, numVertices, D3DXMESH_MANAGED, D3DFVF_POSITION | D3DFVF | D3DFVF_NORMAL | D3DFVF_TEX0, device, &mesh);//Lock the vertex buffer and index buffer and feed it your values.//after that compute the normals of the meshD3DXComputeNormals(mesh, NULL);

I hope this helps a bit.
Keep cool.

##### Share on other sites
Thank you Armadon!!! now i can see my terrain,

it looks sharp but it's my first creation

##### Share on other sites
There's a wonderful book I read called focus on terrain programming - or something like that. I have forgotten the authors name, but its a small, to the point book that taught me wonders.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634135
• Total Posts
3015754
×