How to apply normal map and height map to texture on a 3D object

Hello,

I have a game that is partially 2D and partially 3D, and although I have been able to draw a lot of the 3D elements without issue, I’m having trouble making it look the way I want. Specifically, I have some nice-looking textures that come with ao, diffuse, height, and normal maps. I use the “diffuse” as the standard texture to apply to the 3D object, which works fine. But, I’m not sure how to apply the maps, in particular normal and height maps, to make the textures “look 3D” if that makes sense. For example, let’s say I have a 3D cube, I throw a rock texture on it, I’d like that rock texture to look “bumpy” and I assume the way to do that is to apply the normal and/or height maps that are included with the image. But I can’t figure out how to do this. I’ve read through and worked through some of the various pixel shader tutorials out there and I still have not been able to make this work. Any tips or thoughts?

Your meshs will need tangent data and you will need to write a shader to apply the texture effects you want.

I dont think BasicEffect has the elements you need, though i never use it so others may know better :slight_smile:

Thanks for the reply, so the meshes need to have tangent data built-in otherwise it won’t work?

Any pointers to how I can write the shader to apply the effects?

Yea, you can switch it on in the content pipeline ui for the mesh, but if its not been UV mapped, then it will fail. So minimum needed is uv really.

There are a lot of tuts on writing normal map shaders out there, i would point you at my old repo, but it is very much out of date.

I have a lighting tutorial in there, have a look at this shader, it applies a normal map (ignore that I call it bump map)

Hope this helps, and welcome :slight_smile:

Awesome, thanks, I’ll take a look at that shader and see if I can get it working. I don’t see any option to enable UV mapping in the content pipeline - using the latest version with VS2022 - maybe it’s automatically enabled by default now?

1 Like

You wont, the mesh will need to be uv mapped in an editer I am affraid. If you can apply a texture to it, it will be uv mapped.