Sign in to follow this  
PrincessDaisy

Vertex Shaders and Matrix Transformations

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
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this