Jump to content
  • Advertisement
Sign in to follow this  
PrincessDaisy

Vertex Shaders and Matrix Transformations

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

I'm using Cg as my shader API, and when I run any vertex shader, everything disappears! I am using Cg in DX, but I think this is more of a general question. In all the shader examples I have seen, the verts are altered using the current projection matrix, but in my current project, I still want to do that in the FFP, so no matrix transofmration takes place in the shader. Could this be what is messing up the drawing? The current shader I am using is very simple, and should work!
struct Vert
{
    float4 pos  : POSITION;
    float4 dif  : COLOR0;
    float4 tex  : TEXCOORD0;
};

Vert main(Vert In)
{
    return In;
}
I have checked that my current vertices are compatable with the shader, and that everythign is rendering inetrnally, just nothing is appearing on screen! Any help would be appreciated Thanks Daisy

Share this post


Link to post
Share on other sites
Advertisement
I don't know about Cg but in GLSL when I am using a vertex shader *without* a fragment shader I have to set the fragment (pixel) color in the vertex shader so that the fragment shader can read the color value from it. If I don't do this, fragment values are set as black, and chances are that your clear color is black as well, so that might be what's "hiding" your scene.

Share this post


Link to post
Share on other sites
When using a shader, you are essentially replacing the fixed-function pipeline. You have to project the vertex position yourself.

Share this post


Link to post
Share on other sites
You can't do that. When you use a vertex shader, the (majority) of the FFP transformation phase is bypassed, including the application of the projection matrix.

The output of a vertex shader must be coordinates in clip space (the result of the application of the world, view and projection transforms). The shader you've supplied simply outputs model space coordinates. The hardware will take the output coordinates, clip them, apply the perspective division (by w) to bring them into NDC space, then apply the viewport transformation to bring them into screen space, then rasterization will occur. Since what you've outputted from your vertex shader isn't really what the card expects, the vertices are likely to be drawn somewhere unexpected, or not at all.

Share this post


Link to post
Share on other sites
What the other guys said...

Out of curiosity... Why would you not want to do any transformations in the incredibly fast hardware that is designed specifically for that sort of thing?

Share this post


Link to post
Share on other sites
Thanks for that, it explains why nothing is being displayed, yet my fragment shaders are working fine.

The reason I want to do the matrix transformations in the FFP is because I am just starting out with shaders, and my engine is currently 100% FFP. I wanted, for now, to just start playing around with shaders without changing the base code to much, and move over to programmable pipeline gradually.

Again, thanks for the info, and hopefully I can get round it without to much trouble :)

Daisy

Share this post


Link to post
Share on other sites
Quote:
Original post by PrincessDaisy
The reason I want to do the matrix transformations in the FFP is because I am just starting out with shaders, and my engine is currently 100% FFP. I wanted, for now, to just start playing around with shaders without changing the base code to much, and move over to programmable pipeline gradually.


Something I'd recommend is to keep both FFP and shader pipelines knocking around, and a hotkey for toggling between the two. That way you can quickly compare the results you're getting from each to see that your shader does what you expect.

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!