Rachit Agrawal
Rachit Agrawal

Reputation: 3343

DirectX: Vertex Shader using textures

I am a beginner in Graphics Programming. I came across a case where a "ResourceView" is created out of texture and then this resource view is set as VS Resource. To summarize:

CreateTexture2D( D3D10_TEXTURE2D_DESC{ 640, 512, .... **ID3D10Texture2D_0c2c0f30** )
CreateShaderResourceView( **ID3D10Texture2D_0c2c0f30**, ..., **ID3D10ShaderResourceView_01742c80** )
VSSetShaderResources( 0, 1, [**0x01742c80**])

When and what are the cases when we use textures in Vertex Shaders?? Can anyone help?

Thanks.

Upvotes: 2

Views: 974

Answers (1)

Lucius
Lucius

Reputation: 3745

That completely depends on the effect you are trying to achieve.

If you want to color your vertices individually you would usually use a vertex color component. But nothing is stopping you from sampling the color from a texture. (Except that it is probably slower.)

Also, don't let the name fool you. Textures can be used for a lot more than just coloring. They are basically precomputed functions. For example, you could use a Textue1D to submit a wave function to animate clothing or swaying grass/foilage. And since it is a texture, you can use a different wave for every object you draw, without switching shaders.

The Direct3D developers just want to provide you with a maximum of flexibility. And that includes using texture resources in all shader stages.

Upvotes: 3

Related Questions