Sign in to follow this  
Ethangar

Confusion with HLSL and Textured Meshes

Recommended Posts

Ethangar    122
I have been reading a whole lot on Vertex and Pixel shaders, but I am missing a clear piece of understanding when it comes to textures. Say for instance I have a simple box, maybe it will serve as a wall in game. Now, I want said box to have some fany shaders to give it depth, so I decide to use bump mapping and parallax mapping to achieve this effect with a nice stone texture. My problem is this: How do I texture the box? Do I define the texture in 3d studio max, apply it to my mesh, export the mesh WITH the texture assigned to it in the .X file? OR, do I make the box a simple solid with no texture, export it to the .X file, and somehow project the texture onto the mesh as a pass in HLSL. What about my normal map that I will use for the depth? Do I add that the my mesh file somehow or do I simply define it as a value in the shader. Somewhere I am going wrong with all this and trying to do both things and it is making my mesh go away.

Share this post


Link to post
Share on other sites
Illco    928
Ok this may be a long shot but I will try to do some explaining. Let's first assume we have a model, regardless of whether it came from 3D Studio Max or elsewhere. Furthermore let's assume the mesh's vertex data contains what is required for your effects -- at least positions and normals but perhaps also binormals and tangents. Naturally we require one or more sets of texture coordinates (uv-coordinates). For diffuse texturing we have per vertex:

position
normal
texturecoordinates


If you want to use a HLSL effect file to render this mesh with a diffuse texture, we need to provide the mesh data and a texture to the shader. This is best done using semantics. In your shader you define a texture name and assign the semantic diffuse to it. In your code you then obtain the handle for diffuse texture and pass the texture through this handle using SetTexture() on the effect instance. If the shader is correct, the mesh should be rendered with the texture.

Now where did the mesh and the texture come from? As far as I know, the X-file format only contains references to textures (filenames) and not the textures themselves. So, when exporting from 3DSMax, you need to copy them manually. You do, though, need to make sure that the aforementioned mesh data is written: positions, normals, texture coordinates for diffuse and for some other effects like bumpmapping you will require tangents and/or binormals as well.

I hope this makes some sense. I could go into some more detail here and there if you like, but I'll await your reaction to see what precisely is unclear. For now, good luck!

Greetz,

Illco

Share this post


Link to post
Share on other sites
Ethangar    122
Ok, awesome, and indeed the X file points to the path of the texture (can be relative and absolute). Now I guess my question is in regards to the actual mapping of the texture. Say I have my square box that is 40 x 40 x 40. I have a texture that is 20 x 20. I want each surface on the box to have 4 instances of the texture applied to it (so as I don't stretch the texture any). All that needs to be bump mapped.

Do I have to do anything special in my HLSL to note the mapping of the texture and their normal maps? Or does it gather all that information from the mesh file itself and just knows where to put the normal maps (since they are the same size as the texture).

Share this post


Link to post
Share on other sites
Illco    928
You don't have to do anything special -- the texture is just the texture, the effect just says how it will look but the mesh supplies all data. The texture coordinates are stored per-vertex and come from the mesh. The shader just uses them, so if you tile the texture correctly in, say, 3DSMax, the effect will do fine.

The mapping of the normal maps is a same story. If the normal maps are simply overlays of the diffuse texture, you can reuse the same coordinates and save some memory storage per vertex. But sometimes the normal map is mapped differently (for example with different tiling) and in such cases you require an extra set of coordinates.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Ethangar    122
I'm still having a whole lot of problems with textures. Shouldn't the mesh and the texture be somewhat independent? Ssay I have a mesh with a texture, but decide not to render the textures/materials. Wouldn't that be possible by simply not drawing the materials?

Does anyone have an example of specular lighting of a mesh with a texture?

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