Passing data to vertex shader

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kubatp
Gnome
Posts: 368
Joined: Tue Jan 06, 2009 1:12 pm
x 43

Passing data to vertex shader

Post by kubatp »

Hi,
this is not directly related to OGRE, but I hope there is someone who could give me a hint what to do...

I am passing data to pixel shader via textures. I am pretty sure that this is a usual technique - every vertex has encoded a UV coordinates where to look for a data in the texture, which is dynamically changed according to the game state. This way I am able to change the data and the output itself.
This is working fine, but I would like to do similar thing in vertex shader and VS does not have an access to textures (only its UV coordinates). Is there a way to do similar thing in VS? What is the best way to do this?

Thank you very much for all advices.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Passing data to vertex shader

Post by Kojack »

Vertex shaders can read from textures too, but only if you are using shader model 3 or above.
(Note, mip map level must be manually specified, since the info needed for automatic mip maps isn't known until the pixel shader)
kubatp
Gnome
Posts: 368
Joined: Tue Jan 06, 2009 1:12 pm
x 43

Re: Passing data to vertex shader

Post by kubatp »

Hi Kojack,
thank you very much for your answer. I didn't know that it is possible to read it also in VS, however I am trying to target shader ps_2_1, vs_2_1. What is the best approach for these?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Passing data to vertex shader

Post by dark_sylinc »

kubatp wrote:Hi Kojack,
thank you very much for your answer. I didn't know that it is possible to read it also in VS, however I am trying to target shader ps_2_1, vs_2_1. What is the best approach for these?
It is impossible to read data the way you want in these shader profiles. Note that these profiles are rather old (they target the old GeForce FX 5000 and ATI Radeon 9000 series; which are like 14 years old).

The best way you can send data to the vertex shader is by setting an extra attribute to the vertex buffer (i.e. an extra TEXCOORD) or try to index a shader parameter (i.e. myConstParam[vertex.texcoord0.x]). However shader model 2.x has a limit of 256 uniform parameters (i.e. 256 float4)
kubatp
Gnome
Posts: 368
Joined: Tue Jan 06, 2009 1:12 pm
x 43

Re: Passing data to vertex shader

Post by kubatp »

Thank you.

What is your professional opinion about this? 256xfloat4 is more than enough. With every vertex I will add there special TEXCOORD, which will have encoded the "index" of the uniform parameter.

Is this possible to do? Does it have a performance impact?
Post Reply