Vertex Shaders and Matrix Transformations

Started by
6 comments, last by superpig 18 years, 1 month ago
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
________________________
Pretty In Pink
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.
Why do you want to do the transformation in FFP?
When using a shader, you are essentially replacing the fixed-function pipeline. You have to project the vertex position yourself.
-Tom BlindGame Design and Developmenthttp://tomblind.squad-seven.comtomblind@squad-seven.com
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.
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?
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
________________________
Pretty In Pink
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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement