Passing a texture to a vertex shader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Passing a texture to a vertex shader

Post by Frosty Topaz »

Hey everyone.

I'm working on a vertex shader-based terrain scene node. It uses vertex texture fetch to read a heightmap in video memory and adjust vertices accordingly. Only one problem; my shader is not getting the texture.

When I've written pixel shaders I've always been able to get textures by using this syntax (HLSL):

Code: Select all

sampler2D tex0 : register(s0);
This doesn't seem to be working for vertex shaders though. I've checked around for similar problems (like the threads about loading multiple textures in GLSL shaders) but those solutions haven't helped.

Any thoughts would be appreciated.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

You can't load textures in the vertex shader unfortunately, only in the pixel shader, in HLSL I think. Pass your vertex shader's color output to the pixel then multiply with the texture loaded.
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

Why would you not be able to load textures in the vertex shader? It's supported in shader model 3. And I've seen pure DirectX/HLSL examples online.

And to make sure I'm being understood this texture has nothing to do with colour. It's a height map.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Don't bother.

1. It only works on NVidia cards.
2. It requires an obscure texture format, something like "ATI_LUMINANCE", so you have to implement this into Irrlicht. (I dont know why an NVidia only technique requires a texture format prefixed with ATI, don't ask me.)
<--- This is why you're not recieving a texture.
3. Its slow, averaging at 30 mil tris per second compared to other techniques such as "Copy to Pbuffer" which can do 60. (And ATI's R2VB can do 90 mil tris per second.)

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

1. I only have an NVidia card.
2. Thank you, I'll look into it.
3. It's gotta be faster than passing 64K or so vertices from the CPU to the vertex buffer every frame. I'll look into Copy to Pbuffer. And if I had an ATI card I'd do R2VB. When I'm finished if you'd like to give it a try I can send you my code and you can add the ATI support.

Overall thanks for the reply.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

[Some time spent reading docs later...]

Seems the texture must be a 32 bit floating point texture. I suspect I can shoehorn that into Irrlicht without tooooo much difficulty since I don't need to handle rendering them, just storing them. That said I've never dug into the video drivers and material renderers so it may be more work than I anticipate. I'll report back this weekend when I've had a chance to play with it a bit.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Nadro already provided a patch to add floating point textures some weeks ago. Check the code snippets forum.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

thanks for bringing this up, i forgot about that one.
Image
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

Thanks I'll check out Nadro's work
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

OK I've looked into it a bit more. It seems that DirectX wants vertex textures in particular slots (257 and higher). I modified SMaterial to load textures in those slots but I've still had no luck. If anyone has any ideas let me know I'll keep looking at it when I can.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Something like "sampler2D tex0 : register(s257);" should do the trick. Remember VTF only supports point sampling with SM3 (IIRC).

You need to run against the Debug DirectX libs and see if there are any debug messages. Read the DX docs for full instructions.

VTF has quite a latency IIRC. Do your texture read as early as possible and use the results as late as possible.
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

Thanks for the reply sio2.

Sadly using that just gives me an error saying that the material only has 4 slots. Oddly enough slots 0 through 4 (so a total of 5) generate no error. I think there may be some way to set that number of texture slots which I'm not doing or which is happening somewhere in Irrlicht where I haven't seen it.

Assuming that's true I'll dig a bit more and see if I can find it.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
Post Reply