textures and ligths: HELP ME!!!!

Started by
5 comments, last by Big_T 18 years, 8 months ago
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?
Baffo"role-game needs a table"
Advertisement
Have you made sure that the vertices you are using for your tiles have normals?

Can you post some code.

ace
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.
hello Ace and Armadon, help me again...please

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)
Baffo"role-game needs a table"
Hi there Baf,
How are you doing?

[The Problem]
Computing normals for your tiles?

[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.
Thank you Armadon!!! now i can see my terrain,

it looks sharp but it's my first creation

how can i learn more about terrains?





Baffo"role-game needs a table"
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.

This topic is closed to new replies.

Advertisement