Sign in to follow this  

sampling texture in vertex shader

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've only just started playing with shaders, using HLSL. I've experimented a bit with vertex shaders and written some stuff to deform a grid using sin etc -- all very simple and typical. Anyway what I wanted to do was to use a greyscale texture as a height map, picking the Z values for my verts in the shader from a texture lookup, or also use a texture filled with random colours to modulate my grid coordinates, but it seems that I can't sample the texture in the vertex shader. I'm using shader model 2.0 but I have a 6600GT so could use 3.0 if that supports it (although I would have liked to have been able to do it with a version under 2.0). If this indeed isn't possible, does anyone have any suggestions on how one might go about doing something like this? cheers sam

Share this post


Link to post
Share on other sites
You need to use shader model 3.0. You also need to use texldl; i e, you have to specify the MIP map level yourself.

Beware: there's about a 20 cycle latency when fetching textures in a vertex shader. Try to fetch early, and use late.

Share this post


Link to post
Share on other sites
Doh well! Is there no way to do what I want using anything less than shader model 3? In some roundabout way perhaps?

edit: had a thought -- I could set the vertex colours to colours from the image!

sam

Share this post


Link to post
Share on other sites
"Is there no way to do what I want using anything less than shader model 3? In some roundabout way perhaps?"

Nope. texldl is the only instruction that allows it, and it's a shader 3 instruction.

"I could set the vertex colours to colours from the image!"

I take it you mean the vertex heights, as that's the problem you were initially trying to solve ;) Doing a heightmapped terrain in a shader would probably not be the fastest thing anyway. It's faster just to create your grid mesh, load the heightmap, and loop through each pixel and set the vertices to the appropriate heights (or loop through the vertices instead of the pixels).

Share this post


Link to post
Share on other sites
Yeah it's not so much that I want to create a fully-fledged height map terrain engine with this :) I just want to experiment with some demo-y effects, modulating stuff with various textures and stuff like that.

No I actually meant that I could set the vertex colours to colours from the image, and then use those as my Z values in my shader, but of course now that I repeat that, that's a really stupid idea, and I might as well just set the vertex positions :P

What I wanted to do was to have a texture with, say, some text on it, and then use that as the height map for my grid, and then scroll the height map by adjusting the texture coordinates. But I guess I'll have to do it with SM3.

cheers
sam

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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