Jump to content
  • Advertisement
Sign in to follow this  
ciel123

Multiple vertex/pixel shaders

This topic is 655 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

This is a pretty basic question, but the HLSL documentation and guides out there are pretty scarce and disappointing...

 

I've learned that vertex and pixel shaders are executed by the graphics pipeline during the vertex and pixel shader stages, respectively. But I've seen projects that use multiple vertex/pixel shader functions, like:

 

// Vertex shader

float4 DoSomeTransformationVS(float4 v : POSITION) : SV_POSITION

{

    ...

}

 

// Also vertex shader

float4 DoAnotherTransformationVS(float4 v : POSITION) : SV_POSITION

{

    ...

}

 

What happens then? Are both functions executed during VS stage? In fact, how does the compiler know which functions are vertex shaders and which are pixel shaders?

Share this post


Link to post
Share on other sites
Advertisement

If I got it correctly, these are different vertex shader program. You can have multiple vertex shader available in your program, but you can only bind one vs in each pass.  For the above code, I guess there are multiple passes each frame (or the project allow you to switch vs during runtime), and these two vs is for different passes

Share this post


Link to post
Share on other sites
When you compile a shader, you specify the name of a function in the source code that acts as the "main" function (aka the "entry point").

Your example is just a convenience for the original programmer, where they've written two vertex programs in the same file. That's a common thing to do when there's some code sharing.

Share this post


Link to post
Share on other sites

As Hodgman says, you specify the entry point function while compiling a shader, and while compiling you specify whether this is a vertex or a pixel shader function.

Also please note that in other APIs it's different:

  1. In HLSL you specify whether it's a vertex/pixel shader while compiling (i.e. from C++ or command line if using fxc)
  2. In GLSL you can't specify the entry point's name (it must be always called main) meaning you can't mix pixel and vertex shaders in the same file. Whether you're compiling a vertex or pixel shader is specified while compiling (i.e. from C++)
  3. In Metal, you use the keywords "vertex" and "fragment" to specify whether the function is a vertex or pixel shader entry point. Also, you cannot name a function as "main" (which directly conflicts with GLSL's requirement of having the entry point named "main")
Edited by Matias Goldberg

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!